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

Re: grammar questions

Hi Indrek,

One last thing.  For complex grammars, SableCC generates the "concrete
syntax tree" (CST), but what you would really like to do is to work with
an "abstract syntax tree" (AST).  For this, you definitely need to do
AST transformations (using hidden alternatives) to simplify your AST and
only keep relevant information.  You certainly don't want your stmt-noif
productions to remain for later compilation stages.

You can look in the archives for discussions about this, and at Othman
Alaoui's JOOS compiler for an example of how to do this (
http://www.sable.mcgill.ca/~hendren/520/a-source_java.html ).

Ideally, you should perform the AST transformation at parse time to
reduce memory consumption.  You should design it and test it as a
post-parse transformation, then when debugged, make it into a parse time
transformation (using "filter").  Thanks to the visitor pattern, this
should be strait-forward.

Have fun!

Etienne M. Gagnon, M.Sc.                     e-mail: egagnon@j-meg.com
Author of SableCC:                             http://www.sablecc.org/
and SableVM:                                   http://www.sablevm.org/