/plugins/JavaSideKick/tags/javasidekick-2-3-1/src/sidekick/java/parser/TigerParser.java
# · Java · 2340 lines · 2099 code · 89 blank · 152 comment · 382 complexity · 9694de4aaba2bb9e4b2e4269e0020066 MD5 · raw file
Large files are truncated click here to view the full file
- /* Generated By:JavaCC: Do not edit this line. TigerParser.java */
- package sidekick.java.parser;
- import sidekick.java.node.*;
- import sidekick.java.util.Log;
- import java.io.*;
- import java.util.*;
- /**
- * Based on grammar to parse Java version 1.5 written by Sreenivasa Viswanadha,
- * parses a java file for the JavaSideKick plugin to provide a java code
- * browser that works with java 1.5. I've also updated this file so it will
- * parse javacc files for JavaSideKick too, that makes it a lot easier to edit
- * files such as this.
- * <p>
- * Example usage to parse a java file:<p>
- * <code>
- * TigerParser parser = new TigerParser(filename);<br>
- * CUNode root = parser.getJavaRootNode();<br>
- * </code>
- * or to parse a javacc file:<br>
- * <code>
- * TigerParser parser = new TigerParser(filename);<br>
- * CUNode root = parser.getJavaCCRootNode();<br>
- * </code>
- * Calling either of the above causes the file to be parsed into
- * TigerNodes, of which, CUNode is the top-level. The TigerNodes have a parent/
- * child relastionship, which naturally forms a tree structure.
- * <p>
- * To turn this .jj file into a .java file, run <code>javacc Tiger.jj</code>
- * from the directory that contains this file. Javacc will produce a number of
- * .java files, Be careful -- not all files in the directory are produced by
- * javacc, in particular ModifierSet.java and Token.java are required files and
- * are NOT produced by javacc. So the sequence is:<br>
- * .jj -> javacc -> .java -> javac -> .class
- * <p>
- */
- public class TigerParser implements TigerParserConstants {
- // accumulates counts of classes, interfaces, methods and fields.
- private Results results = new Results();
- private InputStream inputStream = null;
- /**
- * Constructor for TigerParser. Note that JavaSideKick does not use this
- * constructor -- since the options for building the parser have both
- * USER_TOKEN_MANAGER and USER_CHAR_STREAM set to false (these are the
- * default values so are not explicitly set), javacc will create a
- * constructor "public TigerParser(InputStream)". It is that constructor
- * that JavaSideKick uses.
- * @param fileName name of the file to parse
- */
- public TigerParser(String filename)
- {
- this(System.in);
- try {
- inputStream = new FileInputStream(new File(filename));
- ReInit(inputStream);
- }
- catch(Exception e) {
- e.printStackTrace();
- }
- }
- TigerParser(JavaCharStream stream) {
- jj_input_stream = stream;
- token_source = new TigerParserTokenManager(jj_input_stream);
- token = new Token();
- jj_ntk = -1;
- }
- /**
- * @return the accumulated counts of classes, interfaces, methods, and fields.
- */
- public Results getResults() {
- return results;
- }
- public Location getLocation(Token t) {
- if (t == null)
- return new Location(0, 0);
- return new Location(t.beginLine, t.beginColumn);
- }
- public Location getEndLocation(Token t) {
- if (t == null)
- return new Location(0, 0);
- return new Location(t.endLine, t.endColumn);
- }
- public Location getLocation(Modifier m) {
- if (m == null)
- return new Location(0, 0);
- if (m.beginLine == -1)
- m.beginLine = 0;
- return new Location(m.beginLine, m.beginColumn);
- }
- public void error_skipto(int kind) {
- ParseException e = generateParseException(); // generate the exception object.
- addException(e);
- Token t = null;
- int i = 0;
- do {
- i++;
- if (i > 100) {
- break;
- }
- t = getNextToken();
- } while (t != null && t.kind != kind);
- }
- private List exceptions = new ArrayList();
- private void addException(ParseException pe) {
- ErrorNode en = new ErrorNode(pe);
- exceptions.add(en);
- }
- public List getErrors() {
- return exceptions;
- }
- public void adjustModifier(Modifier m, Token t) {
- if (m.beginLine < t.beginLine) {
- m.beginLine = t.beginLine;
- }
- if (m.beginLine == t.beginLine && (t.beginColumn < m.beginColumn || m.beginColumn == -1)) {
- m.beginColumn = t.beginColumn;
- }
- if (m.endLine < t.endLine) {
- m.endLine = t.endLine;
- }
- if (m.endLine == t.endLine && m.endColumn < t.endColumn) {
- m.endColumn = t.endColumn;
- }
- }
- public void setTabSize(int size) {
- jj_input_stream.setTabSize(size);
- }
- public int getTabSize() {
- return jj_input_stream.getTabSize(0);
- }
- /*
- * Returns true if the next token is not in the FOLLOW list of "expansion".
- * It is used to decide when the end of an "expansion" has been reached.
- */
- private boolean notTailOfExpansionUnit() {
- Token t;
- t = getToken(1);
- if (t.kind == BIT_OR || t.kind == COMMA || t.kind == RPAREN || t.kind == RBRACE || t.kind == RBRACKET) return false;
- return true;
- }
- /* returns a list as a comma separated string */
- private String toString(List list) {
- if (list != null) {
- StringBuffer sb = new StringBuffer();
- for (Iterator it = list.iterator(); it.hasNext(); ) {
- Object o = it.next();
- if (o == null) {
- o = "null";
- }
- sb.append(o.toString());
- if (it.hasNext()) {
- sb.append(",");
- }
- }
- return sb.toString();
- }
- return "";
- }
- private String toTigerString(List list) {
- if (list != null) {
- StringBuffer sb = new StringBuffer();
- for (Iterator it = list.iterator(); it.hasNext(); ) {
- TigerNode tn = (TigerNode)it.next();
- sb.append(tn.getName()).append(", ");
- if (tn.getChildCount() > 0) {
- sb.append(toTigerString(tn.getChildren()));
- }
- }
- return sb.toString();
- }
- return "";
- }
- /************************************************
- * THE JAVACC GRAMMAR SPECIFICATION STARTS HERE *
- ************************************************/
- final public CUNode getJavaCCRootNode(int tab_size) throws ParseException {
- setTabSize(tab_size);
- CUNode n = new CUNode();
- List children = null;
- children = javacc_input();
- if (children != null ) {
- for (Iterator it = children.iterator(); it.hasNext(); ) {
- n.addChild((TigerNode)it.next());
- }
- }
- {if (true) return n;}
- throw new Error("Missing return statement in function");
- }
- final public List javacc_input() throws ParseException {
- List children = new ArrayList();
- TigerNode options_node = null;
- Token parser_node_start_t = null;
- Token parser_node_end_t = null;
- Token cunode_start_t = null;
- Token cunode_end_t = null;
- TigerNode production_node = null;
- TigerNode cunode = null;
- TigerNode parser_node = new TigerNode(){public int getOrdinal(){return TigerNode.PARSER;}};
- options_node = javacc_options();
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("PARSER_BEGIN")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- parser_node_start_t = jj_consume_token(IDENTIFIER);
- jj_consume_token(LPAREN);
- identifier();
- cunode_start_t = jj_consume_token(RPAREN);
- cunode = CompilationUnit(getTabSize());
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("PARSER_END")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- cunode_end_t = jj_consume_token(IDENTIFIER);
- jj_consume_token(LPAREN);
- identifier();
- parser_node_end_t = jj_consume_token(RPAREN);
- label_1:
- while (true) {
- production_node = production();
- children.add(production_node);
- if (jj_2_1(1)) {
- ;
- } else {
- break label_1;
- }
- }
- jj_consume_token(0);
- if (options_node != null) {
- children.add(options_node);
- }
- if (parser_node_start_t != null && parser_node_end_t != null ) {
- parser_node.setName("PARSER");
- parser_node.setStartLocation(getLocation(parser_node_start_t));
- parser_node.setEndLocation(getEndLocation(parser_node_end_t));
- children.add(parser_node);
- if (cunode != null) {
- cunode.setStartLocation(getLocation(cunode_start_t));
- cunode.setEndLocation(getEndLocation(cunode_end_t));
- if (cunode.getChildren() != null ) {
- for (Iterator it = cunode.getChildren().iterator(); it.hasNext(); ) {
- parser_node.addChild((TigerNode)it.next());
- }
- }
- else {
- parser_node.addChild(cunode);
- }
- }
- }
- {if (true) return children;}
- throw new Error("Missing return statement in function");
- }
- final public TigerNode javacc_options() throws ParseException {
- TigerNode tn = new TigerNode() {public int getOrdinal() { return TigerNode.OPTIONS;}};
- Token start_t = null;
- Token end_t = null;
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("options")) {
- start_t = jj_consume_token(IDENTIFIER);
- jj_consume_token(LBRACE);
- label_2:
- while (true) {
- option_binding();
- if (jj_2_2(1)) {
- ;
- } else {
- break label_2;
- }
- }
- end_t = jj_consume_token(RBRACE);
- } else {
- ;
- }
- tn.setName("options");
- tn.setStartLocation(getLocation(start_t));
- tn.setEndLocation(getEndLocation(end_t));
- {if (true) return tn;}
- throw new Error("Missing return statement in function");
- }
- final public void option_binding() throws ParseException {
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("LOOKAHEAD")) {
- identifier();
- } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("IGNORE_CASE")) {
- identifier();
- } else {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IDENTIFIER:
- jj_consume_token(IDENTIFIER);
- break;
- case STATIC:
- jj_consume_token(STATIC);
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- jj_consume_token(ASSIGN);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case INTEGER_LITERAL:
- IntegerLiteral();
- break;
- case FALSE:
- case TRUE:
- BooleanLiteral();
- break;
- case STRING_LITERAL:
- StringLiteral();
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- jj_consume_token(SEMICOLON);
- }
- final public TigerNode production() throws ParseException {
- TigerNode tn = null;
- if (jj_2_3(1)) {
- /*
- * Since JAVACODE is both a JavaCC reserved word and a Java identifier,
- * we need to give preference to "javacode_production" over
- * "bnf_production".
- */
- tn = javacode_production();
- } else if (jj_2_4(1)) {
- /*
- * Since SKIP, TOKEN, etc. are both JavaCC reserved words and Java
- * identifiers, we need to give preference to "regular_expression_production"
- * over "bnf_production".
- */
- tn = regular_expr_production();
- } else if (jj_2_5(1)) {
- /*
- * Since TOKEN_MGR_DECLS is both a JavaCC reserved word and a Java identifier,
- * we need to give preference to "token_manager_decls" over
- * "bnf_production".
- */
- tn = token_manager_decls();
- } else {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case BOOLEAN:
- case BYTE:
- case CHAR:
- case DOUBLE:
- case FLOAT:
- case INT:
- case LONG:
- case SHORT:
- case VOID:
- case IDENTIFIER:
- tn = bnf_production();
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- {if (true) return tn;}
- throw new Error("Missing return statement in function");
- }
- final public TigerNode javacode_production() throws ParseException {
- JavaCodeProductionNode mn = new JavaCodeProductionNode();
- List params = null;
- Token start_t = null;
- Type resultType = null;
- String identifier = "";
- BlockNode bn = null;
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("JAVACODE")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- start_t = jj_consume_token(IDENTIFIER);
- resultType = ResultType();
- identifier = identifier();
- params = FormalParameters();
- if (jj_2_6(2)) {
- jj_consume_token(THROWS);
- Name();
- label_3:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_3;
- }
- jj_consume_token(COMMA);
- Name();
- }
- } else {
- ;
- }
- if (jj_2_7(2)) {
- node_descriptor();
- } else {
- ;
- }
- bn = Block();
- if (start_t != null){
- mn.setStartLocation(getLocation(start_t));
- }
- if (resultType != null) {
- mn.setReturnType(resultType);
- }
- mn.setName(identifier);
- if (params != null) {
- mn.setFormalParams(params);
- }
- if (bn != null) {
- mn.setEndLocation(bn.getEndLocation());
- mn.addChild(bn);
- }
- {if (true) return mn;}
- throw new Error("Missing return statement in function");
- }
- final public TigerNode bnf_production() throws ParseException {
- BNFProductionNode mn = new BNFProductionNode();
- List params = null;
- Type resultType = null;
- String identifier = "";
- Token end_t = null;
- BlockNode java_block = null;
- resultType = ResultType();
- identifier = identifier();
- params = FormalParameters();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case THROWS:
- jj_consume_token(THROWS);
- Name();
- label_4:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_4;
- }
- jj_consume_token(COMMA);
- Name();
- }
- break;
- default:
- ;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 125:
- node_descriptor();
- break;
- default:
- ;
- }
- jj_consume_token(COLON);
- java_block = Block();
- jj_consume_token(LBRACE);
- expansion_choices();
- end_t = jj_consume_token(RBRACE);
- if (resultType != null) {
- mn.setStartLocation(resultType.getStartLocation());
- mn.setReturnType(resultType);
- }
- mn.setName(identifier);
- if (params != null) {
- mn.setFormalParams(params);
- }
- if (end_t != null ) {
- mn.setEndLocation(getEndLocation(end_t));
- }
- if (java_block != null) {
- mn.addChild(java_block);
- }
- {if (true) return mn;}
- throw new Error("Missing return statement in function");
- }
- final public TigerNode regular_expr_production() throws ParseException {
- Token start_t = null;
- Token end_t = null;
- Token t = null;
- TigerNode tn = new RegexProductionNode();
- Token kind = null;
- StringBuffer lexical_state_list = new StringBuffer();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LT:
- if (jj_2_8(2)) {
- start_t = jj_consume_token(LT);
- jj_consume_token(STAR);
- jj_consume_token(GT);
- lexical_state_list.append("<*>");
- } else {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LT:
- start_t = jj_consume_token(LT);
- t = jj_consume_token(IDENTIFIER);
- lexical_state_list.append("<").append(t.image);
- label_5:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_5;
- }
- jj_consume_token(COMMA);
- t = jj_consume_token(IDENTIFIER);
- lexical_state_list.append(",").append(t.image);
- }
- jj_consume_token(GT);
- lexical_state_list.append(">");
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- break;
- default:
- ;
- }
- kind = regexpr_kind();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LBRACKET:
- jj_consume_token(LBRACKET);
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("IGNORE_CASE")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- jj_consume_token(IDENTIFIER);
- jj_consume_token(RBRACKET);
- break;
- default:
- ;
- }
- jj_consume_token(COLON);
- jj_consume_token(LBRACE);
- regexpr_spec();
- label_6:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case BIT_OR:
- ;
- break;
- default:
- break label_6;
- }
- jj_consume_token(BIT_OR);
- regexpr_spec();
- }
- end_t = jj_consume_token(RBRACE);
- if (lexical_state_list.length() > 0) {
- tn.setName(lexical_state_list.toString());
- }
- else if (kind != null) {
- tn.setName(kind.image);
- }
- tn.setStartLocation(getLocation(start_t == null ? kind : start_t));
- tn.setEndLocation(getEndLocation(end_t));
- {if (true) return tn;}
- throw new Error("Missing return statement in function");
- }
- final public TigerNode token_manager_decls() throws ParseException {
- Token start_t = null;
- BlockNode bn = null;
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("TOKEN_MGR_DECLS")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- start_t = jj_consume_token(IDENTIFIER);
- jj_consume_token(COLON);
- bn = TokenMgrDeclBlock();
- TigerNode tn = new TokenMgrDeclProductionNode();
- tn.setName(start_t.image);
- tn.setStartLocation(getLocation(start_t));
- if (bn != null) {
- tn.setEndLocation(bn.getEndLocation());
- tn.addChildren(bn.getChildren());
- }
- {if (true) return tn;}
- throw new Error("Missing return statement in function");
- }
- final public Token regexpr_kind() throws ParseException {
- Token t = null;
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("TOKEN")) {
- t = jj_consume_token(IDENTIFIER);
- } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("SPECIAL_TOKEN")) {
- t = jj_consume_token(IDENTIFIER);
- } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("SKIP")) {
- t = jj_consume_token(IDENTIFIER);
- } else if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("MORE")) {
- t = jj_consume_token(IDENTIFIER);
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- {if (true) return t;}
- throw new Error("Missing return statement in function");
- }
- final public void regexpr_spec() throws ParseException {
- regular_expression();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LBRACE:
- Block();
- break;
- default:
- ;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COLON:
- jj_consume_token(COLON);
- jj_consume_token(IDENTIFIER);
- break;
- default:
- ;
- }
- }
- final public void expansion_choices() throws ParseException {
- expansion();
- label_7:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case BIT_OR:
- ;
- break;
- default:
- break label_7;
- }
- jj_consume_token(BIT_OR);
- expansion();
- }
- }
- final public void expansion() throws ParseException {
- if (jj_2_9(1)) {
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("LOOKAHEAD")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- jj_consume_token(IDENTIFIER);
- jj_consume_token(LPAREN);
- local_lookahead();
- jj_consume_token(RPAREN);
- } else {
- ;
- }
- label_8:
- while (true) {
- expansion_unit();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 125:
- node_descriptor();
- break;
- default:
- ;
- }
- if (notTailOfExpansionUnit()) {
- ;
- } else {
- break label_8;
- }
- }
- }
- final public void local_lookahead() throws ParseException {
- boolean commaAtEnd = false, emptyLA = true;
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case INTEGER_LITERAL:
- IntegerLiteral();
- emptyLA = false;
- break;
- default:
- ;
- }
- if (!emptyLA && (getToken(1).kind != RPAREN)) {
- jj_consume_token(COMMA);
- commaAtEnd = true;
- } else {
- ;
- }
- if (getToken(1).kind != RPAREN && getToken(1).kind != LBRACE) {
- expansion_choices();
- emptyLA = false; commaAtEnd = false;
- } else {
- ;
- }
- if (!emptyLA && !commaAtEnd && (getToken(1).kind != RPAREN)) {
- jj_consume_token(COMMA);
- commaAtEnd = true;
- } else {
- ;
- }
- if (emptyLA || commaAtEnd) {
- jj_consume_token(LBRACE);
- Expression();
- jj_consume_token(RBRACE);
- } else {
- ;
- }
- }
- final public void expansion_unit() throws ParseException {
- if (jj_2_11(1)) {
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("LOOKAHEAD")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- jj_consume_token(IDENTIFIER);
- jj_consume_token(LPAREN);
- local_lookahead();
- jj_consume_token(RPAREN);
- } else {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LBRACE:
- Block();
- break;
- case LBRACKET:
- jj_consume_token(LBRACKET);
- expansion_choices();
- jj_consume_token(RBRACKET);
- break;
- case TRY:
- jj_consume_token(TRY);
- jj_consume_token(LBRACE);
- expansion_choices();
- jj_consume_token(RBRACE);
- label_9:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case CATCH:
- ;
- break;
- default:
- break label_9;
- }
- jj_consume_token(CATCH);
- jj_consume_token(LPAREN);
- Name();
- jj_consume_token(IDENTIFIER);
- jj_consume_token(RPAREN);
- Block();
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case FINALLY:
- jj_consume_token(FINALLY);
- Block();
- break;
- default:
- ;
- }
- break;
- default:
- if (jj_2_12(2147483647)) {
- if (jj_2_10(2147483647)) {
- PrimaryExpression();
- jj_consume_token(ASSIGN);
- } else {
- ;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STRING_LITERAL:
- case LT:
- regular_expression();
- break;
- case IDENTIFIER:
- identifier();
- Arguments();
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- } else {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LPAREN:
- jj_consume_token(LPAREN);
- expansion_choices();
- jj_consume_token(RPAREN);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case HOOK:
- case PLUS:
- case STAR:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PLUS:
- jj_consume_token(PLUS);
- break;
- case STAR:
- jj_consume_token(STAR);
- break;
- case HOOK:
- jj_consume_token(HOOK);
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- break;
- default:
- ;
- }
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- }
- }
- }
- final public void regular_expression() throws ParseException {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STRING_LITERAL:
- StringLiteral();
- break;
- default:
- if (jj_2_13(3)) {
- jj_consume_token(LT);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IDENTIFIER:
- case 125:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case 125:
- jj_consume_token(125);
- break;
- default:
- ;
- }
- identifier();
- jj_consume_token(COLON);
- break;
- default:
- ;
- }
- complex_regular_expression_choices();
- jj_consume_token(GT);
- } else if (jj_2_14(2)) {
- jj_consume_token(LT);
- identifier();
- jj_consume_token(GT);
- } else {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LT:
- jj_consume_token(LT);
- if (getToken(1).kind == IDENTIFIER && getToken(1).image.equals("EOF")) {
- } else {
- jj_consume_token(-1);
- throw new ParseException();
- }
- jj_consume_token(IDENTIFIER);
- jj_consume_token(GT);
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- }
- }
- final public void complex_regular_expression_choices() throws ParseException {
- complex_regular_expression();
- label_10:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case BIT_OR:
- ;
- break;
- default:
- break label_10;
- }
- jj_consume_token(BIT_OR);
- complex_regular_expression();
- }
- }
- final public void complex_regular_expression() throws ParseException {
- label_11:
- while (true) {
- complex_regular_expression_unit();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STRING_LITERAL:
- case LPAREN:
- case LBRACKET:
- case LT:
- case TILDE:
- ;
- break;
- default:
- break label_11;
- }
- }
- }
- final public void complex_regular_expression_unit() throws ParseException {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STRING_LITERAL:
- StringLiteral();
- break;
- case LT:
- jj_consume_token(LT);
- identifier();
- jj_consume_token(GT);
- break;
- case LBRACKET:
- case TILDE:
- character_list();
- break;
- case LPAREN:
- jj_consume_token(LPAREN);
- complex_regular_expression_choices();
- jj_consume_token(RPAREN);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case HOOK:
- case PLUS:
- case STAR:
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PLUS:
- jj_consume_token(PLUS);
- break;
- case STAR:
- jj_consume_token(STAR);
- break;
- case HOOK:
- jj_consume_token(HOOK);
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- break;
- default:
- ;
- }
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- final public void character_list() throws ParseException {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case TILDE:
- jj_consume_token(TILDE);
- break;
- default:
- ;
- }
- jj_consume_token(LBRACKET);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STRING_LITERAL:
- character_descriptor();
- label_12:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_12;
- }
- jj_consume_token(COMMA);
- character_descriptor();
- }
- break;
- default:
- ;
- }
- jj_consume_token(RBRACKET);
- }
- final public void character_descriptor() throws ParseException {
- StringLiteral();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case MINUS:
- jj_consume_token(MINUS);
- StringLiteral();
- break;
- default:
- ;
- }
- }
- final public String identifier() throws ParseException {
- Token t = null;
- t = jj_consume_token(IDENTIFIER);
- {if (true) return t.image;}
- throw new Error("Missing return statement in function");
- }
- /**********************************************
- * THE JJTREE PRODUCTIONS START HERE *
- **********************************************/
- final public void node_descriptor() throws ParseException {
- jj_consume_token(125);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IDENTIFIER:
- jj_consume_token(IDENTIFIER);
- break;
- case VOID:
- jj_consume_token(VOID);
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LPAREN:
- jj_consume_token(LPAREN);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case GT:
- jj_consume_token(GT);
- break;
- default:
- ;
- }
- node_descriptor_expression();
- jj_consume_token(RPAREN);
- break;
- default:
- ;
- }
- }
- void node_descriptor_expression() throws ParseException {
- Token tok;
- int nesting = 1;
- while (true) {
- tok = getToken(1);
- if (tok.kind == 0) {
- throw new ParseException();
- }
- if (tok.kind == LPAREN) nesting++;
- if (tok.kind == RPAREN) {
- nesting--;
- if (nesting == 0) break;
- }
- tok = getNextToken();
- }
- }
- /* javacc productions */
- final public void IntegerLiteral() throws ParseException {
- jj_consume_token(INTEGER_LITERAL);
- }
- final public void StringLiteral() throws ParseException {
- jj_consume_token(STRING_LITERAL);
- }
- /*****************************************
- * THE JAVA LANGUAGE GRAMMAR STARTS HERE *
- *****************************************/
- /*
- * Program structuring syntax follows.
- */
- final public CUNode getJavaRootNode(int tab_size) throws ParseException {
- CUNode n = null;
- n = JavaCompilationUnit(tab_size);
- {if (true) return n;}
- throw new Error("Missing return statement in function");
- }
- /**
- * Main entry point for parsing the PARSER section in javacc files. Use
- * JavaCompilationUnit as main entry point for parsing java files.
- * @return a CUNode, which is parent or root node of all other nodes.
- */
- final public CUNode CompilationUnit(int tab_size) throws ParseException {
- setTabSize(tab_size);
- CUNode n = new CUNode();
- TigerNode a;
- String packageName = "";
- ImportNode in = null;
- try {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PACKAGE:
- packageName = PackageDeclaration();
- break;
- default:
- ;
- }
- label_13:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IMPORT:
- ;
- break;
- default:
- break label_13;
- }
- in = ImportDeclaration();
- n.addImport(in);
- }
- label_14:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case ABSTRACT:
- case CLASS:
- case ENUM:
- case FINAL:
- case INTERFACE:
- case NATIVE:
- case PRIVATE:
- case PROTECTED:
- case PUBLIC:
- case STATIC:
- case STRICTFP:
- case SYNCHRONIZED:
- case TRANSIENT:
- case VOLATILE:
- case SEMICOLON:
- case AT:
- ;
- break;
- default:
- break label_14;
- }
- a = TypeDeclaration();
- n.addChild(a);
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- n.setPackageName(packageName);
- {if (true) return n;}
- throw new Error("Missing return statement in function");
- }
- /**
- * Main entry point for parsing java files.
- * @return a CUNode, which is parent or root node of all other nodes.
- */
- final public CUNode JavaCompilationUnit(int tab_size) throws ParseException {
- CUNode n = null;
- Token end_t = null;
- try {
- n = CompilationUnit(tab_size);
- // read the whole file
- end_t = jj_consume_token(0);
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- if (end_t != null) {
- n.setEndLocation(getLocation(end_t));
- }
- {if (true) return n;}
- throw new Error("Missing return statement in function");
- }
- final public String PackageDeclaration() throws ParseException {
- TigerNode name = null;
- try {
- jj_consume_token(PACKAGE);
- name = Name();
- jj_consume_token(SEMICOLON);
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- {if (true) return name == null ? "" : name.getName();}
- throw new Error("Missing return statement in function");
- }
- /**
- * @return just the package name, without the 'import' or 'static' or '.*', e.g.
- * "import java.util.*;" will return "java.util". A fully qualified import will
- * return the full classname, e.g. "import java.util.List;" will return
- * "java.util.List", this is also the case with static imports, e.g.
- * "import static java.lang.Math.PI;" will return "java.lang.Math.PI".
- */
- final public ImportNode ImportDeclaration() throws ParseException {
- TigerNode name = null;
- Token st = null;
- Token et = null;
- try {
- st = jj_consume_token(IMPORT);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case STATIC:
- jj_consume_token(STATIC);
- break;
- default:
- ;
- }
- name = Name();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case DOT:
- jj_consume_token(DOT);
- jj_consume_token(STAR);
- break;
- default:
- ;
- }
- et = jj_consume_token(SEMICOLON);
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- if (name != null) {
- ImportNode in = new ImportNode(name.getName());
- //in.setStartLocation(name.getStartLocation());
- //in.setEndLocation(name.getEndLocation());
- in.setStartLocation(getLocation(st));
- in.setEndLocation(getEndLocation(et));
- {if (true) return in;}
- }
- {if (true) return null;}
- throw new Error("Missing return statement in function");
- }
- /*
- * Modifiers. We match all modifiers in a single rule to reduce the chances of
- * syntax errors for simple modifier mistakes. It will also enable us to give
- * better error messages.
- */
- final public Modifier Modifiers() throws ParseException {
- int modifiers = 0;
- Token t = null;
- Modifier m = new Modifier();
- label_15:
- while (true) {
- if (jj_2_15(2)) {
- ;
- } else {
- break label_15;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case PUBLIC:
- t = jj_consume_token(PUBLIC);
- modifiers |= ModifierSet.PUBLIC; adjustModifier(m, t);
- break;
- case STATIC:
- t = jj_consume_token(STATIC);
- modifiers |= ModifierSet.STATIC; adjustModifier(m, t);
- break;
- case PROTECTED:
- t = jj_consume_token(PROTECTED);
- modifiers |= ModifierSet.PROTECTED; adjustModifier(m, t);
- break;
- case PRIVATE:
- t = jj_consume_token(PRIVATE);
- modifiers |= ModifierSet.PRIVATE; adjustModifier(m, t);
- break;
- case FINAL:
- t = jj_consume_token(FINAL);
- modifiers |= ModifierSet.FINAL; adjustModifier(m, t);
- break;
- case ABSTRACT:
- t = jj_consume_token(ABSTRACT);
- modifiers |= ModifierSet.ABSTRACT; adjustModifier(m, t);
- break;
- case SYNCHRONIZED:
- t = jj_consume_token(SYNCHRONIZED);
- modifiers |= ModifierSet.SYNCHRONIZED; adjustModifier(m, t);
- break;
- case NATIVE:
- t = jj_consume_token(NATIVE);
- modifiers |= ModifierSet.NATIVE; adjustModifier(m, t);
- break;
- case TRANSIENT:
- t = jj_consume_token(TRANSIENT);
- modifiers |= ModifierSet.TRANSIENT; adjustModifier(m, t);
- break;
- case VOLATILE:
- t = jj_consume_token(VOLATILE);
- modifiers |= ModifierSet.VOLATILE; adjustModifier(m, t);
- break;
- case STRICTFP:
- t = jj_consume_token(STRICTFP);
- modifiers |= ModifierSet.STRICTFP; adjustModifier(m, t);
- break;
- case AT:
- Annotation();
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- }
- m.modifiers = modifiers;
- {if (true) return m;}
- throw new Error("Missing return statement in function");
- }
- /*
- * Declaration syntax follows.
- */
- // Handle classes, interfaces, enums, and annotations.
- final public TigerNode TypeDeclaration() throws ParseException {
- Modifier modifier;
- TigerNode tn = null;
- try {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case SEMICOLON:
- jj_consume_token(SEMICOLON);
- break;
- case ABSTRACT:
- case CLASS:
- case ENUM:
- case FINAL:
- case INTERFACE:
- case NATIVE:
- case PRIVATE:
- case PROTECTED:
- case PUBLIC:
- case STATIC:
- case STRICTFP:
- case SYNCHRONIZED:
- case TRANSIENT:
- case VOLATILE:
- case AT:
- modifier = Modifiers();
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case CLASS:
- case INTERFACE:
- tn = ClassOrInterfaceDeclaration(modifier);
- break;
- case ENUM:
- tn = EnumDeclaration(modifier);
- break;
- case AT:
- AnnotationTypeDeclaration(modifier);
- tn = null;
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- {if (true) return tn;}
- throw new Error("Missing return statement in function");
- }
- /**
- * @return a ClassNode or an InterfaceNode
- */
- final public TigerNode ClassOrInterfaceDeclaration(Modifier m) throws ParseException {
- boolean isInterface = false;
- Token t = null;
- TigerNode kids = null; // only need the children of this node
- String type_params = "";
- List extends_list = null;
- List implements_list = null;
- Token type = null;
- try {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case CLASS:
- type = jj_consume_token(CLASS);
- break;
- case INTERFACE:
- type = jj_consume_token(INTERFACE);
- isInterface = true;
- break;
- default:
- jj_consume_token(-1);
- throw new ParseException();
- }
- t = jj_consume_token(IDENTIFIER);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LT:
- type_params = TypeParameters();
- break;
- default:
- ;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case EXTENDS:
- extends_list = ExtendsList(isInterface);
- break;
- default:
- ;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IMPLEMENTS:
- implements_list = ImplementsList(isInterface);
- break;
- default:
- ;
- }
- kids = ClassOrInterfaceBody(isInterface);
- if (jj_2_16(2)) {
- jj_consume_token(SEMICOLON);
- } else {
- ;
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- ClassNode node = isInterface ? new InterfaceNode(t.image, m.modifiers) : new ClassNode(t.image, m.modifiers);
- if (isInterface)
- results.incInterfaceCount();
- else
- results.incClassCount();
- if (m.beginColumn > -1) {
- node.setStartLocation(getLocation(m) );
- }
- else {
- node.setStartLocation(getLocation(type));
- }
- if (kids != null)
- node.setEndLocation(kids.getEndLocation());
- // add the child nodes, don't need the 'kids' node itself, it's just a holder
- // for the nodes I want (although I do want the end location).
- if (kids != null && kids.getChildren() != null)
- node.addChildren(kids.getChildren());
- node.setTypeParams(type_params);
- node.setExtendsList(extends_list);
- node.setImplementsList(implements_list);
- {if (true) return node;}
- throw new Error("Missing return statement in function");
- }
- /**
- * @return a list of sidekick.java.node.Types representing items in an 'extends'
- * list, e.g. the "Bar" in "public class Foo extends Bar"
- */
- final public List ExtendsList(boolean isInterface) throws ParseException {
- boolean extendsMoreThanOne = false;
- List list = new ArrayList(); // a list of Types
- Type type_s = null;
- Type type_a = null;
- try {
- jj_consume_token(EXTENDS);
- type_s = ClassOrInterfaceType();
- list.add(type_s);
- label_16:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_16;
- }
- jj_consume_token(COMMA);
- type_a = ClassOrInterfaceType();
- extendsMoreThanOne = true; list.add(type_a);
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- if (extendsMoreThanOne && !isInterface)
- {if (true) throw new ParseException("A class cannot extend more than one other class");}
- {if (true) return list;}
- throw new Error("Missing return statement in function");
- }
- /**
- * @return a list of sidekick.java.node.Types representing items in an 'implements'
- * list, e.g. the "Bar" and "Serializable" in "public class Foo implements Bar, Serializable"
- */
- final public List ImplementsList(boolean isInterface) throws ParseException {
- List list = new ArrayList();
- Type type_s = null;
- Type type_a = null;
- try {
- jj_consume_token(IMPLEMENTS);
- type_s = ClassOrInterfaceType();
- list.add(type_s);
- label_17:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_17;
- }
- jj_consume_token(COMMA);
- type_a = ClassOrInterfaceType();
- list.add(type_a);
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- if (isInterface)
- {if (true) throw new ParseException("An interface cannot implement other interfaces");}
- {if (true) return list;}
- throw new Error("Missing return statement in function");
- }
- /**
- * @return an EnumNode
- */
- final public TigerNode EnumDeclaration(Modifier m) throws ParseException {
- Token t = null;
- Token start_t = null;
- Location end_loc = null;
- try {
- start_t = jj_consume_token(ENUM);
- t = jj_consume_token(IDENTIFIER);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case IMPLEMENTS:
- ImplementsList(false);
- break;
- default:
- ;
- }
- end_loc = EnumBody();
- } catch (ParseException pe) {
- if (t == null) {
- // handle the case where old code used 'enum' as a variable name
- ParseException e = new ParseException("Parse error at line " + start_t.beginLine + ", column " + start_t.beginColumn + ". Encountered: 'enum' as an identifier, 'enum' is a keyword.");
- addException(e);
- {if (true) return null;}
- }
- else
- error_skipto(SEMICOLON);
- }
- if (t == null) {
- // handle the case where old code used 'enum' as a variable name
- ParseException e = new ParseException("Parse error at line " + start_t.beginLine + ", column " + start_t.beginColumn + ". Encountered: 'enum' as an identifier, 'enum' is a keyword.");
- addException(e);
- {if (true) return null;}
- }
- EnumNode node = new EnumNode(t.image, m.modifiers);
- if (start_t != null) {
- if (m.beginColumn == -1)
- node.setStartLocation(getLocation(start_t));
- else
- node.setStartLocation(getLocation(m));
- }
- if (end_loc != null)
- node.setEndLocation(end_loc);
- {if (true) return node;}
- throw new Error("Missing return statement in function");
- }
- // returns the end location of the enum body
- final public Location EnumBody() throws ParseException {
- Token t = null;
- try {
- jj_consume_token(LBRACE);
- EnumConstant();
- label_18:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_18;
- }
- jj_consume_token(COMMA);
- EnumConstant();
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case SEMICOLON:
- jj_consume_token(SEMICOLON);
- label_19:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case ABSTRACT:
- case BOOLEAN:
- case BYTE:
- case CHAR:
- case CLASS:
- case DOUBLE:
- case ENUM:
- case FINAL:
- case FLOAT:
- case INT:
- case INTERFACE:
- case LONG:
- case NATIVE:
- case PRIVATE:
- case PROTECTED:
- case PUBLIC:
- case SHORT:
- case STATIC:
- case STRICTFP:
- case SYNCHRONIZED:
- case TRANSIENT:
- case VOID:
- case VOLATILE:
- case IDENTIFIER:
- case LBRACE:
- case SEMICOLON:
- case AT:
- case LT:
- ;
- break;
- default:
- break label_19;
- }
- ClassOrInterfaceBodyDeclaration(false);
- }
- break;
- default:
- ;
- }
- t = jj_consume_token(RBRACE);
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- {if (true) return t == null ? null : getLocation(t);}
- throw new Error("Missing return statement in function");
- }
- /// what is this? Should I be handling it?
- final public void EnumConstant() throws ParseException {
- try {
- jj_consume_token(IDENTIFIER);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LPAREN:
- Arguments();
- break;
- default:
- ;
- }
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case LBRACE:
- ClassOrInterfaceBody(false);
- break;
- default:
- ;
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- }
- /**
- * @return a string representing a generics type, e.g. the "<String>" in
- * "List<String> list = new List();", the string will contain the angle brackets.
- */
- final public String TypeParameters() throws ParseException {
- String s = "<";
- String a = "";
- try {
- jj_consume_token(LT);
- a = TypeParameter();
- s += a;
- label_20:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case COMMA:
- ;
- break;
- default:
- break label_20;
- }
- jj_consume_token(COMMA);
- s += ",";
- a = TypeParameter();
- s += a;
- }
- jj_consume_token(GT);
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- {if (true) return s + ">";}
- throw new Error("Missing return statement in function");
- }
- final public String TypeParameter() throws ParseException {
- String s = "";
- Token t = null;
- try {
- t = jj_consume_token(IDENTIFIER);
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case EXTENDS:
- s = TypeBound();
- break;
- default:
- ;
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- StringBuffer sb = new StringBuffer();
- if (t.image != null)
- sb.append(t.image);
- if (s.length() > 0)
- sb.append(" ").append(s);
- {if (true) return sb.toString();}
- throw new Error("Missing return statement in function");
- }
- final public String TypeBound() throws ParseException {
- String s = "extends";
- Type type_s = null;
- Type type_a = null;
- try {
- jj_consume_token(EXTENDS);
- type_a = ClassOrInterfaceType();
- s += " " + type_a.toString();
- label_21:
- while (true) {
- switch ((jj_ntk==-1)?jj_ntk():jj_ntk) {
- case BIT_AND:
- ;
- break;
- default:
- break label_21;
- }
- jj_consume_token(BIT_AND);
- s += " & ";
- type_a = ClassOrInterfaceType();
- s += type_a.toString();
- }
- } catch (ParseException pe) {
- error_skipto(SEMICOLON);
- }
- {if (true) return s;}
- throw new Error("Missing return statement in function");
- }
- /**
- * @return a node representing the contents of a Class or Interface body. The
- * returned node is simply a holder for the contents, it is the children of this
- * node that is useful as they are the methods and fields of the class or
- * interface.
- */
- final public TigerNode ClassOrInterfaceBody(boolean isInterface) throws ParseException {
- TigerNode parent = new TigerNode("", -1);
- TigerNode child;
- Token start_t = null;
- Token end_t = null;
- try {
- start_t = jj_consume_token(LBRACE);…