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

Jeff Kenton <jeffrey.kenton@comcast.net>
Sat, 19 May 2007 09:47:10 -0400

          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)
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)
[1 later articles]
| List of all articles for this month |

From: Jeff Kenton <jeffrey.kenton@comcast.net>
Newsgroups: comp.compilers
Date: Sat, 19 May 2007 09:47:10 -0400
Organization: Compilers Central
References: 07-05-067
Keywords: parse, symbols
Posted-Date: 20 May 2007 22:07:21 EDT

Ryan,


A few things are unclear. First, look at your language and make sure
that there's nothing that's truly ambiguous. Second, it looks from your
example as if identifiers aren't necessarily declared before they're
used, except perhaps in function declarations. If that's true, when do
you know what they are? Are they declared anywhere? Dimensioned? Or
else, what are the rules for assuming types and dimensions? Furthermore,
in your example it seems that "i" is declared in the statement "Function
do_something(i As Integer)". What information about "i" are you missing?


In general, you should be building the symbol table as you parse. If
there is information about an identifier that's missing, that should be
explicitly noted as you proceed. If it's still missing when you finish
parsing, you will need to report errors or apply defaults, depending on
the language specifications.


Overall, my first reaction is that you language sample looks a little
confusing. Your function declarations have parentheses but your
function calls don't. You seem to have mixed your "Dim" statement with
an assignment. Even if your language isn't exactly ambiguous, you might
find that you have made it difficult to parse (and to code) correctly,
and that a little redesign would help. In any case, when you're
parsing, you should be gathering as much information as you can, as soon
as you can. Even noting that information is missing and will have to be
found later is useful to know.


Good luck,


jeff




Ryan Dary wrote:
> 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.
> ...
>
> Function do_something( i As Integer ) As Integer
> Dim a As Integer = i + 10
> do_something_else i
> Return a * 5
> End Function
> ... 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.


Post a followup to this message

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