Due to complications with morphe I only now managed to creat the first
part of the AST.
I decided to create the tree in text first. Here's a sample:
Line{declaration_stmt{Vars{dynamic;Var_Type{Var{ID{ofs}};Var_Value{ID{Integer};}}}};;}
Line{Do{};;}
Line{:={ID{ofs};.{Me;ID{allSrcReadOfs}}};;}
Line{While{<>{.{ID{allSrc};(){ID{Byte};ID{ofs}}};ID{MyEOLnChar}}};;}
Line{:={ID{ofs};+{ID{ofs};Literal{Integer;1}}};;}
Line{Wend;;}
Line{Loop{};;}
I hope you can see the relationship to this code:
dim ofs as Integer
do
ofs = me . allSrcReadOfs
while allSrc.Byte (ofs) <> MyEOLnChar
ofs = ofs + 1
wend
loop
Oh well, not nice but it proves that it works, at least :)
Thomas
Very good progress on the parsing of statements, variables and IDs.
However, the parsing is still too line-oriented. A true abstract
syntax tree (AST) must be construct-based and not line-based, e.g.:
> Line{Do{};;}
> Line{Loop{};;}
treats the Do-Loop construct as two separate lines. This will be a
problem as you try to differentiate inner loops and outer loops, or
nested conditional statements from their enclosing conditional
statements.
The Do and Loop are beginning and end of one construct and should be
treated that way by the AST. A first step may perhaps be something
like using StartDoLoop and EndDoLoop, and a value that determines
which nesting level the Do-Loop corresponds to:
Declaration_stmt{Vars{dynamic;Var_Type{Var{ID{ofs}};Var_Value{ID
{Integer};}}}};;
StartDoLoop{level:1};;
Stmt{:={ID{ofs};.{Me;ID{allSrcReadOfs}}};;}
StartWhileLoop{(level:2}<>{.{ID{allSrc};(){ID{Byte};ID{ofs}}};ID
{MyEOLnChar}}};;}
Stmt{:={ID{ofs};+{ID{ofs};Literal{Integer;1}}};;}
EndWhileLoop(level:2);;
EndDoLoop{level:1};;
The next step, of course, would be converting this to a true tree
structure.
-Scott
Dr. Scott Steinman
Brought to you by a grant from the Steinman Foundation (Thanks, Mom
and Dad!)
Recommended by Major University Studies Over the Leading Brand
steinman at midsouth dot rr dot com
I hope I die peacefully in my sleep like my grandfather. . .not
screaming in terror like his passengers. -- "Deep Thoughts", Jack Handy
Just my two cents :)