Mats Ekberg wrote:
I removed the NEWLINE requirement entierly and evaluates "expr" in
ANTLRWorks, same result. Sorry.
The input "(1 + 2) * 3 - 4" (with a newline at the end) just recognizes
"( 1 + 2" and the nothing more.
Place an EOF in the mix:
stat : expr? EOF ;
And fix your NEWLINE:
NEWLINE: '\r'? '\n' { $channel = HIDDEN; } ;
Then when you run ANTLR Works, make sure that you are choosing the stat
rule as the start rule (and use the debugger, not the interpretter).
Jim
grammar Expr;
expr
: multExpr ( '+' multExpr | '-' multExpr )*
;
multExpr
: atom ('*' atom )*
;
atom
: INT
| '(' expr ')'
;
INT : '0'..'9'+ ;
NEWLINE:'\r'? '\n' ;
WS : (' '|'\t')+ {skip();} ;
ons 2009-01-07 klockan 09:55 -0500 skrev Chris Snyder:
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:[email protected]
[mailto:[email protected]] On
Behalf Of Mats Ekberg
Sent: Wednesday,
January 07, 2009 1:22 AM
To:
[email protected]
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();} ;
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en
-~----------~----~----~----~------~----~------~--~---
|
List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address