Ss CC
Ss CC
SiCC
Simple Compiler Compiler
The Goal of a Compiler Compiler
The code that SiCC generates will tokenize and build a parse
tree, but it does not know what to do next, it cannot compile.
--package pakagename
includes all generated files in the given Java package
--prefix prefix
adds the given prefix to all generated classes
token.def grammar.def
--tokenizer-only tokens.def
--parser-only grammar.def
The SiCC Command
examples...
\ Escape, matches the next character (used to match operators, such as \+ or \[ or \:)
() Group patterns
[^abc] Negative character class, matches any character that is not within the brackets
SKIP
EOF
Rule names must be of only alphanumeric characters ('a' to 'b' and '0'
to '9') and must start with a letter.
The first rule is considered the starting rule and becomes the root of
the parse tree.
() Group patterns
[>1] Multiple child flag, must be places at the end of the definition,
signals that the rule should be included in the parse tree only
if the node has more than one child
Grammar Definition File
examples...
myvar = 5 + 6 * 4 myvar2 = 6 * 4
SiCC Generated Classes
ASTNode Base parse tree node class
Visitor<X,Y> An interface that uses the visitor pattern, used to traverse the
parse tree
Traversing the Parse Tree
parse tree nodes...
Basically:
class SuperApp {
// Simply call the parser's parse() method, which returns the root node
ASTEquationNode rootnode = parser.parse();
// Create a visitor
InterpretorVisitor() interpretor = new InterpretorVisitor();
// Start the traversal by visiting the root node, the output type and
meaning // depends on your Visitor implementation
String output = interpretor.visit(rootnode, null);
}
That's All There Is To It!