private void _VisitDeclareNode(ASTDeclareNode node) { if (_Tables.Lookup(node.LeftChild.Value.Value) != null) { throw new Exception("Variable " + node.LeftChild.Value.Value + " is defined more than once!"); } _Tables.Define(node.LeftChild.Value.Value, node.RightChild.Value.Value); }
private void _VisitDeclare(ASTDeclareNode node) { TokenType type = node.RightChild.Value.Type; string name = node.LeftChild.Value.Value; switch (type) { case TokenType.FLOAT: GLOBAL_SCOPE.Add(name, (float)0); return; case TokenType.INT: GLOBAL_SCOPE.Add(name, (int)0); return; default: throw new Exception("Unknown type: " + type.ToString()); } }
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 }