[antlr-interest] expression parser example Expr.g dont work
    Chris Snyder 
    snyder at t-vec.com
       
    Wed Jan  7 06:55:58 PST 2009
    
    
  
stat:   expr NEWLINE 
 
looks like is should just be
 
stat:   expr 
 
The current form hits the '(' and then looks for expr which requires a
NEWLINE after '2' which you don't have.
 
I didn't verify this though.
 
C
  _____  
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Mats Ekberg
Sent: Wednesday, January 07, 2009 1:22 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] expression parser example Expr.g dont work
 
I have stripped the classical expr.g example and when I run it in ANTLRWorks
it dont work.
The input "(1 + 2) * 3 - 4" (with a newline at the end) just recognizes "( 1
+ 2" and the nothing more.
How come?
grammar Expr;
prog:   stat+ ;
stat:   expr NEWLINE 
    |   NEWLINE
    ;
expr
    :   multExpr ( '+' multExpr | '-' multExpr )*
    ;
multExpr 
    :   atom ('*' atom )*
    ; 
atom 
    :   INT 
    |   '(' expr ')'
    ;
INT :   '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS  :   (' '|'\t')+ {skip();} ; 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090107/ac27d873/attachment.html 
    
    
More information about the antlr-interest
mailing list