예제 #1
0
        private AExpression CalcTerm()
        {
            var result = CalcFactor();

            while (CurrentChar() == '+' || CurrentChar() == '-')
            {
                char curChar = CurrentChar();
                NextChar();
                AExpression right = CalcFactor();
                result = new Expression(curChar, result, right);
            }

            return(result);
        }
예제 #2
0
        private AExpression CalcFactor()
        {
            var result = ParsePrimary();

            while (CurrentChar() == '/' || CurrentChar() == '*')
            {
                char curChar = CurrentChar();
                NextChar();
                AExpression right = ParsePrimary();
                result = new Expression(curChar, result, right);
            }

            return(result);
        }
예제 #3
0
        private AExpression ParsePrimary()
        {
            AExpression result = null;

            if (IsDigit(CurrentChar()))
            {
                result = ParseInteger();
            }
            else if (CurrentChar() == '(')
            {
                NextChar();
                result = CalcAll();
                SkipNextChar();
            }
            else
            {
                Console.WriteLine("Error: unexpected symbol " + CurrentChar() + " at " + cursor);
            }

            return(result);
        }
예제 #4
0
 public Expression(char oper, AExpression result, AExpression right2)
 {
     op    = oper;
     left  = result;
     right = right2;
 }