Re: Sytnax Tree Construction

Yves Deweerdt <yves@news.be>
9 Sep 2003 23:05:31 -0400

          From comp.compilers

Related articles
Sytnax Tree Construction chris@labino.net (2003-09-04)
Re: Sytnax Tree Construction blackmarlin@asean-mail.com (2003-09-09)
Re: Sytnax Tree Construction yves@news.be (Yves Deweerdt) (2003-09-09)
| List of all articles for this month |

From: Yves Deweerdt <yves@news.be>
Newsgroups: comp.compilers
Date: 9 Sep 2003 23:05:31 -0400
Organization: Planet Internet
References: 03-09-024
Keywords: analysis
Posted-Date: 09 Sep 2003 23:05:31 EDT

> I understand the generation of a tree from an expression: 4+2*var:
> +
> / \
> 4 *
> / \
> 2 var
>
> But for instance, how do you handle the actual language keywords. For
> instance, how would a tree be build for the BASIC code:
>
> DO
> x=x+2
> IF x=12
> PRINT "x=12"
> ELSEIF x=14
> PRINT "x=14"
> ELSE CALL function()
> ENDIF
> LOOP WHILE x<>20
>


why do you consider '+' to be an operation taking 2 operands?


and why don't you think of a DO WHILE as an operator too?
it also takes to operands, one being a condition and the other operand
being the statement to execute over and over again until the condition
expires.


let's keep it simple:


DO
    x=x+2
LOOP WHILE x < 20


would be something like this:




                          DO-WHILE
                        / \
                      = <
                    / \ / \
                  x + x 20
                        / \
                      x 2




when you take your expression, you know that when it holds a '+' you
have to take the 2 operands and count them together
now, for the 'DO-WHILE' node, you have to repeat the evaluation of the
left subtree until the right subtree condition evaluates to false...



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.