[antlr-interest] stuck expr

jagad jagad at enciety.com
Wed Oct 1 06:31:31 PDT 2003


Hi All,

I have simple parser like this one;

//***** Parser *****
class MyParser extends Parser;

goal       : exprList SEMI EOF;

exprList   : expr (COMMA expr);

expr       : simpleExpr (relOp simpleExpr)*;

simpleExpr : (PLUS | MINUS)? term (addOp term)*;

term       : factor (mulOp factor)*;

factor     : NUM_INT
           | NUM_REAL
           | (LPAREN expr RPAREN)
           ;

mulOp      : STAR | SLASH | DIV | AND | SHL| SHR;
addOp      : PLUS | MINUS | OR | XOR;
relOp      : GREATHAN 
           | LESSTHAN | GREATHANEQU | LESSTHANEQU |EQU|NOTEQU;

//********************

The I gerenate into C++ code, the problem is the parser allways stuck on
expr and never reach the goal. I have try to set options{ k=xx} with no
effect.

For input:

(1+2);

the output is:

NUM_INT      <----- factor: NUM_INT
term         <----- term: factor 
PLUS         <----- addOp: PLUS 
NUM_INT      <----- factor: NUM_INT 
term         <----- term: factor 
simpleExpr   <----- simpleExpr: term (addOp term)*; 
expr         <----- expr: simpleExpr
( expr )     <----- factor: (LPAREN expr RPAREN)
term         <----- term: factor
simpleExpr   <----- simpleExpr: term
expr         <----- expr: simpleExpr

Why my parser never reach goal? please, let me know.

Thanks in Advance and Best Regards

jagad




 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list