private AstNode UndefineSymbol() { var line = Match(TokenType.Undef); var variable = Variable(); var node = new UndefNode(variable) { Line = line }; return(node); }
public override DynValue Visit(UndefNode undefNode) { var variable = undefNode.Variable as VariableNode; if (variable == null) { throw new RuntimeException("Expected a variable.", undefNode.Line); } Environment.LocalScope.UnSetInChain(variable.Identifier); return(DynValue.Zero); }
public override DynValue Visit(UndefNode undefNode) { switch (undefNode.Type) { case UndefineType.Local: if (CallStack.Count == 0) { throw new RuntimeException($"Attempt to undefine a local variable outside a function '{undefNode.Name}'.", undefNode.Line); } var callStackItem = CallStack.Peek(); if (!callStackItem.LocalVariableScope.ContainsKey(undefNode.Name)) { throw new RuntimeException($"Attempt to undefine a non-existent local variable '{undefNode.Name}'.", undefNode.Line); } callStackItem.LocalVariableScope.Remove(undefNode.Name); break; case UndefineType.Function: if (Environment.BuiltIns.ContainsKey(undefNode.Name)) { throw new RuntimeException($"Attempt to undefine a built-in function '{undefNode.Name}'.", undefNode.Line); } if (!Environment.Functions.ContainsKey(undefNode.Name)) { throw new RuntimeException($"Attempt to undefine a non-existent function '{undefNode.Name}'", undefNode.Line); } Environment.Functions.Remove(undefNode.Name); break; case UndefineType.Global: if (!Environment.Globals.ContainsKey(undefNode.Name)) { throw new RuntimeException($"Attempt to undefine a non-existent global variable '{undefNode.Name}'.", undefNode.Line); } Environment.Globals.Remove(undefNode.Name); break; default: throw new RuntimeException("Internal interpreter error: unexpected UndefType value.", undefNode.Line); } return(DynValue.Zero); }
private AstNode UndefineSymbol() { var line = Match(TokenType.Undef); var node = new UndefNode { Type = UndefineType.Global, Line = line }; if (Scanner.State.CurrentToken.Type == TokenType.Fn) { Match(TokenType.Fn); node.Type = UndefineType.Function; } else if (Scanner.State.CurrentToken.Type == TokenType.LocalVar) { Match(TokenType.LocalVar); node.Type = UndefineType.Local; } node.Name = (string)Scanner.State.CurrentToken.Value; Match(TokenType.Identifier); return(node); }
public abstract DynValue Visit(UndefNode undefNode);