예제 #1
0
 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;
 }
예제 #2
0
 /// <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);
     }
 }
예제 #3
0
        /// <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);
        }
예제 #4
0
        /// <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));
        }