public MyVoid VisitVariableExpr(Expr.Variable expr)
        {
            if (!(scopes.Count == 0))
            {
                if (scopes.Peek().TryGetValue(expr.name.lexeme, out bool value))
                {
                    if (value == false)
                    {
                        //If you do `var a = a;` then it is an error
                        Lox.Error(expr.name, "Cannot read local variable in its own initializer.");
                    }
                }
                else
                {
                    Lox.Error(expr.name, $"Lookup of {expr.name.lexeme} failed");
                }
            }

            resolveLocal(expr, expr.name);
            return(null);
        }
示例#2
0
 public string VisitVariableExpr(Expr.Variable expr)
 {
     return("Printing variable expression not implemeneted");
 }
示例#3
0
 public object VisitVariableExpr(Expr.Variable expr)
 {
     //return environment.Get(expr.name);
     return(LookUpVariable(expr.name, expr));
 }