예제 #1
0
        private Expr Assignment()
        {
            Expr expr = Or();

            if (Match(TokenType.Equal))
            {
                Token equals = Previous();
                Expr  value  = Assignment();

                if (expr is Expr.Variable)
                {
                    Token name = ((Expr.Variable)expr).name;
                    expr = new Expr.Assign(name, value);
                }
                else if (expr is Expr.Get)
                {
                    Expr.Get get = (Expr.Get)expr;
                    expr = new Expr.Set(get.obj, get.name, value);
                }
                else
                {
                    Error(equals, "Invalid assignment target.");
                }
            }

            return(expr);
        }
예제 #2
0
        public object Visit(Expr.Assign expr)
        {
            Resolve(expr.value);
            ResolveLocal(expr, expr.name);

            return(null);
        }
예제 #3
0
        // Expr Visitors
        public object Visit(Expr.Assign expr)
        {
            object value = Evaluate(expr.value);

            if (locals.ContainsKey(expr))
            {
                int distance = locals[expr];
                environment.AssignAt(distance, expr.name, value);
            }
            else
            {
                globals.Assign(expr.name, value);
            }

            return(value);
        }
예제 #4
0
 // Expr Visitors
 public string Visit(Expr.Assign assign)
 {
     //return Parentherize2("=", assign.name.lexeme, assign.value);
     return("");
 }