[antlr-interest] ANTLR v3: enum as identifier and as a keyword

Tarun Khanna tarunkhanna at gmail.com
Thu Jun 30 14:02:03 PDT 2005


Now is there a good way of differentiating between identifiers and type 
names/keywords in general? For example in a language like C/C++ 

A function definition can begin with a type name (such as int). 
------------> int func(int a);
But any expression can also begin with an identifier. 
---------------------------> sum += var1;

Syntactic Predicates is one way of doing it, but it doesn't help in the 
following rule for example.

prog: (declarations)* (expressions)* EOF

Now if the FIRST sets of both declarations and expressions are the same, the 
parser would never know, when to stop looking at declarations and when to 
start looking for expressions. 
I keep getting the all so famous Non Determinism warnings between alt1 and 
the exit block. I know why I am getting the warnings, but I can't think of a 
way to remove them.

What would be a good way to resolve such an ambiguity?
Does it make sense to define tokens in the lexer for all the typeNames, so 
that whenever a lexer sees a token like int, it returns the associated 
token.

I am new to ANTLR and for the past few days I have been breaking my head in 
both going through the documentation and also looking for a good source of 
help for ANTLR, as currently there seems to be no good guide to using ANTLR. 
All the links on the ANRL.org <http://anrl.org/> website are only good for 
getting started as the section in which they are found points out. The 
Manual itself is either not complete or is not very well organized.

Thanks Tarun
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050630/8927d87e/attachment.html


More information about the antlr-interest mailing list