Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Parse::Eyapp a LALR yapp compatible Parser Generator

Reply
Thread Tools

Parse::Eyapp a LALR yapp compatible Parser Generator

 
 
Casiano
Guest
Posts: n/a
 
      01-30-2007
I have released version 1.06550 of Parse::Eyapp in CPAN.

Parse::Eyapp (the name stands for Extended yapp) is a collection of
modules that extends Francois Desarmenien Parse::Yapp 1.05. Eyapp
extends yacc/yapp syntax with functionalities line named attributes,
EBNF-like expressions, modifiable default action, automatic syntax
tree building, semi-automatic abstract syntax tree building,
translation schemes, tree regular expressions, tree transformations,
scope analysis support, directed acyclic graphs and a few more.

The following example shows a simple Eyapp program translating
infix expressions into postfix expressions:

pl@nereida:~/src/perl/YappWithDefaultAction/examples$ cat -n
Postfix.eyp
1 # File Postfix.eyp
2 %right '='
3 %left '-' '+'
4 %left '*' '/'
5 %left NEG
6
7 %defaultaction { return "$left $right $op"; }
8
9 %%
10 line: $exp { print "$exp\n" }
11 ;
12
13 exp: $NUM { $NUM }
14 | $VAR { $VAR }
15 | VAR.left '='.op exp.right
16 | exp.left '+'.op exp.right
17 | exp.left '-'.op exp.right
18 | exp.left '*'.op exp.right
19 | exp.left '/'.op exp.right
20 | '-' $exp %prec NEG { "$exp NEG" }
21 | '(' $exp ')' { $exp }
22 ;
23
24 %%
25
26 sub _Error {
27 my($token)=$_[0]->YYCurval;
28 my($what)= $token ? "input: '$token'" : "end of input";
29 my @expected = $_[0]->YYExpect();
30
31 local $" = ', ';
32 die "Syntax error near $what. Expected one of these tokens:
@expected\n";
33 }
34
35 my $x;
36
37 sub _Lexer {
38 my($parser)=shift;
39
40 for ($x) {
41 s/^\s+//;
42 $_ eq '' and return('',undef);
43
44 s/^([0-9]+(?:\.[0-9]+)?)// and return('NUM',$1);
45 s/^([A-Za-z][A-Za-z0-9_]*)// and return('VAR',$1);
46 s/^(.)//s and return($1,$1);
47 }
48 }
49
50 sub Run {
51 my($self)=shift;
52 print "Write an expression: ";
53 $x = <>;
54 $self->YYParse( yylex => \&_Lexer, yyerror => \&_Error,
55 #yydebug => 0xFF
56 );
57 }

Have fun


Casiano

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Any lalr parser generator for ruby? Tommy Nordgren Ruby 1 12-22-2007 10:58 PM
Ply(LALR) and Yacc behaving differently =?ISO-8859-1?Q?=C5smund_Grammeltvedt?= Python 0 04-07-2005 06:51 PM
[ANN] Beaver - a LALR Parser Generator v0.9.3 is released Alexander Demenchuk Java 0 08-30-2004 07:02 PM
Performance patch to Parse-Yapp 1.05 Clint Olsen Perl Misc 2 02-11-2004 04:49 PM
Perl pattern 5.6+ bug causing Parse::Yapp to fail Clint Olsen Perl Misc 5 02-09-2004 07:28 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57