[antlr-interest] ANTLR v3: enum as identifier and as a keyword
Tarun Khanna
tarunkhanna at gmail.com
Fri Jul 1 06:01:03 PDT 2005
Great...
Thanks a lot for you help. Although That brings up my second question. Is
there a general solution for implementing symbol tables in ANTLR, or do I
have to define some sort of a hash table to achieve that. I guess if I were
implementing a symbol table in yacc with C I would have a structure or a
class to do that.
And is there a way to handle scope also provided in ANTLR itself.
I had a gut feeling that since ANTLR provides so much functionality, there
would be some way of handling the symbol tables also.
I would be highly appreciate if you could provide some help with these
questions. If there are any books or articles that I can refer to, pleases
do provide some pointers to those if possible.
thanks again
Tarun Khanna
On 6/30/05, Terence Parr <parrt at cs.usfca.edu> wrote:
>
> On Jun 30, 2005, at 2:01 PM, Tarun Khanna wrote:
>
> > 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;
>
> Well, statements and declarations of functions occur in different
> contexts so this one is easy. In general though you need a symbol
> table and then use semantic predicates that ask if LT(1).getText() is
> in the symbol table as a type. if so, that tells you how to
> distinguish between (T) as an expression and (T) as a typecast for
> example.
>
> Ter
> --
> CS Professor & Grad Director, University of San Francisco
> Creator, ANTLR Parser Generator, http://www.antlr.org
> Cofounder, http://www.jguru.com
>
>
--
Tarun Khanna
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20050701/4a51c96e/attachment-0001.html
More information about the antlr-interest
mailing list