public ForAST(Token token, StatementListAST ast, VariableAST variable, AST expression1, AST expression2) : base(token) { this.children = ast; this.variable = variable; this.expression1 = expression1; this.expression2 = expression2; }
/// <summary> /// Traverses a statement list AST /// </summary> /// <param name="ast">StatementListAST</param> private void VisitStatementListAST(StatementListAST ast) { foreach (AST node in ast.children) { this.VisitNode(node); } }
/// <summary> /// The start of the program /// </summary> /// <returns>Program AST</returns> private AST Program() { StatementListAST list = new StatementListAST(); List <AST> nodes = this.StatementList(); foreach (AST node in nodes) { list.children.Add(node); } return(list); }
/// <summary> /// Gets a ForAST /// </summary> /// <returns>ForAST</returns> private AST For() { Token token = this.currentToken; this.ConsumeToken(TokenType.FOR); VariableAST variable = this.Variable() as VariableAST; this.ConsumeToken(TokenType.IN); AST expressionAST = this.Expression(); this.ConsumeToken(TokenType.TWO_CONCECUTIVE_DOTS); AST expressionAST2 = this.Expression(); this.ConsumeToken(TokenType.DO); StatementListAST ast = new StatementListAST(); this.StatementList().ForEach(x => ast.children.Add(x)); this.ConsumeToken(TokenType.END); this.ConsumeToken(TokenType.FOR); return(new ForAST(token, ast, variable, expressionAST, expressionAST2)); }