예제 #1
0
        // TermOp -> * SignedFactor TermOp
        // TermOp -> / SignedFactor TermOp
        // TermOp -> EPSILON
        Factor TermOp(Factor factor)
        {
            switch (lookahead.type)
            {
            case TokenType.MULTI:
                GetNextToken();
                factor.Multiply(SignedFactor());
                return(TermOp(factor));

            case TokenType.DEV:
                GetNextToken();
                factor.Divide(SignedFactor());
                return(TermOp(factor));

            default:
                return(factor);
            }
        }
예제 #2
0
        //SignedFactor -> + Factor | - Factor | Factor
        Factor SignedFactor()
        {
            switch (lookahead.type)
            {
            case TokenType.ADD:
                GetNextToken();
                return(Factor());

            case TokenType.SUB:
                GetNextToken();
                Factor t = Factor();
                t.Multiply(new Term(-1));
                return(t);

            default:
                return(Factor());
            }
        }
예제 #3
0
 // TermOp -> * SignedFactor TermOp
 // TermOp -> / SignedFactor TermOp
 // TermOp -> EPSILON
 Factor TermOp(Factor factor)
 {
     switch (lookahead.type) {
     case TokenType.MULTI:
         GetNextToken ();
         factor.Multiply (SignedFactor ());
         return TermOp (factor);
     case TokenType.DEV:
         GetNextToken ();
         factor.Divide (SignedFactor ());
         return TermOp (factor);
     default:
         return factor;
     }
 }