help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Parse Trees and Bison


From: Urdaneta, Alfonso E (N-Summitt Technologies)
Subject: RE: Parse Trees and Bison
Date: Thu, 22 Apr 2004 15:29:49 -0400

> A simple program source file is as follows:
> 
>   Dim x as Integer = 2
>   Print x
> 
> A reduced version for this example of my grammer file is:
> 
>   program : lines ;
>   lines   : line lines ;
>   line    : stmt term ;
>   term    : ':' | '\n' ;
>   stmt    : /*empty */ | dim | print ;
>   dim     : tDIM ident tAS dtype tEQ expr |
>             tDIM ident tAS dtype ;
>   print   : tPRINT expr ;
>   ident   : tNAME ;
>   dtype   : tINTEGER | tREAL | tLONG ;
>   expr    : ident | tSTRING | tNUMBER ;
> 
> I know when I reach the "ident : tNAME;" rule that is when I 
> need to create a symbol and add the symbol to the current scope's
symbol 
> table.  There are no other symbols I should create right?

Well, you are going to get the ident thing first, and at that time you
won't know if its a variable declaration (and you won't know what type),
a function call, a variable assignment, etc., so creating a symbol table
entry at that stage is a little premature.  

As you get the info, store it, and then when the statement is complete,
start going through what you have, and populating your symbol table.
That's how I do it, there may be better ways.

--
I'm alfonso e. urdaneta, and I approve this message.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]