Example #1
0
        public object visitPostfixExpr(Expr.postfix pf)
        {
            object value = evaluate(pf.expr);

            checkNumberOperand(pf.keyword, value);
            object assignValue = value;

            if (pf.keyword.type == TokenType.PLUS_PLUS)
            {
                assignValue = ((double)value) + 1.0;
            }
            else
            {
                assignValue = ((double)value) - 1.0;
            }

            if (locals.TryGetValue(pf.expr, out int distance))
            {
                environment.assignAt(distance, new HelperFunctions.GetToken().evaluate(pf.expr), (double)assignValue);
            }
            else
            {
                globals.assignAt(distance, new HelperFunctions.GetToken().evaluate(pf.expr), (double)assignValue);
            }

            return(value);
        }
Example #2
0
 public object visitPostfixExpr(Expr.postfix pf)
 {
     resolve(pf.expr);
     return(null);
 }
Example #3
0
 public string visitPostfixExpr(Expr.postfix pf)
 {
     return(parenthesize(pf.keyword.lexeme + "p", new Expr[] { pf.expr }));
 }