[antlr-interest] difference in tree parser..

pady prabha_pady at comcast.net
Sat Jan 3 06:24:56 PST 2009



I have a simple if-else grammar ( attached Gwf.g and GwfWalker.g ). When I
run this, I get issues around even handling simple if-else. I debugged
through the generated code and found that one of the generated tree parser
code was looking for an UP token when deciding on the predicate. So I wrote
a very similar simplified grammar ( attached X.g and XW.g ) which has
similar logic for the if-else rule alone. This one works as expected ( and
the generated java code is exactly as expected ).

Can anybody take a quick look at why this difference is there below ? ( the
"ifStatement" rule in Gwf*.g and the "ifRule" rule in X*.g ).

Gwf.g ( grammar )

ifStatement
  : 'if' boolExpression s1=statement (options {k=1;}: 'else' s2=statement)?
  -> ^('if' boolExpression ^(TRUE_COND $s1 ) (^(FALSE_COND $s2 ))?)
  ;

GwfWalker.g ( tree grammar )


ifStatement
   : ^('if' b=boolExpression
       ^(TRUE_COND ({$b.result}? => statement | .))
       (^(FALSE_COND ({!$b.result}? => statement | .)))?)
   ;


X.g ( grammar )

ifRule
 : 'if' boolExpr r1 r2? -> ^(R1_TOK r1) (^(R2_TOK r2))?
 ;

XW.g ( tree grammar )

ifRule
 : ^('if' b=boolExpr ^(R1_TOK ({$b.res}?=> r1 | .)) (^(R2_TOK ({!$b.res}?=>
r2 | .)))?)
 ;




Thanks

-- pady
-------------- next part --------------
A non-text attachment was scrubbed...
Name: GwfWalker.g
Type: application/octet-stream
Size: 3731 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090103/44829cda/attachment.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Gwf.g
Type: application/octet-stream
Size: 5003 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090103/44829cda/attachment-0001.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: XW.g
Type: application/octet-stream
Size: 271 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090103/44829cda/attachment-0002.obj 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: X.g
Type: application/octet-stream
Size: 301 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20090103/44829cda/attachment-0003.obj 


More information about the antlr-interest mailing list