[antlr-interest] Newbie questions: How to traverse the AST ...

Agnisys agnisys at yahoo.com
Sun Dec 31 16:59:05 PST 2006


Hi Rajesh,
 I'm using 2.7.7 so I converted your code but when running Antlr on it I got the following. Once
again the  problem is that '=' can be in the RHS.

ANTLR Parser Generator   Version 2.7.7 (20060930)   1989-2005
menon.g:12: warning:nondeterminism upon
menon.g:12:     k==1:"="
menon.g:12:     between alt 1 and exit branch of block

  Here is my conversion:

class FlexParser  extends Parser;
expressions
	:	(expression)*
	;
expression
	:	lhs EQUALS rhs NEWLINE!
	;
lhs
	:	IDENTIFIER
	;
rhs
	:	lhs(EQUALS rhs)*
	|	NUMBER
	;
class FlexLexer extends Lexer;
options {
	k=2;
}
tokens {
	EQUALS="=";
}
NEWLINE :('\r''\n')=> '\r''\n' //DOS
     | '\n'                  //UNIX
     { newline(); }
     ;
IDENTIFIER
	:	('a'..'z'|'A'..'Z'|'_') ('a'..'z'|'A'..'Z'|'0'..'9'|'_')*
	;
NUMBER
	:	('0'..'9')+('.'('0'..'9')+)?
	;	

Thanks for your help,
Anupam.



More information about the antlr-interest mailing list