예제 #1
0
        // TermRhs: MultDivOperator Factor TermRhs
        private void MatchExprMultDiv(out IExpr result)
        {
            TokenTypes t;                               // remember the type
            IExpr      lhs;

            MatchExprExp(out lhs);
            result = lhs;                               // in case we get no matches
            while ((t = curToken.Type) == TokenTypes.FORWARDSLASH ||
                   t == TokenTypes.STAR ||
                   t == TokenTypes.MODULUS)
            {
                curToken = tokens.Extract();
                IExpr rhs;
                MatchExprExp(out rhs);
                bool bDecimal = (rhs.GetTypeCode() == TypeCode.Decimal &&
                                 lhs.GetTypeCode() == TypeCode.Decimal);
                switch (t)
                {
                case TokenTypes.FORWARDSLASH:
                    if (bDecimal)
                    {
                        result = new FunctionDivDecimal(lhs, rhs);
                    }
                    else
                    {
                        result = new FunctionDiv(lhs, rhs);
                    }
                    break;

                case TokenTypes.STAR:
                    if (bDecimal)
                    {
                        result = new FunctionMultDecimal(lhs, rhs);
                    }
                    else
                    {
                        result = new FunctionMult(lhs, rhs);
                    }
                    break;

                case TokenTypes.MODULUS:
                    result = new FunctionModulus(lhs, rhs);
                    break;
                }
                lhs = result;                           // in case continue in the loop
            }
        }
예제 #2
0
		// TermRhs: MultDivOperator Factor TermRhs
		private void MatchExprMultDiv(out IExpr result)
		{
			TokenTypes t;			// remember the type
			IExpr lhs;
			MatchExprExp(out lhs);
			result = lhs;			// in case we get no matches
			while ((t = curToken.Type) == TokenTypes.FORWARDSLASH ||
				t == TokenTypes.STAR ||
				t == TokenTypes.MODULUS)
			{
				curToken = tokens.Extract();
				IExpr rhs;
				MatchExprExp(out rhs);
				bool bDecimal = (rhs.GetTypeCode() == TypeCode.Decimal &&
					lhs.GetTypeCode() == TypeCode.Decimal);
				switch (t)
				{
					case TokenTypes.FORWARDSLASH:
						if (bDecimal)
							result = new FunctionDivDecimal(lhs, rhs);	
						else
							result = new FunctionDiv(lhs, rhs);	
						break;
					case TokenTypes.STAR:
						if (bDecimal)
							result = new FunctionMultDecimal(lhs, rhs);
						else
							result = new FunctionMult(lhs, rhs);
						break;
					case TokenTypes.MODULUS:
						result = new FunctionModulus(lhs, rhs);
						break;
				}
				lhs = result;		// in case continue in the loop
			}
		}