[antlr-interest] stuck expr

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


The declaration:

exprList   : expr (COMMA expr);

should be

exprList   : expr (COMMA expr)*;

and my problem still exist, anybody could give me the ligth?

TIA

jagad

On Wed, 2003-10-01 at 20:31, jagad wrote:
> 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/
> 


 

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




More information about the antlr-interest mailing list