I'd say arm yourself with some good spare hours and read:
http://sablecc.org/thesis/thesis.html#PAGE52
Then you may want to also look at some implemenations for example
MiniBasic interpreter:
http://sourceforge.net/project/showfiles.php?group_id=5704
Greg
On 6/25/06, Jörn Guy Süß <jgsuess@xxxxxxxxxxxxxx> wrote:
> Hello!
>
> I am trying to write a serialisation of a file parse to Prolog. Since my
> grammar is quite long, I wanted to produce a general solution, which can
> generate source-code to serialize all AST-based sable grammars.
>
> I have loaded my grammar into the SableCC 3.2 tree structure, and now wanted
> to visit it, reading each AST production. However, I find that after just
> the parse, the AST is not filled in.
>
> I have found that there are several children of the DepthFirstAdapter in
> SableCC, including one called AddAstProductions(), but I have no idea how
> they work or which to pick and what the order should be.
>
> Below is the class I have use to test the behaviour. It prints all
> productions in the CST, then says "entering AST", prints the line "grammar"
> and is done. Debug shows that the ast is actually empty.
>
>
> package de.tuberlin.cs.cis.ocl.parser.test;
>
> import java.io.PrintWriter;
> import java.io.Writer;
>
> import org.sablecc.sablecc.analysis.DepthFirstAdapter;
> import org.sablecc.sablecc.node.AAst;
> import org.sablecc.sablecc.node.AProd;
> import org.sablecc.sablecc.node.AProductions;
>
> final class PrologSerializer extends DepthFirstAdapter {
>
> private final Writer _out;
>
> private final String _fileName;
>
> private boolean _inAst;
>
> public PrologSerializer() {
> this(new PrintWriter(System.out),
> String.valueOf(Math.random()));
> }
>
> public PrologSerializer(Writer out, String fileName) {
> super();
> _out = out;
> _fileName = fileName;
> }
>
> public void inAProductions(AProductions arg0) {
> // System.out.print(arg0.toString());
> // TODO Auto-generated method stub
> super.inAProductions(arg0);
> }
>
> public void inAAst(AAst arg0) {
> System.out.println("Entering ast " + arg0.toString());
> super.inAAst(arg0);
> }
>
> public void inAProd(AProd arg0) {
> System.out.println(arg0.toString());
> super.inAProd(arg0);
> }
>
>
> private boolean isInAst() {
> return _inAst;
> }
>
> private void setInAst(boolean inAst) {
> _inAst = inAst;
> }
>
>
>
> }
>
>
> Jörn Guy Süß
>
> Research Officer
>
> Room 350, General Purpose South Building (building 78) Division of Systems
> and Software Engineering School of Information Technology and Electrical
> Engineering The University of Queensland Queensland 4072 AUSTRALIA
>
> Phone: +61 7 3365 2883; Fax: +61 7 3365 4999
>
> email: jgsuess@xxxxxxxxxxxxxx
>
>
>
>
>
> _______________________________________________
> SableCC-user mailing list
> SableCC-user@xxxxxxxxxxx
> http://sablecc.org/lists/control/listinfo/sablecc-user
>