Example #1
0
        public object Visit(Expr.Variable _variable)
        {
            Scope scope = m_Scopes.Peek();

            if (scope != null && scope.ContainsKey(_variable.name.lexeme) && scope[_variable.name.lexeme] == false)
            {
                m_ErrorHandler.Error(_variable.name, "Cannot read local variable in its own initializer.");
            }

            ResolveLocal(_variable, _variable.name);
            return(null);
        }
Example #2
0
 private object LookupVarable(Token name, Expr.Variable _variable)
 {
     if (m_Locals.ContainsKey(_variable))
     {
         int distance = m_Locals[_variable];
         return(m_Enviroment.GetAt(distance, name.lexeme));
     }
     else
     {
         return(m_Globals.Get(name));
     }
 }
Example #3
0
        public object Visit(Expr.Postfix postfix)
        {
            object right = Evaluate(postfix.lhs);

            ValidateNumberOperand(postfix.opp, right);
            switch (postfix.opp.type)
            {
            case TokenType.MinusMinus:
                right = (double)right - 1;
                break;

            case TokenType.PlusPlus:
                right = (double)right + 1;
                break;
            }
            /// This was made up by me because in the book there is nothing that assigns this value.
            // Cast to variable type
            Expr.Variable asVariable = (Expr.Variable)postfix.lhs;
            // Assign it's value
            m_Enviroment.Assign(asVariable.name, right);
            // Return the value.
            return(right);
        }
Example #4
0
 public string Visit(Expr.Variable _variable)
 {
     throw new NotImplementedException();
 }
Example #5
0
 public object Visit(Expr.Variable _variable)
 {
     return(LookupVarable(_variable.name, _variable));
 }