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) |
From: | Hans-Peter Diettrich <DrDiettrich1@aol.com> |
Newsgroups: | comp.compilers |
Date: | 26 Mar 2007 09:11:38 -0400 |
Organization: | Compilers Central |
References: | 07-03-073 07-03-085 |
Keywords: | parse, AST |
Posted-Date: | 26 Mar 2007 09:11:38 EDT |
leppoc@gmail.com wrote:
> A good idea is to use AST (Abstract Syntax Tree). To do so, make for
> each type of Tree, a struct, or object.
And don't forget to add an node type to the basic node structure, so
that a visitor can know who is who. An extended "operator" enum,
covering all node types, will be helpful.
> 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.
Trees should not be write-only. There exists no absolutely best
implementation for trees, but the list oriented approach (LISP...) IMO
is the most flexible one, with regards to postprocessing of trees.
DoDi
Return to the
comp.compilers page.
Search the
comp.compilers archives again.