|ASTs and Type Check Analysis email@example.com (CranCran77) (2008-08-20)|
|Re: ASTs and Type Check Analysis DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-08-24)|
|Re: ASTs and Type Check Analysis ArarghMail808@Arargh.com (2008-08-24)|
|Re: ASTs and Type Check Analysis firstname.lastname@example.org (CranCran77) (2008-08-25)|
|Re: ASTs and Type Check Analysis email@example.com (Bartc) (2008-08-25)|
|Re: ASTs and Type Check Analysis DrDiettrich1@aol.com (Hans-Peter Diettrich) (2008-08-26)|
|Date:||Wed, 20 Aug 2008 12:47:55 -0700 (PDT)|
|Posted-Date:||23 Aug 2008 14:41:34 EDT|
I am presently involved in a compiler project in C++ that is mirroring
the BASIC grammar extensively.
The early stages of this project is more of a proof of concept more
than diving too deeply into many extremities that will certainly prove
very challenging as this project moves forward. So far I've
developed a Lexer object that returns tokens to my Parser class. The
parser class currently reads these tokens and creates a very
simplistic AST tree.
For this proof of concept, I am using a very basic source file that
contains the following:
As I indicated above, we're using BASIC like grammar. The above
example would simply print to the screen the value of "20" and end if
it were to be compiled and executed.
We've taken the Parser to the point where it is creating a very
simplistic AST tree which would look something much like the following
for our example:
+- Name: PRINT
+- List Size: 1
+- Operation: '+'
+- Number: 2
+- Operation: *
+- Number: 3
+- Number: 6
Naturally once the AST tree is created above, I need to use visitor
patterns to do a number of passes. Since my example is extremely
simple, I can see three passes required:
- Pass #1 : Type Analysis
- Pass #2 : Constant Folding
- Pass #3 : Code Generation
Am I off base here ?
Where I am currently getting caught is in the first two phases. What
is the ideal way to layer type information into the AST tree, followed
by constant folding, followed by any other checks prior to compile
Keep in mind of course the next step will be to include variable
declarations and how to assign values to those variables and even
working with very simple function/procedure calls (both code specific
and external library calls to things like DLL functions).
Return to the
Search the comp.compilers archives again.