Ejemplo n.º 1
0
        public object Visit_DeclarationStatement(DeclarationStatement declStmt)
        {
            string varName = declStmt.Name;

            Current[varName] = declStmt.Expression.Accept(this);

            return(0);
        }
Ejemplo n.º 2
0
        public object Visit_DeclarationStatement(DeclarationStatement declStmt)
        {
            string type = declStmt.Type;

            if (currentTable.LookUp(type, out ISymbol symbol))
            {
                string  symbolName = declStmt.Name;
                ISymbol varSymbol  = new VariableSymbol(symbolName, symbol);

                if (!currentTable.Define(varSymbol))
                {
                    throw RaiseError(ScriptErrorCode.ID_ALREADY_DECLARED, declStmt.Token);
                }

                return(0);
            }
            throw RaiseError(ScriptErrorCode.UNDEFINED_SYMBOL, declStmt.Token);
        }
Ejemplo n.º 3
0
        private DeclarationStatement Consume_VariableDeclaration()
        {
            DeclarationStatement declStmt = new DeclarationStatement();
            string variableType           = currentToken.Value.ToString();

            Consume(TokenType.TYPESPEC);
            string variableName = currentToken.Value.ToString();

            declStmt.SetType(variableType);
            declStmt.SetName(variableName);

            Consume(TokenType.ID);
            Consume(TokenType.ASSIGN);
            IExpression expression = Consume_Expression();

            declStmt.SetExpression(expression);

            Consume(TokenType.SEMI);

            return(declStmt);
        }