Re: about syntax trees

"leppoc@gmail.com" <leppoc@gmail.com>
23 Mar 2007 22:16:42 -0400

          From comp.compilers

Related articles
about syntax trees chinluchinawa@yahoo.co.uk (chinlu chinawa) (2007-03-19)
Re: about syntax trees grable0@gmail.com (grable) (2007-03-21)
Re: about syntax trees chinluchinawa@yahoo.co.uk (Chinlu) (2007-03-23)
Re: about syntax trees leppoc@gmail.com (leppoc@gmail.com) (2007-03-23)
Re: about syntax trees DrDiettrich1@aol.com (Hans-Peter Diettrich) (2007-03-26)
| List of all articles for this month |

From: "leppoc@gmail.com" <leppoc@gmail.com>
Newsgroups: comp.compilers
Date: 23 Mar 2007 22:16:42 -0400
Organization: Compilers Central
References: 07-03-073
Keywords: parse, AST
Posted-Date: 23 Mar 2007 22:16:42 EDT

> However I can see ast's being more like this all over
> the place:
>
> +
> /|\
> b | a
> *
> c




Hi,


A good idea is to use AST (Abstract Syntax Tree). To do so, make for
each type of Tree, a struct, or object.
e.g. in pseudo-code:


BinOp extends Tree {
    Tree leftOperand
    Tree rightOperand
    Operator operator //+, -, *, /, % ....
}


IfThenElse extends Tree {
    Tree condition
    Tree thenPart
    Tree elsePart
}


When you parse it with your recursive descent, you can almost directly
fill those trees.


Have Fun !


YC.


Post a followup to this message

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