[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (also possibly naive) question regarding cst -> ast

On Mon, Dec 16, 2002 at 02:13:19PM -0500, Donald Ball wrote:
> First, thanks to everyone who responded to my previous question. Tagging
> the repeated elements with [name]:s worked perfectly. My grammar is now
> working as I expect and the world is a happy place. On to the next
> problem...
> I am now trying (I think) to turn the concrete syntax tree generated by my
> parser into an abstract syntax tree suitable for editing using a GUI tool.
> For instance, a subset of my grammar contains these productions:
>     condition =
>         {term} boolean_term |
>         {or} condition or boolean_term;
>     boolean_term =
>         {factor} boolean_factor |
>         {and} boolean_term and boolean_factor;
> which generates, among other things, nodes named AOrCondition,
> ATermCondition, AFactorBooleanTerm, and AAndBooleanTerm. My (pre-existing)
> abstract syntax tree simply contains a CompoundClause which represents both
> AND and OR clauses. I think that I need to write some sort of visitor that
> walks the CST (left-to-right, probably?) and builds an AST, turning
> AORCondition and AAndBooleanTerm nodes into ConditionClauses, while pretty
> much ignoring the ATermCondition and AFactorBooleanTerm nodes.

Yep, that would be the approach I would take. There are plans to have
automatic AST generation in SableCC 3.0

> Am I on the right track here? Is there a model out there from which I can
> steal code or design patterns? Any pseudocode anyone can suggest?

You can extend the parser class, so that the AST is built during parse
time, instead of after the CST has been constructed. There is an example

> Thanks in advance for any help.

Okay, bye.

> - donald