/// <summary> /// Implements the following grammar rules /// Expression_iCont -> {op_i+1} Expression_i+1 Expression_iCont /// Expression_iCont -> Epsilon /// </summary> /// <param name="expressionLevel">the current level of the expression</param> /// <param name="expressionLeft">the left part of the current expression</param> /// <param name="enclosing">the root element for which this expression should be parsed</param> /// <returns></returns> private Expression ExpressionContinuation(int expressionLevel, Expression expressionLeft) { Expression retVal = expressionLeft; string[] operators = BinaryExpression.Images(BinaryExpression.OperatorsByLevel[expressionLevel]); string op = LookAhead(operators); if (op != null && op.CompareTo("<") == 0) { // Avoid <- to be confused with < -1 if (Index < Buffer.Length - 1 && Buffer[Index + 1] == '-') { op = null; } } if (op != null) // Expression_iCont -> {op_i+1} Expression_i+1 Expression_iCont { Match(op); BinaryExpression.OPERATOR oper = BinaryExpression.FindOperatorByName(op); Expression expressionRight = Expression(expressionLevel + 1); if (expressionRight != null) { retVal = new BinaryExpression(Root, expressionLeft, oper, expressionRight); // {op_i+1} Expression_i+1 retVal = ExpressionContinuation(expressionLevel, retVal); // Expression_iCont } } return(retVal); }
/// <summary> /// Combines two types to create a new one /// </summary> /// <param name="right"></param> /// <returns></returns> public override Types.Type CombineType(Type right, BinaryExpression.OPERATOR Operator) { Types.Type retVal = null; if (Operator == BinaryExpression.OPERATOR.MULT) { if (FullName.CompareTo("Default.BaseTypes.Speed") == 0 && right.FullName.CompareTo("Default.BaseTypes.Time") == 0) { NameSpace nameSpace = EnclosingNameSpaceFinder.find(this); retVal = nameSpace.findTypeByName("Distance"); } } else { if (IsDouble()) { if (right == EFSSystem.DoubleType) { retVal = this; } } else { if (right == EFSSystem.IntegerType) { retVal = this; } } } return(retVal); }
/// <summary> /// Combines two types to create a new one /// </summary> /// <param name="right"></param> /// <returns></returns> public virtual Type CombineType(Type right, BinaryExpression.OPERATOR Operator) { return(null); }
/// <summary> /// Performs the arithmetic operation based on the type of the result /// </summary> /// <param name="context">The context used to perform this operation</param> /// <param name="left"></param> /// <param name="Operation"></param> /// <param name="right"></param> /// <returns></returns> public virtual Values.IValue PerformArithmericOperation(Interpreter.InterpretationContext context, Values.IValue left, BinaryExpression.OPERATOR Operation, Values.IValue right) // left +/-/*/div/exp right { Values.IValue retVal = null; Functions.Function leftFunction = left as Functions.Function; Functions.Function rigthFunction = right as Functions.Function; if (rigthFunction == null) { if (leftFunction.Graph != null) { Functions.Graph graph = Functions.Graph.createGraph(Functions.Function.getDoubleValue(right)); rigthFunction = graph.Function; } else { Functions.Surface surface = Functions.Surface.createSurface(Functions.Function.getDoubleValue(right), leftFunction.Surface.XParameter, leftFunction.Surface.YParameter); rigthFunction = surface.Function; } } if (leftFunction.Graph != null) { Functions.Graph tmp = null; switch (Operation) { case BinaryExpression.OPERATOR.ADD: tmp = leftFunction.Graph.AddGraph(rigthFunction.Graph); break; case BinaryExpression.OPERATOR.SUB: tmp = leftFunction.Graph.SubstractGraph(rigthFunction.Graph); break; case BinaryExpression.OPERATOR.MULT: tmp = leftFunction.Graph.MultGraph(rigthFunction.Graph); break; case BinaryExpression.OPERATOR.DIV: tmp = leftFunction.Graph.DivGraph(rigthFunction.Graph); break; } retVal = tmp.Function; } else { Functions.Surface rightSurface = rigthFunction.getSurface(leftFunction.Surface.XParameter, leftFunction.Surface.YParameter); Functions.Surface tmp = null; switch (Operation) { case BinaryExpression.OPERATOR.ADD: tmp = leftFunction.Surface.AddSurface(rightSurface); break; case BinaryExpression.OPERATOR.SUB: tmp = leftFunction.Surface.SubstractSurface(rightSurface); break; case BinaryExpression.OPERATOR.MULT: tmp = leftFunction.Surface.MultiplySurface(rightSurface); break; case BinaryExpression.OPERATOR.DIV: tmp = leftFunction.Surface.DivideSurface(rightSurface); break; } retVal = tmp.Function; } return(retVal); }