Package com.google.minijoe.compiler.ast

Examples of com.google.minijoe.compiler.ast.Expression


      }
    }
  }

  private Expression parseAdditionExpression() throws CompilerException {
    Expression left = parseMultiplyExpression();
    Expression right;

    // addition expressions are left associative
    while (true) {
      if (nextToken == Token.OPERATOR_PLUS) {
        readToken(Token.OPERATOR_PLUS);
View Full Code Here


      }
    }
  }

  private Expression parseMultiplyExpression() throws CompilerException {
    Expression left = parseUnaryExpression();
    Expression right;

    // multiplicative expressions are left associative
    while (true) {
      if (nextToken == Token.OPERATOR_MULTIPLY) {
        readToken(Token.OPERATOR_MULTIPLY);
View Full Code Here

  }

  private Expression parsePostfixExpression() throws CompilerException {
    // TODO this can be merged with parseUnary().

    Expression expression = parseMemberExpression(false);

    // postfix expressions aren't associative
    if (nextToken == Token.OPERATOR_PLUSPLUS) {
      readToken(Token.OPERATOR_PLUSPLUS);
      return new IncrementExpression(expression, 1, true);
View Full Code Here

   *
   * @param newFlag if we're currently parsing a 'new' expression
   * @return an expression
   */
  private Expression parseMemberExpression(boolean newFlag) throws CompilerException {
    Expression expression;

    // new expressions are right associative
    if (nextToken == Token.KEYWORD_NEW) {
      Expression name;

      readToken(Token.KEYWORD_NEW);
      name = parseMemberExpression(true);

      if (nextToken == Token.OPERATOR_OPENPAREN) {
        Expression[] arguments = parseArgumentList();
        expression = new NewExpression(name, arguments);
      } else {
        expression = new NewExpression(name, null);
      }

    } else if (nextToken == Token.KEYWORD_FUNCTION) {
      expression = parseFunctionLiteral(false);

    } else {
      expression = parsePrimaryExpression();
    }

    // call expressions are left associative
    while (true) {
      if (!newFlag && nextToken == Token.OPERATOR_OPENPAREN) {
        Expression[] arguments = parseArgumentList();
        expression = new CallExpression(expression, arguments);
      } else if (nextToken == Token.OPERATOR_OPENSQUARE) {
        readToken(Token.OPERATOR_OPENSQUARE);
        Expression property = parseExpression(true);
        readToken(Token.OPERATOR_CLOSESQUARE);
        expression = new PropertyExpression(expression, property);
      } else if (nextToken == Token.OPERATOR_DOT) {
        // transform x.bar to x["bar"]
        readToken(Token.OPERATOR_DOT);
View Full Code Here

      readToken(Token.KEYWORD_FALSE);
      return new BooleanLiteral(false);

    } else if (nextToken == Token.OPERATOR_OPENPAREN) {
      readToken(Token.OPERATOR_OPENPAREN);
      Expression expression = parseExpression(true);
      readToken(Token.OPERATOR_CLOSEPAREN);
      return expression;

    } else if (nextToken == Token.OPERATOR_OPENBRACE) {
      return parseObjectLiteral();
View Full Code Here

    return new ObjectLiteral(propertyArray);
  }

  private ObjectLiteralProperty parseObjectLiteralProperty() throws CompilerException {
    Expression propertyName = null;
    Expression propertyValue = null;

    if (nextToken.isIdentifier()) {
      propertyName = new StringLiteral(parseIdentifier().string);
    } else if (nextToken.isStringLiteral()) {
      propertyName = parseStringLiteral();
View Full Code Here

  //
  // expression
  //

  public Expression visit(Identifier identifier) throws CompilerException {
    Expression pa = pendingAssignment;
    pendingAssignment = null;

    Identifier localVariable = (Identifier) localVariableTable.get(identifier);

    if (localVariable != null) {
View Full Code Here

    return expression;
  }

  public Expression visit(AssignmentExpression expression) throws CompilerException {

    Expression savePendingAssignment = pendingAssignment;
    pendingAssignment = expression;
    expression.leftExpression.visitExpression(this);
    if (pendingAssignment != null) {
      throw new RuntimeException("Pending assignment was not resolved");
    }
View Full Code Here

    pendingAssignment = savePendingAssignment;
    return expression;
  }

  public Expression visit(AssignmentOperatorExpression expression) throws CompilerException {
    Expression savePendingAssignment = pendingAssignment;
    pendingAssignment = expression;
    expression.leftExpression.visitExpression(this);
    if (pendingAssignment != null) {
      throw new RuntimeException("Pending assignment was not resolved");
    }
View Full Code Here

    setLabel(expression, "endif");
    return expression;
  }

  public Expression visit(DeleteExpression expression) throws CompilerException {
    Expression savePendingAssignment = pendingAssignment;
    pendingAssignment = expression;
    expression.subExpression.visitExpression(this);
    if (pendingAssignment != null) {
      throw new RuntimeException("Pending assignment was not resolved");
    }
View Full Code Here

TOP

Related Classes of com.google.minijoe.compiler.ast.Expression

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.