How to use SableCCSableCC is a full compiler compiler. It is a Java-based tool that performs the same job as flex/bison. There are two versions of SableCC that you can use, SableCC 2 and SableCC 3. However, since SableCC 3 accepts SableCC 2 grammars, you will actually use the same Java tool for both.The difference between them is that SableCC 3 has special rules for CST->AST transformations and an AST productions section. If you want SableCC 3 to behave like SableCC 2, just omit the transformations and the AST section. 1. Making sure prerequisites are installedBefore you can use these instructions, you should first follow the instructions on using Subversion in this class and setting up your environment for JOOS programs. This will ensure that Java 1.5 is on your PATH and that you have a local copy of SableCC 3.2.
2. Setting up your environmentWe need to set up some additional environment variables:
SABLECCDIRAssuming you have checked out the public_html directory from the class SVN repository to$HOME/cs520/public_html ,
add the following:
setenv SABLECCDIR $HOME/cs520/public_html/sablecc/sablecc-3.2 or
export SABLECCDIR=$HOME/cs520/public_html/sablecc/sablecc-3.2
to your PATHNow we would thesablecc script on our PATH for easy
execution. Add the following:
setenv PATH $SABLECCDIR/bin:$PATH or
export PATH=$SABLECCDIR/bin:$PATH
to your 3. Using SableCCNow that SableCC is installed, you can input your grammar:
$ sablecc grammar.txt
This will generate many directories. You should not add
them to the Subversion repository since it is expected that you
will write a 4. ExamplesThere are many examples of SableCC in use that you can learn from:
5. DocumentationThe documentation for SableCC 2 is excellent. The documentation of the SableCC 3 AST extensions is somewhat lacking in comparison, but the information you need is generally available.
If you have questions that your instructor or TA are not able to answer, you can also subscribe to the SableCC mailing list or email Etienne Gagnon directly. Please be sure to send a copy of any questions or responses to your instructor or TA. |
Maintained by Eric Bodden. [HOME] |