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

            checkNumberOperand(pf.keyword, value);
            if (pf.keyword.type == TokenType.PLUS_PLUS)
            {
                value = ((double)value) + 1.0;
            }
            else
            {
                value = ((double)value) - 1.0;
            }
            if (locals.TryGetValue(pf.expr, out int distance))
            {
                environment.assignAt(distance, new HelperFunctions.GetToken().evaluate(pf.expr), (double)value); //Assign value after change.
            }
            else
            {
                globals.assignAt(distance, new HelperFunctions.GetToken().evaluate(pf.expr), (double)value);
            }
            return(value);
        }
Example #2
0
 public object visitPrefixExpr(Expr.prefix pf) //These two functions may need further resolution
 {
     resolve(pf.expr);
     return(null);
 }
Example #3
0
 public string visitPrefixExpr(Expr.prefix pf)
 {
     return(parenthesize("p" + pf.keyword.lexeme, new Expr[] { pf.expr }));
 }