Example #1
0
 private void reportError(String message, CommonTree ast) {
   // Print an error message relating to the given
   // (sub)AST.
   int line = ast.getLine(), column = ast.getCharPositionInLine();
   System.err.println("line " + line + ":" + column + " " + message);
   errorCount++;
 }
Example #2
0
  // process a statement of the form: describe table <tablename>
  private void executeDescribeTable(CommonTree ast) throws TException {
    if (!CliMain.isConnected()) return;

    // Get table name
    int childCount = ast.getChildCount();
    assert (childCount == 1);

    String tableName = ast.getChild(0).getText();

    if (tableName == null) {
      css_.out.println("Keyspace argument required");
      return;
    }

    // Describe and display
    Map<String, Map<String, String>> columnFamiliesMap;
    try {
      columnFamiliesMap = thriftClient_.describe_keyspace(tableName);
      for (String columnFamilyName : columnFamiliesMap.keySet()) {
        Map<String, String> columnMap = columnFamiliesMap.get(columnFamilyName);
        String desc = columnMap.get("Desc");
        String columnFamilyType = columnMap.get("Type");
        String sort = columnMap.get("CompareWith");
        String flushperiod = columnMap.get("FlushPeriodInMinutes");
        css_.out.println(desc);
        css_.out.println("Column Family Type: " + columnFamilyType);
        css_.out.println("Column Sorted By: " + sort);
        css_.out.println("flush period: " + flushperiod + " minutes");
        css_.out.println("------");
      }
    } catch (NotFoundException e) {
      css_.out.println("Keyspace " + tableName + " could not be found.");
    }
  }
Example #3
0
  private void executeCount(CommonTree ast)
      throws TException, InvalidRequestException, UnavailableException, TimedOutException,
          UnsupportedEncodingException {
    if (!CliMain.isConnected()) return;

    int childCount = ast.getChildCount();
    assert (childCount == 1);

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

    ColumnParent colParent;

    if (columnSpecCnt == 0) {
      colParent = createColumnParent(columnFamily, null);
    } else {
      assert (columnSpecCnt == 1);
      colParent =
          createColumnParent(
              columnFamily, CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8"));
    }

    int count = thriftClient_.get_count(tableName, key, colParent, ConsistencyLevel.ONE);
    css_.out.printf("%d columns\n", count);
  }
  // $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;
  }
Example #5
0
  // $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;
  }
Example #6
0
  // Execute a CLI Statement
  public void executeCLIStmt(String stmt)
      throws TException, NotFoundException, InvalidRequestException, UnavailableException,
          TimedOutException, IllegalAccessException, ClassNotFoundException,
          InstantiationException {
    CommonTree ast = null;

    ast = CliCompiler.compileQuery(stmt);

    try {
      switch (ast.getType()) {
        case CliParser.NODE_EXIT:
          cleanupAndExit();
          break;
        case CliParser.NODE_THRIFT_GET:
          executeGet(ast);
          break;
        case CliParser.NODE_HELP:
          printCmdHelp();
          break;
        case CliParser.NODE_THRIFT_SET:
          executeSet(ast);
          break;
        case CliParser.NODE_THRIFT_DEL:
          executeDelete(ast);
          break;
        case CliParser.NODE_THRIFT_COUNT:
          executeCount(ast);
          break;
        case CliParser.NODE_SHOW_CLUSTER_NAME:
          executeShowProperty(ast, "cluster name");
          break;
        case CliParser.NODE_SHOW_CONFIG_FILE:
          executeShowProperty(ast, "config file");
          break;
        case CliParser.NODE_SHOW_VERSION:
          executeShowProperty(ast, "version");
          break;
        case CliParser.NODE_SHOW_TABLES:
          executeShowTables(ast);
          break;
        case CliParser.NODE_DESCRIBE_TABLE:
          executeDescribeTable(ast);
          break;
        case CliParser.NODE_CONNECT:
          executeConnect(ast);
          break;
        case CliParser.NODE_NO_OP:
          // comment lines come here; they are treated as no ops.
          break;
        default:
          css_.err.println("Invalid Statement (Type: " + ast.getType() + ")");
          break;
      }
    } catch (UnsupportedEncodingException e) {
      throw new RuntimeException("Unable to encode string as UTF-8", e);
    }
  }
Example #7
0
  private void executeDelete(CommonTree ast)
      throws TException, InvalidRequestException, UnavailableException, TimedOutException,
          UnsupportedEncodingException {
    if (!CliMain.isConnected()) return;

    int childCount = ast.getChildCount();
    assert (childCount == 1);

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

    byte[] superColumnName = null;
    byte[] columnName = null;
    boolean isSuper;

    try {
      if (!(getCFMetaData(tableName).containsKey(columnFamily))) {
        css_.out.println("No such column family: " + columnFamily);
        return;
      }

      isSuper =
          getCFMetaData(tableName).get(columnFamily).get("Type").equals("Super") ? true : false;
    } catch (NotFoundException nfe) {
      css_.out.printf("No such keyspace: %s\n", tableName);
      return;
    }

    if ((columnSpecCnt < 0) || (columnSpecCnt > 2)) {
      css_.out.println("Invalid row, super column, or column specification.");
      return;
    }

    if (columnSpecCnt == 1) {
      // table.cf['key']['column']
      if (isSuper) superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      else columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
    } else if (columnSpecCnt == 2) {
      // table.cf['key']['column']['column']
      superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
    }

    thriftClient_.remove(
        tableName,
        key,
        createColumnPath(columnFamily, superColumnName, columnName),
        timestampMicros(),
        ConsistencyLevel.ONE);
    css_.out.println(String.format("%s removed.", (columnSpecCnt == 0) ? "row" : "column"));
  }
  public WhileStatement(CommonTree MyTree, Model MyModel) {
    setLine(MyTree.getLine());
    this.MyModel = MyModel;

    Comparison = ExpressionFactory.getExpression((CommonTree) MyTree.getChild(0), MyModel);
    if (MyTree.getChildCount() > 1) {
      for (int i = 1; i < MyTree.getChildCount(); i++)
        Statements.add(StatementFactory.getStatement((CommonTree) MyTree.getChild(i), MyModel));
    }
  }
Example #9
0
  // Execute SET statement
  private void executeSet(CommonTree ast)
      throws TException, InvalidRequestException, UnavailableException, TimedOutException,
          UnsupportedEncodingException {
    if (!CliMain.isConnected()) return;

    assert (ast.getChildCount() == 2) : "serious parsing error (this is a bug).";

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);
    String value = CliUtils.unescapeSQLString(ast.getChild(1).getText());

    byte[] superColumnName = null;
    byte[] columnName = null;

    // table.cf['key']
    if (columnSpecCnt == 0) {
      css_.err.println("No column name specified, (type 'help' or '?' for help on syntax).");
      return;
    }
    // table.cf['key']['column'] = 'value'
    else if (columnSpecCnt == 1) {
      // get the column name
      columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
    }
    // table.cf['key']['super_column']['column'] = 'value'
    else {
      assert (columnSpecCnt == 2) : "serious parsing error (this is a bug).";

      // get the super column and column names
      superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
    }

    // do the insert
    thriftClient_.insert(
        tableName,
        key,
        createColumnPath(columnFamily, superColumnName, columnName),
        value.getBytes(),
        timestampMicros(),
        ConsistencyLevel.ONE);

    css_.out.println("Value inserted.");
  }
 // xxx: Wrong! Should use TreeGrammer and not to populate customizer with custom nodes
 // Should be rewritten but I have no time for this
 public List<JavaVMOption<?>> parse() {
   Set<JavaVMOption<?>> result = new HashSet<JavaVMOption<?>>();
   try {
     vmOptions_return options_return = vmOptions();
     CommonTree root = options_return.tree;
     if (root instanceof JavaVMOption<?>) {
       result.add((JavaVMOption<?>) root);
     } else if (root != null) {
       result.addAll(root.getChildren());
     }
   } catch (RecognitionException e) {
     e.printStackTrace();
   }
   result.addAll(getAllOptions());
   return new LinkedList<JavaVMOption<?>>(result);
 }
Example #11
0
 private String getLocatorName(CommonTree tree) {
   String text = tree.getText();
   if (text.endsWith("://")) {
     return text.substring(0, text.length() - 3);
   } else {
     return null;
   }
 }
Example #12
0
 private Number getNumber(CommonTree tree) {
   String text = tree.getText();
   if (text.contains(".")) {
     return Double.parseDouble(text);
   } else {
     return Integer.parseInt(text);
   }
 }
Example #13
0
  // process a statement of the form: connect hostname/port
  private void executeConnect(CommonTree ast) {
    int portNumber = Integer.parseInt(ast.getChild(1).getText());
    Tree idList = ast.getChild(0);

    StringBuilder hostName = new StringBuilder();
    int idCount = idList.getChildCount();
    for (int idx = 0; idx < idCount; idx++) {
      hostName.append(idList.getChild(idx).getText());
    }

    // disconnect current connection, if any.
    // This is a no-op, if you aren't currently connected.
    CliMain.disconnect();

    // now, connect to the newly specified host name and port
    css_.hostName = hostName.toString();
    css_.thriftPort = portNumber;
    CliMain.connect(css_.hostName, css_.thriftPort);
  }
 public static Expression getExpression(CommonTree Child, Model MyModel) {
   Expression returnMe = null;
   int Type = Child.getType();
   if (Type == Constants.NOT
       || Type == Constants.CAST_EXPRESSION
       || Type == Constants.MINUS
       || Type == Constants.PLUS
       || Type == Constants.POWER_EXPRESSION
       || Type == Constants.TIMES
       || Type == Constants.MOD
       || Type == Constants.DIV
       || Type == Constants.AND
       || Type == Constants.OR
       || Type == Constants.NOT_EQUALS
       || Type == Constants.GTE
       || Type == Constants.LT
       || Type == Constants.GT
       || Type == Constants.EQUALS
       || Type == Constants.LTE
       || Type == Constants.INCREMENT
       || Type == Constants.DECREMENT) {
     if (Type != Constants.CAST_EXPRESSION)
       returnMe = (Expression) (new ArithmeticExpression(Child, MyModel, Type));
     else { // We must be attempting to cast move one step farther into tree.
       if (Child.getChildCount() > 0) {
         Type = ((CommonTree) Child.getChild(0)).getType();
         returnMe = (Expression) (new ArithmeticExpression(Child, MyModel, Type));
       }
     }
   } else if (Type == Constants.DOUBLE) {
     returnMe = new TypeFloat(new Float(Child.toString()));
   } else if (Type == Constants.STRING_LITERAL) {
     returnMe = new TypeString(Child.toString().substring(1, Child.toString().length() - 1));
   } else if (Type == Constants.INTEGER_LITERAL) {
     returnMe = new TypeInteger(new Integer(Child.toString()));
   } else if (Type == Constants.BOOLEAN_LITERAL) {
     returnMe = new TypeBoolean(new Boolean(Child.toString()));
   } else if (Type == Constants.IDENTIFIER) {
     returnMe = new TypeIdentifier(Child.toString());
   } else if (Type == Constants.ARRAY_IDENTIFIER) {
     returnMe = new TypeIdentifier(Child, MyModel);
   } else if (Type == Constants.ARRAY_DECLARE) {
     returnMe = new ArrayDeclareExpression(Child, MyModel);
   } else if (Type == Constants.PROCEDURE) {
     returnMe = new ProcedureExpression(Child, MyModel);
   }
   return (returnMe);
 }
Example #15
0
  // $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;
  }
Example #16
0
  // $ANTLR start "assignment"
  // DefRef.g:107:1: assignment : ^(eq= '=' member . ) ;
  public final void assignment() throws RecognitionException {
    CommonTree eq = null;
    Type member6 = null;

    try {
      // DefRef.g:108:5: ( ^(eq= '=' member . ) )
      // DefRef.g:108:9: ^(eq= '=' member . )
      {
        eq = (CommonTree) match(input, 27, FOLLOW_27_in_assignment473);
        if (state.failed) return;

        match(input, Token.DOWN, null);
        if (state.failed) return;
        pushFollow(FOLLOW_member_in_assignment475);
        member6 = member();

        state._fsp--;
        if (state.failed) return;
        matchAny(input);
        if (state.failed) return;

        match(input, Token.UP, null);
        if (state.failed) return;
        if (state.backtracking == 1) {

          System.out.println("line " + eq.getLine() + ": assign to type " + member6.getName());
        }
      }

    } catch (RecognitionException re) {
      reportError(re);
      recover(input, re);
    } finally {
    }
    return;
  }
Example #17
0
  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;
  }
Example #18
0
  // $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;
  }
Example #19
0
 private String getString(CommonTree tree) {
   return tree.getText().substring(1, tree.getText().length() - 1);
 }
Example #20
0
  // $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;
  }
Example #21
0
  // $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;
  }
Example #22
0
  // $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;
  }
Example #23
0
  // $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;
  }
Example #24
0
  // $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;
  }
Example #25
0
  // $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;
  }
Example #26
0
  // Execute GET statement
  private void executeGet(CommonTree ast)
      throws TException, NotFoundException, InvalidRequestException, UnavailableException,
          TimedOutException, UnsupportedEncodingException, IllegalAccessException,
          InstantiationException, ClassNotFoundException {

    if (!CliMain.isConnected()) return;

    // This will never happen unless the grammar is broken
    assert (ast.getChildCount() == 1) : "serious parsing error (this is a bug).";

    CommonTree columnFamilySpec = (CommonTree) ast.getChild(0);
    if (!(columnFamilySpec.getType() == CliParser.NODE_COLUMN_ACCESS)) return;

    String tableName = CliCompiler.getTableName(columnFamilySpec);
    String key = CliCompiler.getKey(columnFamilySpec);
    String columnFamily = CliCompiler.getColumnFamily(columnFamilySpec);
    int columnSpecCnt = CliCompiler.numColumnSpecifiers(columnFamilySpec);

    if (!(getCFMetaData(tableName).containsKey(columnFamily))) {
      css_.out.println("No such column family: " + columnFamily);
      return;
    }

    boolean isSuper =
        getCFMetaData(tableName).get(columnFamily).get("Type").equals("Super") ? true : false;

    byte[] superColumnName = null;
    byte[] columnName = null;

    // table.cf['key'] -- row slice
    if (columnSpecCnt == 0) {
      doSlice(tableName, key, columnFamily, superColumnName);
      return;
    }

    // table.cf['key']['column'] -- slice of a super, or get of a standard
    if (columnSpecCnt == 1) {
      if (isSuper) {
        superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
        doSlice(tableName, key, columnFamily, superColumnName);
        return;
      } else {
        columnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      }
    }
    // table.cf['key']['column']['column'] -- get of a sub-column
    else if (columnSpecCnt == 2) {
      superColumnName = CliCompiler.getColumn(columnFamilySpec, 0).getBytes("UTF-8");
      columnName = CliCompiler.getColumn(columnFamilySpec, 1).getBytes("UTF-8");
    }
    // The parser groks an arbitrary number of these so it is possible to get here.
    else {
      css_.out.println("Invalid row, super column, or column specification.");
      return;
    }

    // Perform a get(), print out the results.
    ColumnPath path = createColumnPath(columnFamily, superColumnName, columnName);
    Column column = thriftClient_.get(tableName, key, path, ConsistencyLevel.ONE).column;
    css_.out.printf(
        "=> (column=%s, value=%s, timestamp=%d)\n",
        formatColumnName(tableName, columnFamily, column),
        new String(column.value, "UTF-8"),
        column.timestamp);
  }
  // $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;
  }
Example #28
0
  // $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;
  }