Re: Am I parsing this correctly? (when do I build the symbol table)

Uli Kusterer <ulimakesacompiler@googlemail.com>
Sun, 20 May 2007 13:18:32 +0200

          From comp.compilers

Related articles
[2 earlier articles]
Re: Am I parsing this correctly? (when do I build the symbol table) mailbox@dmitry-kazakov.de (Dmitry A. Kazakov) (2007-05-19)
Re: Am I parsing this correctly? (when do I build the symbol table) DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-05-19)
Re: Am I parsing this correctly? (when do I build the symbol table) mburrel@uwo.ca (Mike Burrell) (2007-05-19)
Re: Am I parsing this correctly? (when do I build the symbol table) jeffrey.kenton@comcast.net (Jeff Kenton) (2007-05-19)
Re: Am I parsing this correctly? (when do I build the symbol table) gneuner2@comcast.net (George Neuner) (2007-05-19)
Re: Am I parsing this correctly? (when do I build the symbol table) 148f3wg02@sneakemail.com (Karsten Nyblad) (2007-05-20)
Re: Am I parsing this correctly? (when do I build the symbol table) ulimakesacompiler@googlemail.com (Uli Kusterer) (2007-05-20)
Re: Am I parsing this correctly? (when do I build the symbol table) chris.dollin@hp.com (Chris Dollin) (2007-05-21)
Re: Am I parsing this correctly? (when do I build the symbol table) ulimakesacompiler@googlemail.com (Uli Kusterer) (2007-05-22)
Re: Am I parsing this correctly? (when do I build the symbol table) gah@ugcs.caltech.edu (glen herrmannsfeldt) (2007-05-23)
Re: Am I parsing this correctly? (when do I build the symbol table) paul@paul-robinson.us (Paul Robinson) (2007-05-31)
| List of all articles for this month |

From: Uli Kusterer <ulimakesacompiler@googlemail.com>
Newsgroups: comp.compilers
Date: Sun, 20 May 2007 13:18:32 +0200
Organization: Compilers Central
References: 07-05-067
Keywords: parse, symbols
Posted-Date: 20 May 2007 22:08:03 EDT

On 18.05.2007, at 06:43, Ryan Dary wrote:
> For instance,
> as I parse the Dim statement (which is used to declare a variable), I
> am able to parse the components "Dim a As Integer = <exp>" where the
> <exp> (expression) seems to be impossible to really parse without
> having a symbol table thus far in the parsing. I wouldn't know if "i"
> is a variable or a function or a constant, because I don't have any
> way of looking it up in a symbol table. So, should I be building the
> symbol table as I'm parsing the syntax tree from the tokens?


    Now, I don't have any formal teaching in compilers and parsers, but
I've wiggled through quite well with books and the web and my own
attempts so far, and I think you're right here. You will need to know
whether a certain word is a user-defined type, a variable or
whatever, unless you do like PHP or some other languages which
explicitly mark variables with an operator ("$myVar" and the likes,
or have keywords uppercase and the rest lowercase, or whatever...).


    Of course, depending on the nature of your language, you might get
away with breaking it up some more without having a symbol table .
The end of the line is indicated by return characters, a line that
starts with "Dim" is a variable definition/declaration, a function
call is an identifier immediately followed by a parameter list in
brackets... You can scan ahead to find out about such things for some
languages. For the code snippet you posted, that might even work.
Depends on what else the language can do.


    I don't know enough about the rules of the syntax tree to tell you
whether that's a good idea, mind you. I usually just tokenize and
then parse right away, building my symbol table as I go. But then I
usually create a variant of HyperTalk, where you neither specially
mark, nor declare variables, so it's simply impossible to parse
without the kind of context provided by a symbol table.


Cheers,
-- M. Uli Kusterer
http://www.zathras.de


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.