[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Symbol tables and scopes
Hi all!
"Etienne M. Gagnon" wrote:
>
> > Does SableCC include support for symbol tables and management of
> > (nested)scopes?
>
> There comes the magic of OO and Java:-)
>
> 1- You design a SymbolTable class, that probably uses a Hashtable object
> to associate strings with declaration nodes.
> 2- You extend your preferred tree walker (probably DepthFirstAdapter),
> and use a Stack field to push/pop SymbolTable objects as you enter/leave
> a scope.
>
> This is one way of doing it.
>
> Etienne
I thought more about construction of scopes while parsing and building
the ast.
I'm not quite sure if this is necessary, probably I have to work at a
different edge. What I like to do/have is to descide if an identifier is
read if this is a TYPE or a VARIABLE, so when a type is defined I need
to update the symboltable while parsing and the lexer needs to have to
look up if it returns a TYPE token or an IDENTIFIER token.
I thought for stuff like this you allready might have a standard symbol
table.
Anyway, if you like to support a typedef keyword like in C/C++ how would
you manage to insert the new type into a symbol table after the ';' is
read?
Regards,
Angelo
----------------------------------------------------------------------
Angelo Schneider OOAD/UML Angelo.Schneider@oomentor.de
Putlitzstr. 24 Patterns/FrameWorks Fon: +49 721 9812465
76137 Karlsruhe C++/JAVA Fax: +49 721 9812467