Exemplo n.º 1
0
  @Override
  public Token parse() {
    Token next = first.getNext();

    if (!next.isOperator(Operator.BRACKET_LEFT))
      throw new RuntimeException("Expected '(' after WHILE, found: " + next);

    next = next.getNext();
    testExp = new BooleanExpression(next, scope);
    next = testExp.parse();

    if (!next.isOperator(Operator.BRACKET_RIGHT))
      throw new RuntimeException("Expected ')' after WHILE condition, found: " + next);

    next = next.getNext();
    if (!next.isNewline()) throw new RuntimeException("Expected newline, found: " + next);

    next = next.getNext();

    Keyword[] target = {Keyword.END};
    statements = new StatementGroup(next, target, scope);
    next = statements.parse();

    return next.getNext();
  }