Exemplo n.º 1
0
		// ExprAddSub: PlusMinusOperator Term ExprRhs
		private void MatchExprAddSub(out IExpr result)
		{
			TokenTypes t;			// remember the type

			IExpr lhs;
			MatchExprMultDiv(out lhs);
			result = lhs;			// in case we get no matches
			while ((t = curToken.Type) == TokenTypes.PLUS || t == TokenTypes.PLUSSTRING || t == TokenTypes.MINUS)
			{
				curToken = tokens.Extract();
				IExpr rhs;
				MatchExprMultDiv(out rhs);
				TypeCode lt = lhs.GetTypeCode();
				TypeCode rt = rhs.GetTypeCode();
				bool bDecimal = (rt == TypeCode.Decimal &&
					lt == TypeCode.Decimal);
                bool bInt32 = (rt == TypeCode.Int32 &&
                    lt == TypeCode.Int32);
				bool bString = (rt == TypeCode.String ||
					lt == TypeCode.String);

				switch(t)
				{
					case TokenTypes.PLUSSTRING:
						result = new FunctionPlusString(lhs, rhs);
						break;
					case TokenTypes.PLUS:
                        if (bDecimal)
                            result = new FunctionPlusDecimal(lhs, rhs);
                        else if (bString)
                            result = new FunctionPlusString(lhs, rhs);
                        else if (bInt32)
                            result = new FunctionPlusInt32(lhs, rhs);
                        else
                            result = new FunctionPlus(lhs, rhs);
						break;
					case TokenTypes.MINUS:
						if (bDecimal)
							result = new FunctionMinusDecimal(lhs, rhs);
						else if (bString)
							throw new ParserException("'-' operator works only on numbers." + "  At column " + Convert.ToString(curToken.StartCol));
                        else if (bInt32)
                            result = new FunctionMinusInt32(lhs, rhs);
                        else
							result = new FunctionMinus(lhs, rhs);
						break;
				}
				lhs = result;		// in case continue in the loop
			}
		}
Exemplo n.º 2
0
		// ExprAddSub: PlusMinusOperator Term ExprRhs
		private void MatchExprAddSub(out IExpr result)
		{
			TokenTypes t;			// remember the type

			IExpr lhs;
			MatchExprMultDiv(out lhs);
			result = lhs;			// in case we get no matches
			while ((t = curToken.Type) == TokenTypes.PLUS || t == TokenTypes.PLUSSTRING || t == TokenTypes.MINUS)
			{
				curToken = tokens.Extract();
				IExpr rhs;
				MatchExprMultDiv(out rhs);
				TypeCode lt = lhs.GetTypeCode();
				TypeCode rt = rhs.GetTypeCode();
				bool bDecimal = (rt == TypeCode.Decimal &&
					lt == TypeCode.Decimal);
                bool bInt32 = (rt == TypeCode.Int32 &&
                    lt == TypeCode.Int32);
				bool bString = (rt == TypeCode.String ||
					lt == TypeCode.String);

				switch(t)
				{
					case TokenTypes.PLUSSTRING:
						result = new FunctionPlusString(lhs, rhs);
						break;
					case TokenTypes.PLUS:
                        if (bDecimal)
                            result = new FunctionPlusDecimal(lhs, rhs);
                        else if (bString)
                            result = new FunctionPlusString(lhs, rhs);
                        else if (bInt32)
                            result = new FunctionPlusInt32(lhs, rhs);
                        else
                            result = new FunctionPlus(lhs, rhs);
						break;
					case TokenTypes.MINUS:
						if (bDecimal)
							result = new FunctionMinusDecimal(lhs, rhs);
						else if (bString)
							throw new ParserException(Strings.Parser_ErrorP_MinusNeedNumbers + GetLocationInfo(curToken));
                        else if (bInt32)
                            result = new FunctionMinusInt32(lhs, rhs);
                        else
							result = new FunctionMinus(lhs, rhs);
						break;
				}
				lhs = result;		// in case continue in the loop
			}
		}