Parse::Eyapp 1.069577
Sponsored Links
Parse::Eyapp 1.069577 Ranking & Summary
File size:
0.36 MB
Platform:
Any Platform
License:
Perl Artistic License
Price:
Downloads:
850
Date added:
2007-06-27
Publisher:
Casiano Rodriguez-Leon
Parse::Eyapp 1.069577 description
Parse::Eyapp module contains extensions for Parse::Yapp.
SYNOPSIS
use strict;
use Parse::Eyapp;
use Parse::Eyapp::Treeregexp;
sub TERMINAL::info {
$_[0]{attr}
}
my $grammar = q{
%right = # Lowest precedence
%left - + # + and - have more precedence than = Disambiguate a-b-c as (a-b)-c
%left * / # * and / have more precedence than + Disambiguate a/b/c as (a/b)/c
%left NEG # Disambiguate -a-b as (-a)-b and not as -(a-b)
%tree # Let us build an abstract syntax tree ...
%%
line: exp <%name EXPRESION_LIST + ;> { $_[1] } /* list of expressions separated by ; */
;
/* The %name directive defines the name of the class to which the node being built belongs */
exp:
%name NUM NUM | %name VAR VAR | %name ASSIGN VAR = exp
| %name PLUS exp + exp | %name MINUS exp - exp | %name TIMES exp * exp
| %name DIV exp / exp | %name UMINUS - exp %prec NEG
| ( exp ) { $_[2] } /* Let us simplify a bit the tree */
;
%%
sub _Error { die "Syntax error near ".($_[0]->YYCurval?$_[0]->YYCurval:"end of file")."n" }
sub _Lexer {
my($parser)=shift; # The parser object
for ($parser->YYData->{INPUT}) { # Topicalize
m{Gs+}gc;
$_ eq and return(,undef);
m{G([0-9]+(?:.[0-9]+)?)}gc and return(NUM,$1);
m{G([A-Za-z][A-Za-z0-9_]*)}gc and return(VAR,$1);
m{G(.)}gcs and return($1,$1);
}
}
sub Run {
my($self)=shift;
$self->YYParse( yylex => &_Lexer, yyerror => &_Error, );
}
}; # end grammar
our (@all, $uminus);
Parse::Eyapp->new_grammar( # Create the parser package/class
input=>$grammar,
classname=>Calc, # The name of the package containing the parser
firstline=>7 # String $grammar starts at line 7 (for error diagnostics)
);
my $parser = Calc->new(); # Create a parser
$parser->YYData->{INPUT} = "2*-3+b*0;--2n"; # Set the input
my $t = $parser->Run; # Parse it!
local $Parse::Eyapp::Node::INDENT=2;
print "Syntax Tree:",$t->str;
# Let us transform the tree. Define the tree-regular expressions ..
my $p = Parse::Eyapp::Treeregexp->new( STRING => q{
{ # Example of support code
my %Op = (PLUS=>+, MINUS => -, TIMES=>*, DIV => /);
}
constantfold: /TIMES|PLUS|DIV|MINUS/:bin(NUM($x), NUM($y))
=> {
my $op = $Op{ref($bin)};
$x->{attr} = eval "$x->{attr} $op $y->{attr}";
$_[0] = $NUM[0];
}
uminus: UMINUS(NUM($x)) => { $x->{attr} = -$x->{attr}; $_[0] = $NUM }
zero_times_whatever: TIMES(NUM($x), .) and { $x->{attr} == 0 } => { $_[0] = $NUM }
whatever_times_zero: TIMES(., NUM($x)) and { $x->{attr} == 0 } => { $_[0] = $NUM }
},
OUTPUTFILE=> main.pm
);
$p->generate(); # Create the tranformations
$t->s($uminus); # Transform UMINUS nodes
$t->s(@all); # constant folding and mult. by zero
local $Parse::Eyapp::Node::INDENT=0;
print "nSyntax Tree after transformations:n",$t->str,"n";
SYNOPSIS
use strict;
use Parse::Eyapp;
use Parse::Eyapp::Treeregexp;
sub TERMINAL::info {
$_[0]{attr}
}
my $grammar = q{
%right = # Lowest precedence
%left - + # + and - have more precedence than = Disambiguate a-b-c as (a-b)-c
%left * / # * and / have more precedence than + Disambiguate a/b/c as (a/b)/c
%left NEG # Disambiguate -a-b as (-a)-b and not as -(a-b)
%tree # Let us build an abstract syntax tree ...
%%
line: exp <%name EXPRESION_LIST + ;> { $_[1] } /* list of expressions separated by ; */
;
/* The %name directive defines the name of the class to which the node being built belongs */
exp:
%name NUM NUM | %name VAR VAR | %name ASSIGN VAR = exp
| %name PLUS exp + exp | %name MINUS exp - exp | %name TIMES exp * exp
| %name DIV exp / exp | %name UMINUS - exp %prec NEG
| ( exp ) { $_[2] } /* Let us simplify a bit the tree */
;
%%
sub _Error { die "Syntax error near ".($_[0]->YYCurval?$_[0]->YYCurval:"end of file")."n" }
sub _Lexer {
my($parser)=shift; # The parser object
for ($parser->YYData->{INPUT}) { # Topicalize
m{Gs+}gc;
$_ eq and return(,undef);
m{G([0-9]+(?:.[0-9]+)?)}gc and return(NUM,$1);
m{G([A-Za-z][A-Za-z0-9_]*)}gc and return(VAR,$1);
m{G(.)}gcs and return($1,$1);
}
}
sub Run {
my($self)=shift;
$self->YYParse( yylex => &_Lexer, yyerror => &_Error, );
}
}; # end grammar
our (@all, $uminus);
Parse::Eyapp->new_grammar( # Create the parser package/class
input=>$grammar,
classname=>Calc, # The name of the package containing the parser
firstline=>7 # String $grammar starts at line 7 (for error diagnostics)
);
my $parser = Calc->new(); # Create a parser
$parser->YYData->{INPUT} = "2*-3+b*0;--2n"; # Set the input
my $t = $parser->Run; # Parse it!
local $Parse::Eyapp::Node::INDENT=2;
print "Syntax Tree:",$t->str;
# Let us transform the tree. Define the tree-regular expressions ..
my $p = Parse::Eyapp::Treeregexp->new( STRING => q{
{ # Example of support code
my %Op = (PLUS=>+, MINUS => -, TIMES=>*, DIV => /);
}
constantfold: /TIMES|PLUS|DIV|MINUS/:bin(NUM($x), NUM($y))
=> {
my $op = $Op{ref($bin)};
$x->{attr} = eval "$x->{attr} $op $y->{attr}";
$_[0] = $NUM[0];
}
uminus: UMINUS(NUM($x)) => { $x->{attr} = -$x->{attr}; $_[0] = $NUM }
zero_times_whatever: TIMES(NUM($x), .) and { $x->{attr} == 0 } => { $_[0] = $NUM }
whatever_times_zero: TIMES(., NUM($x)) and { $x->{attr} == 0 } => { $_[0] = $NUM }
},
OUTPUTFILE=> main.pm
);
$p->generate(); # Create the tranformations
$t->s($uminus); # Transform UMINUS nodes
$t->s(@all); # constant folding and mult. by zero
local $Parse::Eyapp::Node::INDENT=0;
print "nSyntax Tree after transformations:n",$t->str,"n";
Parse::Eyapp 1.069577 Screenshot
Parse::Eyapp 1.069577 Keywords
NUM
Eyapp 1.069577
VAR
UMINUS
DIV
PLUS
EXP
0
name
attr
times
parser
Parse::Eyapp
ParseEyapp
Parse::Eyapp 1.069577
Libraries
Bookmark Parse::Eyapp 1.069577
Parse::Eyapp 1.069577 Copyright
WareSeeker periodically updates pricing and software information of Parse::Eyapp 1.069577 full version from the publisher, so some information may be slightly out-of-date. You should confirm all information before relying on it. Software piracy is theft, Using crack, password, serial numbers, registration codes, key generators is illegal and prevent future development of Parse::Eyapp 1.069577 Edition. Download links are directly from our publisher sites, torrent files or links from rapidshare.com, yousendit.com or megaupload.com are not allowed
Featured Software
Want to place your software product here?
Please contact us for consideration.
Contact WareSeeker.com
Related Information
name definitions
baby names
law of attraction
namenda
name meanings
attrition
name tags
orlando attractions
obamau0027s secret service code names
name goo goo dolls
attractions x26 activities
attractions in washington dc
what does my name mean
name change
las vegas attractions
domain names
parser error message
timeshares
Related Software
CQL::Parser is a Perl module that compiles CQL strings into parse trees of Node subtypes. Free Download
Parse::Template was initially created to serve as a code generator for the Parse::Lex class. Free Download
SVG::Parser is a Perl module with XML Parser for SVG documents. Free Download
Parse::Java is a Perl module that acts like a parser for Java code. Free Download
PXR::Parser is a Pure Perl SAX XML Push Parser. Free Download
Parse::RecDescent is a Perl module to generate Recursive-Descent Parsers. Free Download
Workspace Name Applet is a Gnome panel applet to display and edit the name of the current workspace. Free Download
iCal::Parser::HTML is a Perl module to generate HTML calendars from iCalendars. Free Download
Latest Software
Popular Software
Favourite Software