[antlr-interest] Re: HELP!!!: with left recursion

lgcraymer lgc at mail1.jpl.nasa.gov
Sun Nov 2 23:19:02 PST 2003


Look at any of the language grammars--java.g may be the easiest--and 
borrow the expression grammar from there as a first step.  Also, it 
helps to sort the "if" and "for" statements out of the expression 
grammar.  The big problem is usually preserving operator precedence.

--Loring

--- In antlr-interest at yahoogroups.com, "aaanwar" <aaanwar at y...> 
wrote:
> Greetings,
> 
> Any advise on this:
> 
> exp	--> 	let  decs in exp end
> 	| 	if exp then exp end
> 	| 	if exp then exp else exp end
> 	| 	for ID :=  exp to exp do exp end
> 	| 	while exp do exp end
> 	| 	lvalue
> 	| 	lvalue :=exp
> 	| 	builtin
> 	| 	ID ( arg_seq  )
> 	| 	ID ( )
> 	| 	exp &  exp 
> 	| 	exp |  exp 
> 	| 	exp *  exp 
> 	| 	exp /  exp  
> 	| 	exp +  exp  
> 	| 	exp -  exp  
> 	| 	exp =  exp 
> 	| 	exp > exp 
> 	| 	exp >= exp 
> 	| 	exp < exp 
> 	| 	exp <= exp 
> 	| 	exp <> exp 
> 	| 	INTEGER_LITERAL
> 	| 	STRING_LIT	
> 	| 	( exp_seq )
> 	| 	( )
> 
> I tried this but no luck:
> 
> exp				: expr (binaryOp expr)*;
> expr			: 	LET decs "in" exp END 
> 				| 	IF exp THEN exp (ELSE exp)? 
> END 
> 				| 	FOR ID ASSIGN  exp TO exp DO 
> exp END 
> 				| 	WHILE exp DO exp END 
> 				| 	lvalue (ASSIGN exp)? 
> 				| 	builtin 
> 				| 	ID LBRACKET (arg_seq )? 
> RBRACKET 
> 				| 	INTEGER_LITERAL 
> 				| 	STRING_LIT 
> 				| 	LBRACKET exp_seq RBRACKET 
> 				| 	LBRACKET RBRACKET ;
> 				
> binaryOp		:  AMPERSAND
> 				| OR
> 				| STAR
> 				| DIV
> 				| PLUS
> 				| MINUS
> 				| EQUAL
> 				| GT
> 				| GTEQ
> 				| LT
> 				| LTEQ
> 				| NOTEQ;


 

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




More information about the antlr-interest mailing list