public double Visit(UnaryExpr un)
 {
     ils.Add(MakeListItem(un.OP));
     Console.Write("( " + ((un.OP == OPERATOR.MUL) ? "mul " : "add "));
     un.Right.accept(this);
     Console.Write(" ) ");
     return(0);
 }
Example #2
0
 public double Visit(UnaryExpr un)
 {
     un.Right.accept(this);
     if (un.OP == OPERATOR.PLUS)
     {
         eval_stack.Push(eval_stack.Pop());
     }
     else if (un.OP == OPERATOR.MINUS)
     {
         eval_stack.Push(-eval_stack.Pop());
     }
     return(Double.NaN);
 }
Example #3
0
 public double Visit(UnaryExpr un)
 {
     un.Right.accept(this);
     if (un.OP == OPERATOR.PLUS)
     {
         Console.Write("  + ");
     }
     else if (un.OP == OPERATOR.MINUS)
     {
         Console.Write("  - ");
     }
     return(Double.NaN);
 }
Example #4
0
        public double Visit(UnaryExpr un)

        {
            if (un.OP == OPERATOR.PLUS)
            {
                return(+un.Right.accept(this));
            }
            else if (un.OP == OPERATOR.MINUS)
            {
                return(-un.Right.accept(this));
            }
            return(Double.NaN);
        }
        /// <summary>
        ///
        /// </summary>
        public Expr Factor()
        {
            TOKEN l_token;
            Expr  RetValue = null;

            if (Current_Token == TOKEN.TOK_DOUBLE)
            {
                RetValue      = new Number(GetNumber());
                Current_Token = GetToken();
            }
            else if (Current_Token == TOKEN.TOK_OPAREN)
            {
                Current_Token = GetToken();

                RetValue = Expr();  // Recurse

                if (Current_Token != TOKEN.TOK_CPAREN)
                {
                    Console.WriteLine("Missing Closing Parenthesis\n");
                    throw new Exception();
                }
                Current_Token = GetToken();
            }

            else if (Current_Token == TOKEN.TOK_PLUS || Current_Token == TOKEN.TOK_SUB)
            {
                l_token       = Current_Token;
                Current_Token = GetToken();
                RetValue      = Factor();

                RetValue = new UnaryExpr(RetValue,
                                         l_token == TOKEN.TOK_PLUS ? OPERATOR.PLUS : OPERATOR.MINUS);
            }
            else
            {
                Console.WriteLine("Illegal Token");
                throw new Exception();
            }


            return(RetValue);
        }
Example #6
0
 public double Visit(UnaryExpr un)
 {
     un.Right.accept(this);
     // ils.Add(MakeListItem(un.OP));
     return(0);
 }
        public static Expr ParseTwo()
        {
            Expr r = new UnaryExpr(new Number(10), OPERATOR.MINUS);

            return(r);
        }