specifications – SKIP, TOKEN, SPECIAL_TOKEN, MORE • List of productions – non terminal declaration followed by ; – declarations and statements within {} – lexical tokens as strings or regular expressions – use non terminals with [...] – actions Aggelos Biboudis 4
generated token manager (or scanner/lexical analyzer). • <MyParser>Constants.java: A bunch of useful constants. • Also some boilerplate at "Token.java", "ParseException.java" Aggelos Biboudis 5
at line 25, column 3 and line 31, column 3 respectively. A common prefix is: <ID> Consider using a lookahead of 2 for earlier expansion. Aggelos Biboudis 10
generates – Syntax tree classes based on productions in grammar – Visitor design pattern – Visitor and GJVisitor interfaces – Two depth-first visitors: DepthFirstVisitor (simply for visiting) and GJDepthFirst (with generic return and args) – A JavaCC grammar (output jtb.out.jj. It builds the tree during parsing). Aggelos Biboudis 13
Code a Visitor that is used in the jj (FreeVarFinderVisitor in the example) • javacc jtb.out.jj • javac SubScheme.java • java SubScheme < inputfile Aggelos Biboudis 15
on the RHS of the production the public fields that are generated are of the following types – Node – NodeListInterface – NodeChoise – NodeList – NodeListOptional – NodeOptional – NodeSequence – NodeToken