Package com.google.minijoe.compiler.ast

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


    if (expression instanceof Identifier && nextToken == Token.OPERATOR_COLON) {
      readToken(Token.OPERATOR_COLON);
      return new LabelledStatement((Identifier) expression, parseStatement());
    } else {
      readTokenSemicolon();
      return new ExpressionStatement(expression);
    }
  }
View Full Code Here


  }

  public Statement visit(FunctionDeclaration functionDeclaration) throws CompilerException {
    functionDeclaration = (FunctionDeclaration) super.visit(functionDeclaration);

    functionVector.addElement(new ExpressionStatement(functionDeclaration.literal));

    return new EmptyStatement();
  }
View Full Code Here

    for (int i = 0; i < variableStatement.declarations.length; i++) {
      Expression expression = visitExpression(variableStatement.declarations[i]);

      if (expression != null) {
        Statement statement = new ExpressionStatement(expression);
        statement.setLineNumber(variableStatement.getLineNumber());
        statements.addElement(statement);
      }
    }

    if (statements.size() == 0) {
View Full Code Here

  public void testIfStatement() throws CompilerException {
    assertParserOutput(
        new IfStatement(
            new BooleanLiteral(true),
            new ExpressionStatement(
                new Identifier("foo")
            ),
            null
        ),
        "if (true) foo;"
    );
    assertParserOutput(
        new IfStatement(
            new BooleanLiteral(true),
            new ExpressionStatement(
                new Identifier("foo")
            ),
            new ExpressionStatement(
                new Identifier("bar")
            )
        ),
        "if (true) foo; else bar;"
    );
    assertParserOutput(
        new IfStatement(
            new BooleanLiteral(true),
            new IfStatement(
                new BooleanLiteral(true),
                new ExpressionStatement(
                    new Identifier("foo")
                ),
                new ExpressionStatement(
                    new Identifier("bar")
                )
            ),
            null
        ),
        "if (true) if (true) foo; else bar;"
    );
    assertParserOutput(
        new IfStatement(
            new BooleanLiteral(true),
            new IfStatement(
                new BooleanLiteral(true),
                new ExpressionStatement(
                    new Identifier("foo")
                ),
                new ExpressionStatement(
                    new Identifier("bar")
                )
            ),
            new ExpressionStatement(
                new Identifier("baz")
            )
        ),
        "if (true) if (true) foo; else bar; else baz;"
    );
View Full Code Here

  public void testTryCatchStatement() throws CompilerException {
    assertParserOutput(
        new TryStatement(
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("something")
                    )
                }
            ),
            new Identifier("foo"),
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                }
            ),
            null
        ),
        "try {something;} catch (foo) {bar;}"
    );
    assertParserOutput(
        new TryStatement(
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("something")
                    )
                }
            ),
            null,
            null,
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("baz")
                    )
                }
            )
        ),
        "try {something;} finally {baz;}"
    );
    assertParserOutput(
        new TryStatement(
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("something")
                    )
                }
            ),
            new Identifier("foo"),
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                }
            ),
            new BlockStatement(
                new Statement[] {
                    new ExpressionStatement(
                        new Identifier("baz")
                    )
                }
            )
        ),
View Full Code Here

    super(name);
  }

  public void testEqualsExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_EQUALEQUAL
            )
        ),
        "foo == bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_EQUALEQUAL
                ),
                new Identifier("baz"),
                Token.OPERATOR_EQUALEQUAL
            )
        ),
        "foo == bar == baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
View Full Code Here

    );
  }

  public void testNotEqualsExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_NOTEQUAL
            )
        ),
        "foo != bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_NOTEQUAL
                ),
                new Identifier("baz"),
                Token.OPERATOR_NOTEQUAL
            )
        ),
        "foo != bar != baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
View Full Code Here

    );
  }

  public void testStrictEqualsExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_EQUALEQUALEQUAL
            )
        ),
        "foo === bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_EQUALEQUALEQUAL
                ),
                new Identifier("baz"),
                Token.OPERATOR_EQUALEQUALEQUAL
            )
        ),
        "foo === bar === baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
View Full Code Here

    );
  }

  public void testStrictNotEqualsExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_NOTEQUALEQUAL
            )
        ),
        "foo !== bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_NOTEQUALEQUAL
                ),
                new Identifier("baz"),
                Token.OPERATOR_NOTEQUALEQUAL
            )
        ),
        "foo !== bar !== baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
View Full Code Here

    super(name);
  }

  public void testBitwiseAndExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_BITWISEAND
            )
        ),
        "foo & bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_BITWISEAND
                ),
                new Identifier("baz"),
                Token.OPERATOR_BITWISEAND
            )
        ),
        "foo & bar & baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
View Full Code Here

TOP

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

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.