/* This is a skeleton of a JavaCC parser specification. You are best off simply filling in the missing grammar rules. */ options { LOOKAHEAD = 2; CHOICE_AMBIGUITY_CHECK = 2; OTHER_AMBIGUITY_CHECK = 1; STATIC = true; DEBUG_PARSER = false; DEBUG_LOOKAHEAD = false; DEBUG_TOKEN_MANAGER = false; ERROR_REPORTING = true; JAVA_UNICODE_ESCAPE = false; UNICODE_INPUT = false; IGNORE_CASE = false; USER_TOKEN_MANAGER = false; USER_CHAR_STREAM = false; BUILD_PARSER = true; BUILD_TOKEN_MANAGER = true; SANITY_CHECK = true; FORCE_LA_CHECK = false; } PARSER_BEGIN(Parser) package pointless; public class Parser { public static void main(String args[]) throws ParseException { Parser parser = new Parser(System.in); Node x = parser.Input(); x.print(0); } } PARSER_END(Parser) SKIP : { " " | "\r" | "\t" //fill in comments and mult-line comments. | "\n" } Node Input() : {Node out;} { out = Program(new Node("root")) { return out;} } //here's an example of a formatted grammer rule Node Program(Node parent) :{ Node child; } { ( (child = Function() | child = Record() | child = GlobalDecl()) { parent.children.add(child); } )* { return parent; } } RecordNode Record(): { RecordNode $rec = new RecordNode(); } { "record" $rec.name = TypeId() "{" (Decl($rec.children) ";")* "}" { return $rec; }} // Now, you should be able to fill in the rest. // feel free to modify the above rules, they are only there // as examples. //here is one way to define id. String Id(): { Token t; StringBuffer b = new StringBuffer(); } { ( ( ( t = < IDSYM: (["a" - "z" ] ( [ "A" - "Z", "a" - "z", "0" - "9", "_" ] ) * ) > ) { b.append(t.image);} ) ) { return b.toString(); } }