Пример #1
0
        public void VisitDeclaration(DeclarationNode dn)
        {
            int    temp   = this.depth;
            string spaces = IncreaseDepth();

            this.io.WriteLine($"{spaces}Declaration: (\n{spaces}  Identifier: {dn.Identifier},\n{spaces}  Type: {dn.Type},\n{spaces}  Token: {dn.Token}\n{spaces})");
            this.depth = temp;
        }
Пример #2
0
        ASTNode VAR()
        {
            var node = new DeclarationNode();

            node.lexeme     = Consume("var", TokenType.KEYWORD);
            node.identifier = IDENT();
            Consume(":", TokenType.SEPARATOR);
            node.identifierType  = TYPE();
            node.identifierValue = VARTAIL();
            return(node);
        }
Пример #3
0
        public void VisitDeclaration(DeclarationNode dn)
        {
            string defaultValue = "";

            switch (dn.Type)
            {
            case SymbolType.IntegerValue: defaultValue = "0"; break;

            default: defaultValue = ""; break;
            }
            if (!this.symbolTable.AddEntry(new SymbolTableEntry(dn.Identifier, dn.Type, defaultValue)))
            {
                throw new DeclarationError($"Variable {dn.Identifier} has already been declared", dn.Token);
            }
        }