Esempio n. 1
0
        public Expr MatchFactor()
        {
            Expr left = MatchValue();

            if (fallback)
            {
                return(null);
            }

            if (tk.Type == TokenType.Times)
            {
                var a = new Arith();
                a.Op = ArithOp.Mul;
                Match(TokenType.Times);
                a.Left  = left;
                a.Right = MatchFactor();

                if (fallback)
                {
                    return(null);
                }

                return(a);
            }
            else if (tk.Type == TokenType.Slash)
            {
                var a = new Arith();
                a.Op = ArithOp.Div;
                Match(TokenType.Slash);
                a.Left  = left;
                a.Right = MatchFactor();

                if (fallback)
                {
                    return(null);
                }

                return(a);
            }

            if (fallback)
            {
                return(null);
            }

            return(left);
        }
Esempio n. 2
0
        public Expr MatchTerm()
        {
            Expr left = MatchFactor();

            if (fallback)
            {
                return(null);
            }

            if (tk.Type == TokenType.Plus)
            {
                var a = new Arith();
                a.Op = ArithOp.Add;
                Match(TokenType.Plus);
                a.Left  = left;
                a.Right = MatchTerm();

                if (fallback)
                {
                    return(null);
                }

                return(a);
            }
            else if (tk.Type == TokenType.Minus)
            {
                var a = new Arith();
                a.Op = ArithOp.Sub;
                Match(TokenType.Minus);
                a.Left  = left;
                a.Right = MatchTerm();

                if (fallback)
                {
                    return(null);
                }

                return(a);
            }

            if (fallback)
            {
                return(null);
            }

            return(left);
        }