// $ANTLR start "unit" // SequenceWalker.g:20:1: unit returns [Unit result] : ^( UNIT WORD TERMINATOR ) ; public final Unit unit() throws RecognitionException { Unit result = null; CommonTree WORD1 = null; CommonTree TERMINATOR2 = null; try { // SequenceWalker.g:21:2: ( ^( UNIT WORD TERMINATOR ) ) // SequenceWalker.g:21:4: ^( UNIT WORD TERMINATOR ) { match(input, UNIT, FOLLOW_UNIT_in_unit75); match(input, Token.DOWN, null); WORD1 = (CommonTree) match(input, WORD, FOLLOW_WORD_in_unit77); TERMINATOR2 = (CommonTree) match(input, TERMINATOR, FOLLOW_TERMINATOR_in_unit79); match(input, Token.UP, null); result = new Unit( (WORD1 != null ? WORD1.getText() : null), (TERMINATOR2 != null ? TERMINATOR2.getText() : null)); } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return result; }
private String getLocatorName(CommonTree tree) { String text = tree.getText(); if (text.endsWith("://")) { return text.substring(0, text.length() - 3); } else { return null; } }
private Number getNumber(CommonTree tree) { String text = tree.getText(); if (text.contains(".")) { return Double.parseDouble(text); } else { return Integer.parseInt(text); } }
// $ANTLR start "formal" // FunChecker.g:207:1: formal returns [Type type] : ( ^( FORMAL t= type ID ) | NOFORMAL ); public final Type formal() throws RecognitionException { Type type = null; CommonTree ID6 = null; CommonTree FORMAL7 = null; Type t = null; try { // FunChecker.g:208:2: ( ^( FORMAL t= type ID ) | NOFORMAL ) int alt6 = 2; int LA6_0 = input.LA(1); if ((LA6_0 == FORMAL)) { alt6 = 1; } else if ((LA6_0 == NOFORMAL)) { alt6 = 2; } else { NoViableAltException nvae = new NoViableAltException("", 6, 0, input); throw nvae; } switch (alt6) { case 1: // FunChecker.g:208:4: ^( FORMAL t= type ID ) { FORMAL7 = (CommonTree) match(input, FORMAL, FOLLOW_FORMAL_in_formal234); match(input, Token.DOWN, null); pushFollow(FOLLOW_type_in_formal238); t = type(); state._fsp--; ID6 = (CommonTree) match(input, ID, FOLLOW_ID_in_formal240); match(input, Token.UP, null); define((ID6 != null ? ID6.getText() : null), t, FORMAL7); type = t; } break; case 2: // FunChecker.g:212:4: NOFORMAL { match(input, NOFORMAL, FOLLOW_NOFORMAL_in_formal252); type = Type.VOID; } break; } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return type; }
// $ANTLR start "var_decl" // FunChecker.g:216:1: var_decl : ^( VAR t1= type ID t2= expr ) ; public final void var_decl() throws RecognitionException { CommonTree ID8 = null; CommonTree VAR9 = null; Type t1 = null; Type t2 = null; try { // FunChecker.g:217:2: ( ^( VAR t1= type ID t2= expr ) ) // FunChecker.g:217:4: ^( VAR t1= type ID t2= expr ) { VAR9 = (CommonTree) match(input, VAR, FOLLOW_VAR_in_var_decl270); match(input, Token.DOWN, null); pushFollow(FOLLOW_type_in_var_decl274); t1 = type(); state._fsp--; ID8 = (CommonTree) match(input, ID, FOLLOW_ID_in_var_decl276); pushFollow(FOLLOW_expr_in_var_decl280); t2 = expr(); state._fsp--; match(input, Token.UP, null); define((ID8 != null ? ID8.getText() : null), t1, VAR9); checkType(t1, t2, VAR9); } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return; }
private String getString(CommonTree tree) { return tree.getText().substring(1, tree.getText().length() - 1); }
// $ANTLR start "propertyExpr" // nu/cotentin/parsing/cotentinel/CotentinELTree.g:67:1: propertyExpr returns [ExprNode result] : // (id= ID (acc= accessor )? (prop= propertyExpr )? ) ; public final ExprNode propertyExpr() throws RecognitionException { ExprNode result = null; CommonTree id = null; ExprNode acc = null; ExprNode prop = null; try { // nu/cotentin/parsing/cotentinel/CotentinELTree.g:67:39: ( (id= ID (acc= accessor )? (prop= // propertyExpr )? ) ) // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:2: (id= ID (acc= accessor )? (prop= // propertyExpr )? ) { // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:2: (id= ID (acc= accessor )? (prop= // propertyExpr )? ) // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:2: id= ID (acc= accessor )? (prop= // propertyExpr )? { id = (CommonTree) match(input, ID, FOLLOW_ID_in_propertyExpr246); if (state.failed) return result; // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:11: (acc= accessor )? int alt7 = 2; switch (input.LA(1)) { case NUMBER: case STRING: { alt7 = 1; } break; } switch (alt7) { case 1: // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:11: acc= accessor { pushFollow(FOLLOW_accessor_in_propertyExpr250); acc = accessor(); state._fsp--; if (state.failed) return result; } break; } // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:26: (prop= propertyExpr )? int alt8 = 2; switch (input.LA(1)) { case ID: { alt8 = 1; } break; } switch (alt8) { case 1: // nu/cotentin/parsing/cotentinel/CotentinELTree.g:68:26: prop= propertyExpr { pushFollow(FOLLOW_propertyExpr_in_propertyExpr255); prop = propertyExpr(); state._fsp--; if (state.failed) return result; } break; } } if (state.backtracking == 0) { result = new IdentifierNode(id.getText()); ExprNode cur = result; if (acc != null) { result.getChildren().add(acc); cur = acc; } if (prop != null) { cur.getChildren().add(prop); } } } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return result; }
// $ANTLR start "expr" // FunChecker.g:268:1: expr returns [Type type] : ( FALSE | TRUE | NUM | ID | ^( FUNCCALL ID t= // expr ) | ^( EQ t1= expr t2= expr ) | ^( LT t1= expr t2= expr ) | ^( GT t1= expr t2= expr ) | ^( // PLUS t1= expr t2= expr ) | ^( MINUS t1= expr t2= expr ) | ^( TIMES t1= expr t2= expr ) | ^( DIV // t1= expr t2= expr ) | ^( NOT t= expr ) | NOACTUAL ); public final Type expr() throws RecognitionException { Type type = null; CommonTree ID19 = null; CommonTree ID20 = null; CommonTree FUNCCALL21 = null; CommonTree EQ22 = null; CommonTree LT23 = null; CommonTree GT24 = null; CommonTree PLUS25 = null; CommonTree MINUS26 = null; CommonTree TIMES27 = null; CommonTree DIV28 = null; CommonTree NOT29 = null; Type t = null; Type t1 = null; Type t2 = null; try { // FunChecker.g:269:2: ( FALSE | TRUE | NUM | ID | ^( FUNCCALL ID t= expr ) | ^( EQ t1= expr // t2= expr ) | ^( LT t1= expr t2= expr ) | ^( GT t1= expr t2= expr ) | ^( PLUS t1= expr t2= // expr ) | ^( MINUS t1= expr t2= expr ) | ^( TIMES t1= expr t2= expr ) | ^( DIV t1= expr t2= // expr ) | ^( NOT t= expr ) | NOACTUAL ) int alt10 = 14; switch (input.LA(1)) { case FALSE: { alt10 = 1; } break; case TRUE: { alt10 = 2; } break; case NUM: { alt10 = 3; } break; case ID: { alt10 = 4; } break; case FUNCCALL: { alt10 = 5; } break; case EQ: { alt10 = 6; } break; case LT: { alt10 = 7; } break; case GT: { alt10 = 8; } break; case PLUS: { alt10 = 9; } break; case MINUS: { alt10 = 10; } break; case TIMES: { alt10 = 11; } break; case DIV: { alt10 = 12; } break; case NOT: { alt10 = 13; } break; case NOACTUAL: { alt10 = 14; } break; default: NoViableAltException nvae = new NoViableAltException("", 10, 0, input); throw nvae; } switch (alt10) { case 1: // FunChecker.g:269:4: FALSE { match(input, FALSE, FOLLOW_FALSE_in_expr479); type = Type.BOOL; } break; case 2: // FunChecker.g:271:4: TRUE { match(input, TRUE, FOLLOW_TRUE_in_expr490); type = Type.BOOL; } break; case 3: // FunChecker.g:273:4: NUM { match(input, NUM, FOLLOW_NUM_in_expr501); type = Type.INT; } break; case 4: // FunChecker.g:275:4: ID { ID19 = (CommonTree) match(input, ID, FOLLOW_ID_in_expr512); type = retrieve((ID19 != null ? ID19.getText() : null), ID19); } break; case 5: // FunChecker.g:278:4: ^( FUNCCALL ID t= expr ) { FUNCCALL21 = (CommonTree) match(input, FUNCCALL, FOLLOW_FUNCCALL_in_expr524); match(input, Token.DOWN, null); ID20 = (CommonTree) match(input, ID, FOLLOW_ID_in_expr526); pushFollow(FOLLOW_expr_in_expr530); t = expr(); state._fsp--; match(input, Token.UP, null); Type result = checkCall((ID20 != null ? ID20.getText() : null), t, FUNCCALL21); if (result.equiv(Type.VOID)) reportError("procedure should be non-void", FUNCCALL21); type = result; } break; case 6: // FunChecker.g:287:4: ^( EQ t1= expr t2= expr ) { EQ22 = (CommonTree) match(input, EQ, FOLLOW_EQ_in_expr543); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr547); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr551); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(COMPTYPE, t1, t2, EQ22); } break; case 7: // FunChecker.g:290:4: ^( LT t1= expr t2= expr ) { LT23 = (CommonTree) match(input, LT, FOLLOW_LT_in_expr564); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr568); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr572); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(COMPTYPE, t1, t2, LT23); } break; case 8: // FunChecker.g:293:4: ^( GT t1= expr t2= expr ) { GT24 = (CommonTree) match(input, GT, FOLLOW_GT_in_expr585); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr589); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr593); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(COMPTYPE, t1, t2, GT24); } break; case 9: // FunChecker.g:296:4: ^( PLUS t1= expr t2= expr ) { PLUS25 = (CommonTree) match(input, PLUS, FOLLOW_PLUS_in_expr606); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr610); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr614); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(ARITHTYPE, t1, t2, PLUS25); } break; case 10: // FunChecker.g:299:4: ^( MINUS t1= expr t2= expr ) { MINUS26 = (CommonTree) match(input, MINUS, FOLLOW_MINUS_in_expr627); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr631); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr635); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(ARITHTYPE, t1, t2, MINUS26); } break; case 11: // FunChecker.g:302:4: ^( TIMES t1= expr t2= expr ) { TIMES27 = (CommonTree) match(input, TIMES, FOLLOW_TIMES_in_expr648); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr652); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr656); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(ARITHTYPE, t1, t2, TIMES27); } break; case 12: // FunChecker.g:305:4: ^( DIV t1= expr t2= expr ) { DIV28 = (CommonTree) match(input, DIV, FOLLOW_DIV_in_expr669); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr673); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_expr677); t2 = expr(); state._fsp--; match(input, Token.UP, null); type = checkBinary(ARITHTYPE, t1, t2, DIV28); } break; case 13: // FunChecker.g:308:4: ^( NOT t= expr ) { NOT29 = (CommonTree) match(input, NOT, FOLLOW_NOT_in_expr690); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_expr694); t = expr(); state._fsp--; match(input, Token.UP, null); type = checkUnary(NOTTYPE, t, NOT29); } break; case 14: // FunChecker.g:310:4: NOACTUAL { match(input, NOACTUAL, FOLLOW_NOACTUAL_in_expr706); type = Type.VOID; } break; } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return type; }
// $ANTLR start "com" // FunChecker.g:231:1: com : ( ^( ASSN ID t= expr ) | ^( PROCCALL ID t= expr ) | ^( IF t= expr com // ) | ^( IFELSE t= expr com com ) | ^( WHILE t= expr com ) | ^( FOR ID t1= expr t2= expr com ) | // ^( SEQ ( com )* ) ); public final void com() throws RecognitionException { CommonTree ID10 = null; CommonTree ASSN11 = null; CommonTree ID12 = null; CommonTree PROCCALL13 = null; CommonTree IF14 = null; CommonTree IFELSE15 = null; CommonTree WHILE16 = null; CommonTree ID17 = null; CommonTree FOR18 = null; Type t = null; Type t1 = null; Type t2 = null; try { // FunChecker.g:232:2: ( ^( ASSN ID t= expr ) | ^( PROCCALL ID t= expr ) | ^( IF t= expr com ) // | ^( IFELSE t= expr com com ) | ^( WHILE t= expr com ) | ^( FOR ID t1= expr t2= expr com ) // | ^( SEQ ( com )* ) ) int alt9 = 7; switch (input.LA(1)) { case ASSN: { alt9 = 1; } break; case PROCCALL: { alt9 = 2; } break; case IF: { alt9 = 3; } break; case IFELSE: { alt9 = 4; } break; case WHILE: { alt9 = 5; } break; case FOR: { alt9 = 6; } break; case SEQ: { alt9 = 7; } break; default: NoViableAltException nvae = new NoViableAltException("", 9, 0, input); throw nvae; } switch (alt9) { case 1: // FunChecker.g:232:4: ^( ASSN ID t= expr ) { ASSN11 = (CommonTree) match(input, ASSN, FOLLOW_ASSN_in_com331); match(input, Token.DOWN, null); ID10 = (CommonTree) match(input, ID, FOLLOW_ID_in_com333); pushFollow(FOLLOW_expr_in_com337); t = expr(); state._fsp--; match(input, Token.UP, null); Type tvar = retrieve((ID10 != null ? ID10.getText() : null), ASSN11); checkType(tvar, t, ASSN11); } break; case 2: // FunChecker.g:237:4: ^( PROCCALL ID t= expr ) { PROCCALL13 = (CommonTree) match(input, PROCCALL, FOLLOW_PROCCALL_in_com350); match(input, Token.DOWN, null); ID12 = (CommonTree) match(input, ID, FOLLOW_ID_in_com352); pushFollow(FOLLOW_expr_in_com356); t = expr(); state._fsp--; match(input, Token.UP, null); Type tres = checkCall((ID12 != null ? ID12.getText() : null), t, PROCCALL13); if (!tres.equiv(Type.VOID)) reportError("procedure should be void", PROCCALL13); } break; case 3: // FunChecker.g:245:4: ^( IF t= expr com ) { IF14 = (CommonTree) match(input, IF, FOLLOW_IF_in_com369); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_com373); t = expr(); state._fsp--; pushFollow(FOLLOW_com_in_com375); com(); state._fsp--; match(input, Token.UP, null); checkType(Type.BOOL, t, IF14); } break; case 4: // FunChecker.g:248:4: ^( IFELSE t= expr com com ) { IFELSE15 = (CommonTree) match(input, IFELSE, FOLLOW_IFELSE_in_com388); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_com392); t = expr(); state._fsp--; pushFollow(FOLLOW_com_in_com394); com(); state._fsp--; pushFollow(FOLLOW_com_in_com396); com(); state._fsp--; match(input, Token.UP, null); checkType(Type.BOOL, t, IFELSE15); } break; case 5: // FunChecker.g:251:4: ^( WHILE t= expr com ) { WHILE16 = (CommonTree) match(input, WHILE, FOLLOW_WHILE_in_com409); match(input, Token.DOWN, null); pushFollow(FOLLOW_expr_in_com413); t = expr(); state._fsp--; pushFollow(FOLLOW_com_in_com415); com(); state._fsp--; match(input, Token.UP, null); checkType(Type.BOOL, t, WHILE16); } break; case 6: // FunChecker.g:254:5: ^( FOR ID t1= expr t2= expr com ) { FOR18 = (CommonTree) match(input, FOR, FOLLOW_FOR_in_com429); match(input, Token.DOWN, null); ID17 = (CommonTree) match(input, ID, FOLLOW_ID_in_com431); pushFollow(FOLLOW_expr_in_com435); t1 = expr(); state._fsp--; pushFollow(FOLLOW_expr_in_com439); t2 = expr(); state._fsp--; pushFollow(FOLLOW_com_in_com441); com(); state._fsp--; match(input, Token.UP, null); Type ident = retrieve((ID17 != null ? ID17.getText() : null), FOR18); checkType(Type.INT, ident, FOR18); checkType(Type.INT, t1, FOR18); checkType(Type.INT, t2, FOR18); } break; case 7: // FunChecker.g:262:4: ^( SEQ ( com )* ) { match(input, SEQ, FOLLOW_SEQ_in_com454); if (input.LA(1) == Token.DOWN) { match(input, Token.DOWN, null); // FunChecker.g:262:10: ( com )* loop8: do { int alt8 = 2; int LA8_0 = input.LA(1); if ((LA8_0 == ASSN || LA8_0 == FOR || (LA8_0 >= IF && LA8_0 <= IFELSE) || LA8_0 == PROCCALL || LA8_0 == SEQ || LA8_0 == WHILE)) { alt8 = 1; } switch (alt8) { case 1: // FunChecker.g:262:10: com { pushFollow(FOLLOW_com_in_com456); com(); state._fsp--; } break; default: break loop8; } } while (true); match(input, Token.UP, null); } } break; } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return; }
public boolean evaluate(JSUPTree ast, TokenRewriteStream trs) { if (ast.getType() != JavaScriptParser.CALL) return false; tokenStream = trs; if (!checkMemberChain(ast)) return false; // Remove all argument from the end, since deleteChild updates // indices. Save the argument Trees for use later. int numArgs = callArguments.getChildCount(); JSUPTree[] origArgs = new JSUPTree[numArgs]; // Remember where original arguments begin and end, excluding parens int argsStart = callArguments.getTokenStartIndex() + 1; int argsStop = callArguments.getTokenStopIndex(); writePointer = argsStart; // Assumes insertion from left to right. // Disregard the parentheses since those are given. for (int i = numArgs - 1; i >= 0; i--) { origArgs[i] = removeArgument(i); } for (int j = argsStart; j < argsStop; j++) { tokenStream.delete(j); } // Replace arguments according to the argument_map. int insertAt = argsStart; for (int k = toPlaceholders.size() - 1; k >= 0; k--) { CommonTree toph = toPlaceholders.get(k); int type = toph.getType(); if (type == JSUPPatchParser.Wild) { System.err.println("Wild card specified in \"to\" construct."); continue; } else if (type == JSUPPatchParser.Comment) { addArgument(toph.getText(), JavaScriptParser.Comment); } else if (type == JSUPPatchParser.Placeholder) { boolean found = false; for (int j = 0; j < fromPlaceholders.size(); j++) { CommonTree frph = fromPlaceholders.get(j); if (frph.getText().equals(toph.getText())) { if (origArgs.length > j) { JSUPTree arg = origArgs[j]; addArgument(arg); found = true; } else { System.err.println("Corresponding argument missing."); } break; } } if (!found) { addArgument(" /* new argument */ ", JavaScriptParser.Comment); } } else if (type == JSUPPatchParser.Identifier) { addArgument(toph.getText(), JavaScriptParser.Identifier); } else if (type == JSUPPatchParser.String) { addArgument(toph.getText(), JavaScriptParser.StringLiteral); } } return true; }
// $ANTLR start "proc_decl" // FunChecker.g:169:1: proc_decl : ( ^( PROC ID t= formal ( var_decl )* com ) | ^( FUNC t1= type // ID t2= formal ( var_decl )* com t3= expr ) ); public final void proc_decl() throws RecognitionException { CommonTree ID2 = null; CommonTree PROC3 = null; CommonTree ID4 = null; CommonTree FUNC5 = null; Type t = null; Type t1 = null; Type t2 = null; Type t3 = null; try { // FunChecker.g:170:2: ( ^( PROC ID t= formal ( var_decl )* com ) | ^( FUNC t1= type ID t2= // formal ( var_decl )* com t3= expr ) ) int alt5 = 2; int LA5_0 = input.LA(1); if ((LA5_0 == PROC)) { alt5 = 1; } else if ((LA5_0 == FUNC)) { alt5 = 2; } else { NoViableAltException nvae = new NoViableAltException("", 5, 0, input); throw nvae; } switch (alt5) { case 1: // FunChecker.g:170:4: ^( PROC ID t= formal ( var_decl )* com ) { PROC3 = (CommonTree) match(input, PROC, FOLLOW_PROC_in_proc_decl102); match(input, Token.DOWN, null); ID2 = (CommonTree) match(input, ID, FOLLOW_ID_in_proc_decl108); typeTable.enterLocalScope(); pushFollow(FOLLOW_formal_in_proc_decl122); t = formal(); state._fsp--; Type proctype = new Type.Mapping(t, Type.VOID); define((ID2 != null ? ID2.getText() : null), proctype, PROC3); // ... to enable recursion // FunChecker.g:180:5: ( var_decl )* loop3: do { int alt3 = 2; int LA3_0 = input.LA(1); if ((LA3_0 == VAR)) { alt3 = 1; } switch (alt3) { case 1: // FunChecker.g:180:5: var_decl { pushFollow(FOLLOW_var_decl_in_proc_decl134); var_decl(); state._fsp--; } break; default: break loop3; } } while (true); pushFollow(FOLLOW_com_in_proc_decl141); com(); state._fsp--; match(input, Token.UP, null); typeTable.exitLocalScope(); // Enter the function in the local // scope, to enable it to be recursive: define((ID2 != null ? ID2.getText() : null), proctype, PROC3); } break; case 2: // FunChecker.g:187:4: ^( FUNC t1= type ID t2= formal ( var_decl )* com t3= expr ) { FUNC5 = (CommonTree) match(input, FUNC, FOLLOW_FUNC_in_proc_decl154); match(input, Token.DOWN, null); pushFollow(FOLLOW_type_in_proc_decl162); t1 = type(); state._fsp--; ID4 = (CommonTree) match(input, ID, FOLLOW_ID_in_proc_decl168); typeTable.enterLocalScope(); pushFollow(FOLLOW_formal_in_proc_decl182); t2 = formal(); state._fsp--; Type functype = new Type.Mapping(t2, t1); define((ID4 != null ? ID4.getText() : null), functype, FUNC5); // ... to enable recursion // FunChecker.g:198:5: ( var_decl )* loop4: do { int alt4 = 2; int LA4_0 = input.LA(1); if ((LA4_0 == VAR)) { alt4 = 1; } switch (alt4) { case 1: // FunChecker.g:198:5: var_decl { pushFollow(FOLLOW_var_decl_in_proc_decl194); var_decl(); state._fsp--; } break; default: break loop4; } } while (true); pushFollow(FOLLOW_com_in_proc_decl201); com(); state._fsp--; pushFollow(FOLLOW_expr_in_proc_decl209); t3 = expr(); state._fsp--; match(input, Token.UP, null); typeTable.exitLocalScope(); define((ID4 != null ? ID4.getText() : null), functype, FUNC5); checkType(t1, t3, FUNC5); } break; } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { // do for sure before leaving } return; }
// $ANTLR start "boolean_expr" // D:\\eclipse\\workspace\\InformationRetrieval\\src\\query\\QueryExecuter.g:27:1: boolean_expr // returns [List<Integer> result] : ( ^( AND a= boolean_expr b= boolean_expr ) | ^( OR a= // boolean_expr b= boolean_expr ) | ^( NOT a= boolean_expr ) | WORD ); public final List<Integer> boolean_expr() throws RecognitionException { List<Integer> result = null; CommonTree WORD1 = null; List<Integer> a = null; List<Integer> b = null; try { // D:\\eclipse\\workspace\\InformationRetrieval\\src\\query\\QueryExecuter.g:28:9: ( ^( AND a= // boolean_expr b= boolean_expr ) | ^( OR a= boolean_expr b= boolean_expr ) | ^( NOT a= // boolean_expr ) | WORD ) int alt2 = 4; switch (input.LA(1)) { case AND: { alt2 = 1; } break; case OR: { alt2 = 2; } break; case NOT: { alt2 = 3; } break; case WORD: { alt2 = 4; } break; default: NoViableAltException nvae = new NoViableAltException("", 2, 0, input); throw nvae; } switch (alt2) { case 1: // D:\\eclipse\\workspace\\InformationRetrieval\\src\\query\\QueryExecuter.g:28:11: ^( AND // a= boolean_expr b= boolean_expr ) { match(input, AND, FOLLOW_AND_in_boolean_expr92); match(input, Token.DOWN, null); pushFollow(FOLLOW_boolean_expr_in_boolean_expr96); a = boolean_expr(); state._fsp--; pushFollow(FOLLOW_boolean_expr_in_boolean_expr100); b = boolean_expr(); state._fsp--; match(input, Token.UP, null); result = TermPosting.andLists(a, b); } break; case 2: // D:\\eclipse\\workspace\\InformationRetrieval\\src\\query\\QueryExecuter.g:29:4: ^( OR // a= boolean_expr b= boolean_expr ) { match(input, OR, FOLLOW_OR_in_boolean_expr126); match(input, Token.DOWN, null); pushFollow(FOLLOW_boolean_expr_in_boolean_expr130); a = boolean_expr(); state._fsp--; pushFollow(FOLLOW_boolean_expr_in_boolean_expr134); b = boolean_expr(); state._fsp--; match(input, Token.UP, null); result = TermPosting.orLists(a, b); } break; case 3: // D:\\eclipse\\workspace\\InformationRetrieval\\src\\query\\QueryExecuter.g:30:4: ^( NOT // a= boolean_expr ) { match(input, NOT, FOLLOW_NOT_in_boolean_expr143); match(input, Token.DOWN, null); pushFollow(FOLLOW_boolean_expr_in_boolean_expr147); a = boolean_expr(); state._fsp--; match(input, Token.UP, null); result = TermPosting.notList(a); } break; case 4: // D:\\eclipse\\workspace\\InformationRetrieval\\src\\query\\QueryExecuter.g:31:4: WORD { WORD1 = (CommonTree) match(input, WORD, FOLLOW_WORD_in_boolean_expr157); result = index.getTermPostingList((WORD1 != null ? WORD1.getText() : null)); } break; } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { } return result; }
// $ANTLR start "member" // DefRef.g:118:1: member returns [Type type] : ( ^( '.' m= member ID ) | ID ); public final Type member() throws RecognitionException { Type type = null; CommonTree ID7 = null; CommonTree ID8 = null; Type m = null; try { // DefRef.g:119:5: ( ^( '.' m= member ID ) | ID ) int alt6 = 2; int LA6_0 = input.LA(1); if ((LA6_0 == 30)) { alt6 = 1; } else if ((LA6_0 == ID)) { alt6 = 2; } else { if (state.backtracking > 0) { state.failed = true; return type; } NoViableAltException nvae = new NoViableAltException("", 6, 0, input); throw nvae; } switch (alt6) { case 1: // DefRef.g:119:7: ^( '.' m= member ID ) { match(input, 30, FOLLOW_30_in_member527); if (state.failed) return type; match(input, Token.DOWN, null); if (state.failed) return type; pushFollow(FOLLOW_member_in_member531); m = member(); state._fsp--; if (state.failed) return type; ID7 = (CommonTree) match(input, ID, FOLLOW_ID_in_member533); if (state.failed) return type; match(input, Token.UP, null); if (state.failed) return type; if (state.backtracking == 1) { StructSymbol scope = (StructSymbol) m; // get scope of expr Symbol s = scope.resolveMember((ID7 != null ? ID7.getText() : null)); // resolve ID in scope System.out.println( "line " + ID7.getLine() + ": ref " + m.getName() + "." + (ID7 != null ? ID7.getText() : null) + "=" + s); if (s != null) type = s.type; // return ID's type } } break; case 2: // DefRef.g:127:7: ID { ID8 = (CommonTree) match(input, ID, FOLLOW_ID_in_member550); if (state.failed) return type; if (state.backtracking == 1) { Symbol s = currentScope.resolve((ID8 != null ? ID8.getText() : null)); System.out.println( "line " + ID8.getLine() + ": ref " + (ID8 != null ? ID8.getText() : null) + "=" + s); if (s != null) type = s.type; } } break; } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { } return type; }
// $ANTLR start "varDeclaration" // DefRef.g:86:1: varDeclaration : ^( ( FIELD_DECL | VAR_DECL | ARG_DECL ) type ID ( . )? ) ; public final void varDeclaration() throws RecognitionException { CommonTree ID4 = null; DefRef.type_return type5 = null; try { // DefRef.g:87:5: ( ^( ( FIELD_DECL | VAR_DECL | ARG_DECL ) type ID ( . )? ) ) // DefRef.g:87:9: ^( ( FIELD_DECL | VAR_DECL | ARG_DECL ) type ID ( . )? ) { if (input.LA(1) == ARG_DECL || (input.LA(1) >= VAR_DECL && input.LA(1) <= FIELD_DECL)) { input.consume(); state.errorRecovery = false; state.failed = false; } else { if (state.backtracking > 0) { state.failed = true; return; } MismatchedSetException mse = new MismatchedSetException(null, input); throw mse; } match(input, Token.DOWN, null); if (state.failed) return; pushFollow(FOLLOW_type_in_varDeclaration363); type5 = type(); state._fsp--; if (state.failed) return; ID4 = (CommonTree) match(input, ID, FOLLOW_ID_in_varDeclaration365); if (state.failed) return; // DefRef.g:87:50: ( . )? int alt5 = 2; int LA5_0 = input.LA(1); if (((LA5_0 >= METHOD_DECL && LA5_0 <= 30))) { alt5 = 1; } switch (alt5) { case 1: // DefRef.g:87:50: . { matchAny(input); if (state.failed) return; } break; } match(input, Token.UP, null); if (state.failed) return; if (state.backtracking == 1) { System.out.println( "line " + ID4.getLine() + ": def " + (ID4 != null ? ID4.getText() : null)); VariableSymbol vs = new VariableSymbol( (ID4 != null ? ID4.getText() : null), (type5 != null ? type5.tsym : null)); currentScope.define(vs); } } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { } return; }
// $ANTLR start "enterMethod" // DefRef.g:66:1: enterMethod : ^( METHOD_DECL type ID ( . )* ) ; public final void enterMethod() throws RecognitionException { CommonTree ID2 = null; DefRef.type_return type3 = null; try { // DefRef.g:67:5: ( ^( METHOD_DECL type ID ( . )* ) ) // DefRef.g:67:9: ^( METHOD_DECL type ID ( . )* ) { match(input, METHOD_DECL, FOLLOW_METHOD_DECL_in_enterMethod284); if (state.failed) return; match(input, Token.DOWN, null); if (state.failed) return; pushFollow(FOLLOW_type_in_enterMethod286); type3 = type(); state._fsp--; if (state.failed) return; ID2 = (CommonTree) match(input, ID, FOLLOW_ID_in_enterMethod288); if (state.failed) return; // DefRef.g:67:31: ( . )* loop4: do { int alt4 = 2; int LA4_0 = input.LA(1); if (((LA4_0 >= METHOD_DECL && LA4_0 <= 30))) { alt4 = 1; } else if ((LA4_0 == UP)) { alt4 = 2; } switch (alt4) { case 1: // DefRef.g:67:31: . { matchAny(input); if (state.failed) return; } break; default: break loop4; } } while (true); match(input, Token.UP, null); if (state.failed) return; if (state.backtracking == 1) { System.out.println( "line " + ID2.getLine() + ": def method " + (ID2 != null ? ID2.getText() : null)); MethodSymbol ms = new MethodSymbol( (ID2 != null ? ID2.getText() : null), (type3 != null ? type3.tsym : null), currentScope); currentScope.define(ms); // def method in globals currentScope = ms; // set current scope to method scope } } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { } return; }
// $ANTLR start "enterStruct" // DefRef.g:48:1: enterStruct : ^( 'struct' ID ( . )+ ) ; public final void enterStruct() throws RecognitionException { CommonTree ID1 = null; try { // DefRef.g:49:5: ( ^( 'struct' ID ( . )+ ) ) // DefRef.g:49:7: ^( 'struct' ID ( . )+ ) { match(input, 17, FOLLOW_17_in_enterStruct219); if (state.failed) return; match(input, Token.DOWN, null); if (state.failed) return; ID1 = (CommonTree) match(input, ID, FOLLOW_ID_in_enterStruct221); if (state.failed) return; // DefRef.g:49:21: ( . )+ int cnt3 = 0; loop3: do { int alt3 = 2; int LA3_0 = input.LA(1); if (((LA3_0 >= METHOD_DECL && LA3_0 <= 30))) { alt3 = 1; } else if ((LA3_0 == UP)) { alt3 = 2; } switch (alt3) { case 1: // DefRef.g:49:21: . { matchAny(input); if (state.failed) return; } break; default: if (cnt3 >= 1) break loop3; if (state.backtracking > 0) { state.failed = true; return; } EarlyExitException eee = new EarlyExitException(3, input); throw eee; } cnt3++; } while (true); match(input, Token.UP, null); if (state.failed) return; if (state.backtracking == 1) { System.out.println( "line " + ID1.getLine() + ": def struct " + (ID1 != null ? ID1.getText() : null)); StructSymbol ss = new StructSymbol((ID1 != null ? ID1.getText() : null), currentScope); currentScope.define(ss); // def struct in current scope currentScope = ss; // set current scope to struct scope } } } catch (RecognitionException re) { reportError(re); recover(input, re); } finally { } return; }