示例#1
0
 private void _VisitVarNode(ASTVarNode node)
 {
     if (_Tables.Lookup(node.Value.Value) == null)
     {
         throw new Exception("Variable " + node.Value.Value + " is undefined!");
     }
 }
示例#2
0
        private ASTNode _DeclareStatement()
        {
            var type = _CurrentToken;

            if (_CurrentToken.Type == TokenType.INT ||
                _CurrentToken.Type == TokenType.FLOAT)
            {
                _Eat(_CurrentToken.Type);
            }
            else
            {
                throw new Exception("Unexpected token: " + type.Value + ". Expected a type.");
            }

            //Parse the current token as a variable
            ASTVarNode name = _Variable();

            ASTDeclareNode node = new ASTDeclareNode(name, new ASTTypeNode(type));

            _Eat(TokenType.SEMI);
            return(node);

            //TODO: Support assigning to a just-declared variable
        }