[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Parse Trees and Bison
From: |
chris . cranford |
Subject: |
Parse Trees and Bison |
Date: |
Thu, 22 Apr 2004 13:15:52 -0400 |
I'm trying to understand the best way by adding C functions to my BISON
grammer file to being able to generate a syntax tree of my source code.
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?
Then going back up the stack, where do I create the nodes for my syntax tree?
Thanks in advance!
Chris
- Parse Trees and Bison,
chris . cranford <=