/// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public Expr Expr()
        {
            TOKEN l_token;
            Expr  RetValue = Term();

            while (Current_Token == TOKEN.TOK_PLUS || Current_Token == TOKEN.TOK_SUB)
            {
                l_token       = Current_Token;
                Current_Token = GetToken();
                Expr e1 = Expr();
                RetValue = new BinaryExpr(RetValue, e1,
                                          l_token == TOKEN.TOK_PLUS ? OPERATOR.PLUS : OPERATOR.MINUS);
            }

            return(RetValue);
        }
        /// <summary>
        ///
        /// </summary>
        public Expr Term()
        {
            TOKEN l_token;
            Expr  RetValue = Factor();

            while (Current_Token == TOKEN.TOK_MUL || Current_Token == TOKEN.TOK_DIV)
            {
                l_token       = Current_Token;
                Current_Token = GetToken();


                Expr e1 = Term();
                RetValue = new BinaryExpr(RetValue, e1,
                                          l_token == TOKEN.TOK_MUL ? OPERATOR.MUL : OPERATOR.DIV);
            }

            return(RetValue);
        }
Ejemplo n.º 3
0
        public double Visit(BinaryExpr bin)
        {
            if (bin.OP == OPERATOR.PLUS)
            {
                return(bin.Left.accept(this) + bin.Right.accept(this));
            }
            else if (bin.OP == OPERATOR.MUL)
            {
                return(bin.Left.accept(this) * bin.Right.accept(this));
            }
            else if (bin.OP == OPERATOR.DIV)
            {
                return(bin.Left.accept(this) / bin.Right.accept(this));
            }
            else if (bin.OP == OPERATOR.MINUS)
            {
                return(bin.Left.accept(this) - bin.Right.accept(this));
            }

            return(Double.NaN);
        }
Ejemplo n.º 4
0
        public double Visit(BinaryExpr bin)
        {
            bin.Left.accept(this);
            bin.Right.accept(this);

            if (bin.OP == OPERATOR.PLUS)
            {
                eval_stack.Push(eval_stack.Pop() + eval_stack.Pop());
            }
            else if (bin.OP == OPERATOR.MUL)
            {
                eval_stack.Push(eval_stack.Pop() * eval_stack.Pop());
            }
            else if (bin.OP == OPERATOR.DIV)
            {
                eval_stack.Push(eval_stack.Pop() / eval_stack.Pop());
            }
            else if (bin.OP == OPERATOR.MINUS)
            {
                eval_stack.Push(eval_stack.Pop() - eval_stack.Pop());
            }

            return(Double.NaN);
        }
Ejemplo n.º 5
0
        public double Visit(BinaryExpr bin)
        {
            bin.Left.accept(this);
            bin.Right.accept(this);

            if (bin.OP == OPERATOR.PLUS)
            {
                Console.Write(" + ");
            }
            else if (bin.OP == OPERATOR.MUL)
            {
                Console.Write(" * ");
            }
            else if (bin.OP == OPERATOR.DIV)
            {
                Console.Write(" / ");
            }
            else if (bin.OP == OPERATOR.MINUS)
            {
                Console.Write(" - ");
            }

            return(Double.NaN);
        }
        public static Expr ParseTwo()
        {
            Expr r = new BinaryExpr(new Number(3), new Number(4), OPERATOR.MUL);

            return(r);
        }