Parser RB code

3 views
Skip to first unread message

Thomas Tempelmann

unread,
Feb 12, 2006, 7:46:04 PM2/12/06
to REALs...@googlegroups.com
OK, this time for the correct mailing list:

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

Scott Steinman

unread,
Feb 12, 2006, 9:28:47 PM2/12/06
to REALs...@googlegroups.com
Hi 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

Jonathan Johnson

unread,
Feb 13, 2006, 10:50:08 AM2/13/06
to REALsource
The way that I've wanted a AST is to simply deal with a statement by
statement view of the source. This is the most consistent way to deal
with things, because if there are missing end if's, or missing next
statements, the grammar will cause syntax errors when parsing. However,
if you form an array of statements, you can then use another routine to
link together the begins and ends of blocks, classes, modules, etc.
This is much better, because you can detect symantec errors, such as
using End for a For loop.

Just my two cents :)

Reply all
Reply to author
Forward
0 new messages