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

(also possibly naive) question regarding cst -> ast



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.

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?

Thanks in advance for any help.

- donald