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

Ryan Dary <iecc@ryandary.com>
Thu, 17 May 2007 21:43:38 -0700

          From comp.compilers

Related articles
Am I parsing this correctly? (when do I build the symbol table) iecc@ryandary.com (Ryan Dary) (2007-05-17)
Re: Am I parsing this correctly? (when do I build the symbol table) wyrmwif@tsoft.org (SM Ryan) (2007-05-19)
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)
[6 later articles]
| List of all articles for this month |

From: Ryan Dary <iecc@ryandary.com>
Newsgroups: comp.compilers
Date: Thu, 17 May 2007 21:43:38 -0700
Organization: Compilers Central
Keywords: parse, question
Posted-Date: 19 May 2007 00:40:54 EDT

I'm working on a phase of my compiler. The language is similar to
Visual Basic, and I want to know if I'm parsing this correctly.


Right now, I am walking through the tokens, and building up a tree
like structure so that I have nodes like Program, Function, Class,
etc. Then, as I'm parsing some of the source lines, I am actually
skipping them right now because it seems impossible to know what the
tokens mean until I have built a symbol table of all the functions,
etc. Perhaps I have this phase a bit backwards...


Take a look at this source code, and then I'll explain some problems
that I'm having...




Sub do_something_else( byRef i As Integer )
            i = i * 10
End Sub


Function do_something( i As Integer ) As Integer
            Dim a As Integer = i + 10
            do_something_else i
            Return a * 5
End Function




My understanding of the syntax tree is that I'm not supposed to be
worried about the "meaning" of the code, but rather the "structure" of
the code. So, I'm not building a symbol tree at this phase... the
problem with that seems to be that I'm unable to make heads or tails
of the lines of code within the function declaration. 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?


So, hopefully, my nonsense explanation of my problem will make sense to
someone who can shed some light on my question. Thanks in advance.


- Ryan Dary


Post a followup to this message

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