Exemple #1
0
        /// <summary>
        /// Checks the static semantic constraints of a BinOpNode.
        /// </summary>
        ///
        /// <returns>An ISemanticCheckValue.</returns>
        /// <param name="node">Node.</param>
        public ISemanticCheckValue VisitDeclarationNode(DeclarationNode node)
        {
            // check that the id property is ok
            IProperty property = getVariableProperty(node);

            if (property == voidProperty)
            {
                return(voidProperty);
            }

            VariableIdNode idNode = node.IDNode;

            // if the property is declared already, it's an error
            if (property.Declared)
            {
                analyzer.notifyError(new DeclarationError(idNode));
            }
            else
            {
                // if it wasn't declared, now it is.
                property.Declared = true;
                // check the AssignNode
                node.AssignNode.Accept(this);
            }

            return(voidProperty);
        }
Exemple #2
0
        /// <summary>
        /// Visits the declaration node.
        /// </summary>
        /// <returns>An ISemanticCheckValue.</returns>
        /// <param name="node">Node.</param>
        public ISemanticCheckValue VisitDeclarationNode(DeclarationNode node)
        {
            // adds the id into the symbolic table and executes the assign node
            addNewId(node.IDNode);
            node.AssignNode.Accept(this);

            return(voidProperty);
        }
Exemple #3
0
        public DeclarationNode CreateDeclarationNode(VariableIdNode idNode, StatementsNode statementsNode, Token t)
        {
            DeclarationNode declarationNode = new DeclarationNode(idNode, symbolTable, t);

            declarationNode.AssignNode = CreateAssignNode(idNode, t);
            statementsNode.Statement   = declarationNode;

            return(declarationNode);
        }
Exemple #4
0
        /// <summary>
        /// Parses a declaration statement.
        /// </summary>
        /// <returns>The next token.</returns>
        /// <param name="token">Token.</param>
        /// <param name="statementsNode">A StatementsNode.</param>
        private Token ParseDeclaration(Token token, StatementsNode statementsNode)
        {
            // Try to parse all the pieces that a DeclarationNode needs to be evaluated.
            try {
                VariableIdNode idNode = nodeBuilder.CreateIdNode();
                // parse the target id
                Token next = ParseVarId(scanner.getNextToken(token), idNode);

                match(next, TokenType.SET_TYPE);
                // parse the id's type
                next = ParseType(scanner.getNextToken(next), idNode);

                // create the actual DeclarationNode
                DeclarationNode declarationNode = nodeBuilder.CreateDeclarationNode(idNode, statementsNode, token);
                // parse the assign for the DeclarationNode
                return(ParseAssign(next, declarationNode.AssignNode));
            } catch (UnexpectedTokenException ex) {
                return(FastForwardToStatementEnd(ex));
            }
        }
Exemple #5
0
 /// <summary>
 /// Visits the declaration node.
 /// </summary>
 /// <returns>An ISemanticCheckValue.</returns>
 /// <param name="node">Node.</param>
 public ISemanticCheckValue VisitDeclarationNode(DeclarationNode node)
 {
     // nothing to evaluate here, it's done from the ExecutionVisitor
     return(voidProperty);
 }
Exemple #6
0
 /// <summary>
 /// Visits the declaration node.
 /// </summary>
 /// <returns>An ISemanticCheckValue.</returns>
 /// <param name="node">Node.</param>
 public ISemanticCheckValue VisitDeclarationNode(DeclarationNode node)
 {
     // return the evaluation of the node's assignment
     return(node.AssignNode.Accept(this));
 }