/// <summary> /// Parse a class declaration /// </summary> private Stmt ClassDeclaration() { Token name = Consume(TokenType.IDENTIFIER, "Expect class name"); // Superclass Expr.Variable superclass = null; if (Match(TokenType.LESS)) { Consume(TokenType.IDENTIFIER, "Expect superclass name."); superclass = new Expr.Variable(Previous()); } // Body Consume(TokenType.LEFT_BRACE, "Expect '{' before class body"); List <Stmt.Function> methods = new List <Stmt.Function>(); while (!Check(TokenType.RIGHT_BRACE) && !IsAtEnd()) { methods.Add((Stmt.Function)Function("method")); } Consume(TokenType.RIGHT_BRACE, "Expect '}' after class body."); return(new Stmt.Class(name, superclass, methods)); }
public Value Visit(Expr.Variable var) { Value v = _env.Lookup(var); v.Span = var.Span; return(v); }
public object visitVariableExpr(Expr.Variable varExpr) { captureToken(varExpr.name); getNamedVariable(varExpr.name); return(null); }
public object VisitVariableExpr(Expr.Variable expr) { if (this.Macros.Contains(expr.Name)) { executeBlock((this.Macros.Get(expr.Name) as Stmt.Macro).Body.Statements, new Environment(IntEnvironment)); return(true); } return(IntEnvironment.Get(expr.Name)); }
public Unit VisitVariableExpr(Expr.Variable expr) { if (_Scopes.Count != 0 && _Scopes[_Scopes.Count - 1].ContainsKey(expr.Name.Lexeme) && _Scopes[_Scopes.Count - 1][expr.Name.Lexeme] == false) { CSLox.Error(expr.Name, "Can't read local variable in it own initalizer."); } ResolveLocal(expr, expr.Name); return(new Unit()); }
/// <summary> /// Resolve a variable expression /// </summary> /// <param name="expr">The expression</param> public object Visit(Expr.Variable expr) { if (!_scopes.IsEmpty() && _scopes.Peek().Get(expr.Name.Lexeme) == false) { _error_handler.Error(expr.Name, "Cannot read local variable in its own initializer."); } ResolveLocal(expr, expr.Name); return(null); }
public LoxVoid VisitVariableExpr(Expr.Variable expr) { if (_scopes.Any() && _scopes.Peek().TryGetValue(expr.Name.Lexeme, out Variable variable) && variable.State == VariableState.Declared) { Lox.Error(expr.Name, "Cannot read local variable in its own initializer."); } ResolveLocal(expr, expr.Name); return(null); }
public object VisitVariableExpr(Expr.Variable expr) { if (_scopes.Count != 0 && _scopes.Peek().TryGetValue(expr.name.Lexeme, out var value) && value.State == VariableState.Declared) { Lox.Error(expr.name, "Can't read local variable in its own initializer."); } ResolveLocal(expr, expr.name, true); return(null); }
public Unit VisitVariableExpr(Expr.Variable expr) { if (Scopes.Count != 0) { var scope = Scopes.Peek(); if (scope.ContainsKey(expr.Name.Lexeme) && scope[expr.Name.Lexeme] == false) { CSLox.Error(expr.Name, "Can't read local variable in it's own initalizer"); } } ResolveLocal(expr, expr.Name); return(new Unit()); }
public object VisitVariableExpr(Expr.Variable expr) { if (scopes.Count > 0 && scopes.Peek().ContainsKey(expr.Name.Lexeme) && scopes.Peek()[expr.Name.Lexeme] == false) { throw new InterpretingException(expr.Name, "Can't read local variable in its own initializer."); } ResolveLocal(expr, expr.Name); return(null); }
public object VisitVariableExpr(Expr.Variable expr) { if (Scopes.Count != 0 && Scopes.Peek().ContainsKey(expr.Name.Lexeme) && Scopes.Peek()[expr.Name.Lexeme] == false) { Lox.Error(expr.Name, "Can't read local variable in its own initializer"); } ResolveLocal(expr, expr.Name); return(null); }
public Value Lookup(Expr.Variable name) { if (_vars.ContainsKey(name.Name)) { return(_vars[name.Name].Force()); } if (_enclosing != null) { return(_enclosing.Lookup(name)); } throw new ErrorBuilder().Msg($"undefined variable `{name.Name}`").Type(ErrorType.UnboundVariable) .Span(name.Span).Build(); }
public object visitVariableExpr(Expr.Variable expr) { //jlox: (!scopes.isEmpty() && scopes.peek().get(expr.name.lexeme()) == Boolean.FALSE) if (scopes.Count > 0 && scopes[scopes.Count - 1].ContainsKey(expr.name.lexeme())) { if (scopes[scopes.Count - 1][expr.name.lexeme()] == false) // declared but not yet defined { Interpreter.error(expr.name, "Cannot read local variable in its own initializer."); } } resolveLocal(expr, expr.name); return(null); }
public Unit VisitVariableExpr(Expr.Variable expr) { if (Scopes.Count != 0) { var scope = Scopes.Peek(); if (scope.ContainsKey(expr.Name.Lexeme) && scope[expr.Name.Lexeme] == false) { CSLox.Error(expr.Name, "Can't read local variable in it's own initalizer"); } } // Where a variable is referenced // we send that info into to the interpreter ResolveLocal(expr, expr.Name); return(new Unit()); }
public static TrashObject VariableExpr(this Interpreter interpreter, Expr.Variable expr) { var env = interpreter.IntEnvironment; while (env != null && !env.Contains(expr.Name)) { // run through all the environments to check if we have the variable env = env.Enclosing; } if (env == null) { // this is an interesting issue // since the dot operator is treated as a binary operator, this happens when trying to access stuff // so for now, I might treat identifiers as strings and see if I can get classes working //throw new Interpreter.RuntimeError($"Trying to access non-existing variable {expr.Name.Literal}"); return(new TrashObject(expr.Name)); } var value = env.Get(expr.Name).Access(); if (value is Stmt.Macro) // if it's a macro, run it as a macro { // I'm lazy, so I'll just note it down here // the argument list on Macros doesn't actually matter // ie. since named arguments are passed in, the argument list is more of a documentation than anything var macro = value as Stmt.Macro; var newEnv = new Environment(macro.Name.Literal, interpreter.IntEnvironment); if (expr.Arguments != null) { foreach (var assign in expr.Arguments.Values) { // you know // I could probably have made this, so define takes an assign statement // but again // I'm lazy // so I'll leave this here for when I stumble upon it again and decide to remake the function newEnv.Define(assign.Name, interpreter.Evaluate(assign.Initialiser)); } } return(interpreter.ExecuteBlock(macro.Body.Statements, newEnv)); } return(env.Get(expr.Name)); }
public TypeSpecifier VisitVariableExpression(Expr.Variable exp) { if (_namedValues.ContainsKey(exp.Name.Source)) { //_valueStack.Push(_namedValues[exp.Name.Source].Value); var variable = _namedValues[exp.Name.Source]; var value = variable.Value; var loadinst = LLVM.BuildLoad(_builder, value, exp.Name.Source); _valueStack.Push(loadinst); if (variable.Binding != null) { HandleBinding(variable, true); } } else { throw new Exception("Unknown variable name"); } return(_namedValues[exp.Name.Source].KtsType); }
private Stmt ClassDeclaration() { Token name = Consume(Identifier, "Expect class name."); Expr.Variable superclass = null; if (Match(Less)) { Consume(Identifier, "Expect superclass name."); superclass = new Expr.Variable(Previous()); } Consume(LeftBrace, "Expect '{' before class body."); List <Stmt.Function> methods = new List <Stmt.Function>(); while (!Check(RightBrace) && !IsAtEnd()) { methods.Add(Function("method")); } Consume(RightBrace, "Expect '}' after class body."); return(new Stmt.Class(name, superclass, methods)); }
public Class(Token name, Expr.Variable superclass, List <Stmt.Function> methods) { Name = name; Superclass = superclass; Methods = methods; }
public string VisitVariableExpr(Expr.Variable expr) { return(expr.Name.Lexeme); }
public TrashObject VisitVariableExpr(Expr.Variable expr) { return(this.VariableExpr(expr)); }
public Token visitVariable(Expr.Variable variable) { return(variable.name); }
public object VisitVariableExpr(Expr.Variable var, object options) { return(var.token.lexeme); }
public Value Visit(Expr.Variable expr) { var value = this.LookupVariable(expr.Name); return(this._instructionBuilder.Load(value.ElementType, value).RegisterName(expr.Name)); }
public object VisitVariableExpr(Expr.Variable expr) { return(LookUpVariable(expr.Name, expr)); }
public void Visit(Expr.Variable expr) => _sql.Append(expr.IsProperty ? $"SUM(name = '{expr.Token.Text}' AND " : expr.Token.Text);
public string VisitVariableExpr(Expr.Variable expr) { return(Parenthesize(expr.Name.Lexeme, expr)); }
public string VisitVariableExpr(Expr.Variable expr) { return(Parenthesize("var", expr)); }
public string VisitVariableExpr(Expr.Variable expr) { return(Printer(expr.Name.Lexeme, expr)); }
public string visitVariableExpr(Expr.Variable expr) { throw new NotImplementedException(); }
public string visitVariable(Expr.Variable expr) { throw new System.NotImplementedException(); }