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); }
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)); } }
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); }
public string Visit(Expr.Variable _variable) { throw new NotImplementedException(); }
public object Visit(Expr.Variable _variable) { return(LookupVarable(_variable.name, _variable)); }