Esempio n. 1
0
  // literal := INTEGER | FLOAT | TRUE | FALSE .
  public ast.Expression literal() throws IOException {
    ast.Expression expr = null;

    if (currentToken.kind.name().equals("INTEGER")) {
      expr = Command.newLiteral(expectRetrieve(Token.Kind.INTEGER));
    } else if (currentToken.kind.name().equals("FLOAT")) {
      expr = Command.newLiteral(expectRetrieve(Token.Kind.FLOAT));
    } else if (currentToken.kind.name().equals("TRUE")) {
      expr = Command.newLiteral(expectRetrieve(Token.Kind.TRUE));
    } else if (currentToken.kind.name().equals("FALSE")) {
      expr = Command.newLiteral(expectRetrieve(Token.Kind.FALSE));
    }

    return expr;
  }
Esempio n. 2
0
 /*
 * expression3 := "not" expression3
      | "(" expression0 ")"
      | designator
      | call-expression
      | literal .
 */
 private ast.Expression expression3() throws IOException {
   // TODO Auto-generated method stub
   ast.Expression expr3 = null;
   if (currentToken.kind.name().equals("NOT")) {
     Token op = expectRetrieve(Token.Kind.NOT);
     ast.Expression right = expression3();
     expr3 = Command.newExpression(right, op, null);
   } else if (currentToken.kind.name().equals("OPEN_PAREN")) {
     accept(Token.Kind.OPEN_PAREN);
     expr3 = expression0();
     expect(Token.Kind.CLOSE_PAREN);
   } else if (currentToken.kind.name().equals("IDENTIFIER")) {
     int lineNum = currentToken.lineNumber();
     int charPos = currentToken.charPosition();
     ast.Expression deref = designator();
     expr3 = new ast.Dereference(lineNum, charPos, deref);
   } else if (currentToken.kind.name().equals("CALL")) {
     expr3 = call_expression();
   } else if (currentToken.kind.name().equals("INTEGER")
       || currentToken.kind.name().equals("FLOAT")
       || currentToken.kind.name().equals("TRUE")
       || currentToken.kind.name().equals("FALSE")) {
     expr3 = literal();
   }
   return expr3;
 }
Esempio n. 3
0
  // expression2 := expression3 { op2 expression3 } .
  private ast.Expression expression2() throws IOException {
    // TODO Auto-generated method stub
    ast.Expression expr2 = null;
    expr2 = expression3();
    while (NonTerminal.OP2.firstSet.contains(currentToken.kind)) {
      ast.Expression left = expr2;
      Token op2 = op2();
      ast.Expression right = expression3();
      expr2 = Command.newExpression(left, op2, right);
    }

    return expr2;
  }
Esempio n. 4
0
  // expression0 := expression1 [ op0 expression1 ] .
  private ast.Expression expression0() throws IOException {
    // TODO Auto-generated method stub
    ast.Expression expr = null;
    expr = expression1();
    if (!currentToken.is(Token.Kind.SEMICOLON)) {
      if (NonTerminal.OP0.firstSet.contains(currentToken.kind)) {
        ast.Expression left = expr;
        Token op0 = op0();
        ast.Expression right = expression1();
        expr = Command.newExpression(left, op0, right);
      }
    }

    return expr;
  }
Esempio n. 5
0
 // type := IDENTIFIER .
 private ast.Expression type() throws IOException {
   // TODO Auto-generated method stub
   // expects IDENTIFIER
   return Command.newLiteral(expectRetrieve(Token.Kind.IDENTIFIER));
 }