Package com.google.minijoe.compiler.ast

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


  public void testBitwiseShiftLeftExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_SHIFTLEFT
            )
        ),
        "foo << bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_SHIFTLEFT
                ),
                new Identifier("baz"),
                Token.OPERATOR_SHIFTLEFT
            )
        ),
        "foo << bar << baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
                    Token.OPERATOR_PLUS
                ),
                Token.OPERATOR_SHIFTLEFT
            )
View Full Code Here


  public void testBitwiseShiftRightExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_SHIFTRIGHT
            )
        ),
        "foo >> bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_SHIFTRIGHT
                ),
                new Identifier("baz"),
                Token.OPERATOR_SHIFTRIGHT
            )
        ),
        "foo >> bar >> baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
                    Token.OPERATOR_PLUS
                ),
                Token.OPERATOR_SHIFTRIGHT
            )
View Full Code Here

  public void testBitwiseShiftRightUnsignedExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new Identifier("bar"),
                Token.OPERATOR_SHIFTRIGHTUNSIGNED
            )
        ),
        "foo >>> bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new BinaryOperatorExpression(
                    new Identifier("foo"),
                    new Identifier("bar"),
                    Token.OPERATOR_SHIFTRIGHTUNSIGNED
                ),
                new Identifier("baz"),
                Token.OPERATOR_SHIFTRIGHTUNSIGNED
            )
        ),
        "foo >>> bar >>> baz;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new BinaryOperatorExpression(
                new Identifier("foo"),
                new BinaryOperatorExpression(
                    new Identifier("bar"),
                    new NumberLiteral(1.0),
                    Token.OPERATOR_PLUS
                ),
                Token.OPERATOR_SHIFTRIGHTUNSIGNED
            )
View Full Code Here

    assertParserOutput(
        new BlockStatement(
            new Statement[] {
                new ExpressionStatement(
                    new AssignmentExpression(
                        new Identifier("foo"),
                        new NumberLiteral(1.0)
                    )
                )
            }
        ),
        "{foo = 1.0;};"
    );
    assertParserOutput(
        new BlockStatement(
            new Statement[] {
                new ExpressionStatement(
                    new AssignmentExpression(
                        new Identifier("foo"),
                        new NumberLiteral(1.0)
                    )
                ),
                new ExpressionStatement(
                    new AssignmentExpression(
                        new Identifier("bar"),
                        new NumberLiteral(2.0)
                    )
                )
            }
        ),
View Full Code Here

  }

  public void testSwitchStatement() throws CompilerException {
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
            }
        ),
        "switch (something) {}"
    );
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
              new CaseStatement(
                  null,
                  new Statement[] {
                      new ExpressionStatement(
                          new Identifier("foo")
                      )
                  }
              )
            }
        ),
        "switch (something) {default: foo;}"
    );
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
              new CaseStatement(
                  new NumberLiteral(0),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                  }
              )
            }
        ),
        "switch (something) {case 0: bar;}"
    );
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
              new CaseStatement(
                  new NumberLiteral(0),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                  }
              ),
              new CaseStatement(
                  new NumberLiteral(1),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("baz")
                    )
                  }
              )
            }
        ),
        "switch (something) {case 0: bar; case 1: baz;}"
    );
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
              new CaseStatement(
                  null,
                  new Statement[] {
                      new ExpressionStatement(
                          new Identifier("foo")
                      )
                  }
              ),
              new CaseStatement(
                  new NumberLiteral(0),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                  }
              ),
              new CaseStatement(
                  new NumberLiteral(1),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("baz")
                    )
                  }
              )
            }
        ),
        "switch (something) {default: foo; case 0: bar; case 1: baz;}"
    );
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
              new CaseStatement(
                  new NumberLiteral(0),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                  }
              ),
              new CaseStatement(
                  null,
                  new Statement[] {
                      new ExpressionStatement(
                          new Identifier("foo")
                      )
                  }
              ),
              new CaseStatement(
                  new NumberLiteral(1),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("baz")
                    )
                  }
              )
            }
        ),
        "switch (something) {case 0: bar; default: foo; case 1: baz;}"
    );
    assertParserOutput(
        new SwitchStatement(
            new Identifier("something"),
            new CaseStatement[] {
              new CaseStatement(
                  new NumberLiteral(0),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("bar")
                    )
                  }
              ),
              new CaseStatement(
                  new NumberLiteral(1),
                  new Statement[] {
                    new ExpressionStatement(
                        new Identifier("baz")
                    )
                  }
              ),
              new CaseStatement(
                  null,
                  new Statement[] {
                      new ExpressionStatement(
                          new Identifier("foo")
                      )
                  }
              )
            }
        ),
View Full Code Here

  public void testVariableStatement() throws CompilerException {
    assertParserOutput(
        new VariableStatement(
            new VariableDeclaration[] {
                new VariableDeclaration(
                    new Identifier("foo"),
                    null
                )
            }
        ),
        "var foo;"
    );
    assertParserOutput(
        new VariableStatement(
            new VariableDeclaration[] {
                new VariableDeclaration(
                    new Identifier("foo"),
                    new NumberLiteral(1.0)
                )
            }
        ),
        "var foo = 1.0;"
    );
    assertParserOutput(
        new VariableStatement(
            new VariableDeclaration[] {
                new VariableDeclaration(
                    new Identifier("bar"),
                    new BinaryOperatorExpression(
                        new Identifier("x"),
                        new Identifier("baz"),
                        Token.KEYWORD_IN
                    )
                )
            }
        ),
        "var bar = x in baz;"
    );
    assertParserOutput(
        new VariableStatement(
            new VariableDeclaration[] {
                new VariableDeclaration(
                    new Identifier("foo"),
                    null
                ),
                new VariableDeclaration(
                    new Identifier("bar"),
                    null
                )
            }
        ),
        "var foo, bar;"
    );
    assertParserOutput(
        new VariableStatement(
            new VariableDeclaration[] {
                new VariableDeclaration(
                    new Identifier("foo"),
                    new NumberLiteral(1.0)
                ),
                new VariableDeclaration(
                    new Identifier("bar"),
                    null
                )
            }
        ),
        "var foo = 1.0, bar;"
    );
    assertParserOutput(
        new VariableStatement(
            new VariableDeclaration[] {
                new VariableDeclaration(
                    new Identifier("foo"),
                    new NumberLiteral(1.0)
                ),
                new VariableDeclaration(
                    new Identifier("bar"),
                    new BinaryOperatorExpression(
                        new Identifier("x"),
                        new Identifier("baz"),
                        Token.KEYWORD_IN
                    )
                )
            }
        ),
View Full Code Here

  }

  public void testForInStatement() throws CompilerException {
    assertParserOutput(
        new ForInStatement(
            new Identifier("foo"),
            new ArrayLiteral(
                new Expression[] {
                    new NumberLiteral(1.0),
                    new NumberLiteral(2.0),
                    new NumberLiteral(3.0),
                    new NumberLiteral(4.0)
                }
            ),
            new EmptyStatement()
        ),
        "for (foo in [1, 2, 3, 4]);"
    );
    assertParserOutput(
        new ForInStatement(
            new PropertyExpression(
                new Identifier("foo"),
                new StringLiteral("bar")
            ),
            new ArrayLiteral(
                new Expression[] {
                    new NumberLiteral(1.0),
                    new NumberLiteral(2.0),
                    new NumberLiteral(3.0),
                    new NumberLiteral(4.0)
                }
            ),
            new EmptyStatement()
        ),
        "for (foo.bar in [1, 2, 3, 4]);"
    );
    assertParserOutput(
        new ForInStatement(
            new VariableDeclaration(
                new Identifier("foo"),
                null
            ),
            new ArrayLiteral(
                new Expression[] {
                    new NumberLiteral(1.0),
View Full Code Here

  public void testPropertyExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new PropertyExpression(
                new Identifier("foo"),
                new StringLiteral("bar")
            )
        ),
        "foo.bar;"
    );
    assertParserOutput(
        new ExpressionStatement(
            new PropertyExpression(
                new Identifier("foo"),
                new StringLiteral("bar")
            )
        ),
        "foo[\"bar\"];"
    );
View Full Code Here

  public void testNewExpression() throws CompilerException {
    assertParserOutput(
        new ExpressionStatement(
            new NewExpression(
                new Identifier("Object"),
                new Expression[] {
                }
            )
        ),
        "new Object();"
    );
    assertParserOutput(
        new ExpressionStatement(
            new NewExpression(
                new Identifier("Object"),
                new Expression[] {
                  new NumberLiteral(1.0)
                }
            )
        ),
        "new Object(1.0);"
    );
    assertParserOutput(
        new ExpressionStatement(
            new NewExpression(
                new Identifier("Object"),
                new Expression[] {
                  new NumberLiteral(1.0),
                  new StringLiteral("hatstand")
                }
            )
View Full Code Here

        ),
        "continue;"
    );
    assertParserOutput(
        new ContinueStatement(
            new Identifier("loop")
        ),
        "continue loop;"
    );
  }
View Full Code Here

TOP

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

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.