Exemplo n.º 1
0
        /// <summary>
        /// Gets a VariableAST
        /// </summary>
        /// <returns>VariableAST</returns>
        private AST Variable()
        {
            VariableAST ast = new VariableAST(this.currentToken);

            this.ConsumeToken(TokenType.IDTOKEN);
            return(ast);
        }
Exemplo n.º 2
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;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Gets a ReadAST
        /// </summary>
        /// <returns>ReadAST</returns>
        private AST Read()
        {
            Token token = this.currentToken;

            this.ConsumeToken(TokenType.READ);
            VariableAST variable = this.Variable() as VariableAST;

            return(new ReadAST(token, variable));
        }
Exemplo n.º 4
0
        /// <summary>
        /// Gets an assignment AST
        /// </summary>
        /// <returns>AssignmentAST</returns>
        private AST Assignment()
        {
            VariableAST left  = this.Variable() as VariableAST;
            Token       token = this.currentToken;

            this.ConsumeToken(token.type);
            AST       right = this.Expression();
            AssignAST ast   = new AssignAST(left, this.currentToken, right);

            return(ast);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets a VariableDeclarationAST
        /// </summary>
        /// <returns>VariableDeclarationAST</returns>
        private AST VariableDeclaration()
        {
            this.ConsumeToken(TokenType.VAR);
            VariableAST variable = new VariableAST(this.currentToken);

            this.ConsumeToken(TokenType.IDTOKEN);
            this.ConsumeToken(TokenType.TWODOT);
            TypeAST type = (TypeAST)this.TypeSpec();

            if (this.currentToken.type == TokenType.SEMICOLON)
            {
                return(new VariableDeclarationAST(variable, type, this.currentToken));
            }
            else
            {
                this.ConsumeToken(TokenType.ASSIGN);
                return(new VariableDeclarationAST(variable, type, this.currentToken, this.Expression()));
            }
        }
Exemplo n.º 6
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));
        }
Exemplo n.º 7
0
 public AssignAST(VariableAST left, Token operation, AST right) : base(operation)
 {
     this.left  = left;
     this.right = right;
 }
Exemplo n.º 8
0
        /// <summary>
        /// Traverses variable AST
        /// </summary>
        /// <param name="ast">VariableAST</param>
        /// <returns>Symbol value</returns>
        private object VisitVariableAST(VariableAST ast)
        {
            string variableName = (string)ast.value;

            return(this.symbolTable.LookupSymbol(variableName).value);
        }
Exemplo n.º 9
0
 public ReadAST(Token token, VariableAST variable) : base(token)
 {
     this.variable = variable;
 }
 public VariableDeclarationAST(VariableAST varNode, TypeAST typeNode, Token token, AST assignValue = null) : base(token)
 {
     this.assignedValue = assignValue;
     this.varNode       = varNode;
     this.typeNode      = typeNode;
 }