Пример #1
0
 /**
  * Private contructor, use builder
  */
 public HeapAllocation(String variableName, IExpressions expression)
 {
     this.variableName = variableName;
     //        this.expressionResult = expression.eval(symbolicTable);
     this.expression = expression;
     //        pointer = heap.size();
     //        heap.put(heap.size() ,expressionResult);
     //        symbolicTable.put(variableName, pointer);
 }
Пример #2
0
 public SwitchStatement(IExpressions expression, IExpressions case1, IExpressions case2,
                    IMyStatement statementDefault, IMyStatement statementCase1, IMyStatement statementCase2)
 {
     this.expression = expression;
     this.case1 = case1;
     this.case2 = case2;
     this.statementDefault = statementDefault;
     this.statementCase1 = statementCase1;
     this.statementCase2 = statementCase2;
 }
        public async Task <ExpressionResponse> CalculateResult(string[] expressions, int?precision)
        {
            /*when calculations are to be implemented in this calculation engine instead of using the Maths API,
             * every expression in the chain will be either a SimpleArithmeticSingleExpression or ComplexArithmeticSingleExpression or we may create further
             * classes to handle specific expressions based on the Parser output
             * so all we have to do is call ReturnExpressionResults for every expression in the chain of expressions and it should return us the object
             * of the specific class that will handle that expression
             * For now, below are the categories
             * -> SimpleArithmeticSingleExpression is an expression involving 2 numbers and only one operator like +, -, * or /
             * -> ComplexArithmeticSingleExpression is an expression involving multiple numbers with multiple operators where BEDMAS will be applied
             * -> ComplexArithmeticSingleExpression is also an expression like sqrt(4), sin(45 deg)^2 etc but we may create separate class for this
             *
             * This is how the implementation will look like -
             * var expressionResponse = new ExpressionResponse();
             * foreach(var expression in expressions)
             * {
             *  var response = await ReturnExpressionResults(expression, precision);
             *  if(response!=null)
             *  {
             *      expressionResponse.result.Add(response.result.FirstOrDefault());
             *  }
             *  else
             *  {
             *      expressionResponse.result = null;
             *      expressionResponse.error = $"An error occurred while evaluating this expression - {expression}";
             *  }
             * }
             * return expressionResponse; */

            //Until then we use the below to resolve the chain of expressions -
            if (expressions.Length == 1)
            {
                return(await ReturnExpressionResults(expressions, precision));
            }
            else //This class ChainOfExpressions will not be required after we implement as described above.
                 //for now, create this class and call Maths API within.
            {
                _expressions = new ChainOfExpressions(_callMathsAPIService);
                return(await _expressions.CalculateResult(expressions, precision));
            }
        }
 public CalculateResultService(IParseExpressions parseExpressions, ICallMathsAPIService callMathsAPIService, IExpressions expressions)
 {
     _parseExpressions    = parseExpressions;
     _callMathsAPIService = callMathsAPIService;
     _expressions         = expressions;
 }
Пример #5
0
 /**
  * The constructor
  * @param expression The expression
  * @param thenStatement The correct statement
  * @param elseStatement The false statement
  */
 public IfStatement(IExpressions expression, IMyStatement thenStatement, IMyStatement elseStatement)
 {
     this.Expression = expression;
     this.thenStatement = thenStatement;
     this.elseStatement = elseStatement;
 }
Пример #6
0
 public void setExpression(IExpressions expression)
 {
     this.Expression = expression;
 }
Пример #7
0
 public SleepStatement(IExpressions time)
 {
     this.time = time;
 }
Пример #8
0
 /**
  * The constructor
  * @param variableName The var name
  * @param expression the expression
  */
 public WriteHeapStatement(String variableName, IExpressions expression)
 {
     this.variableName = variableName;
     this.expression = expression;
 }
Пример #9
0
 public void setExpression(IExpressions mExpression)
 {
     this.expression = mExpression;
 }
Пример #10
0
 /**
  * The constructor
  * @param expression Expression
  */
 public PrintStatement(IExpressions expression)
 {
     this.expression = expression;
 }
Пример #11
0
 public WhileStatement(IMyStatement statement, IExpressions expression)
 {
     this.statement = statement;
     this.expression = expression;
 }
Пример #12
0
 public LogicExpression(String theOperator, IExpressions expression1, IExpressions expression2)
 {
     this.operatorType = getOperatorType(theOperator);
     this.firstExpression = expression1;
     this.secondExpression = expression2;
 }
Пример #13
0
 /**
  * The constructor
  * @param variableName The name of variable
  * @param expression The expression
  */
 public AssignStatement(String variableName, IExpressions expression)
 {
     this.variableName = variableName;
     this.expression = expression;
 }
Пример #14
0
 public BooleanExpression(string myOperator, IExpressions expression1, IExpressions expression2)
 {
     this.operatorType = getOperatorType(myOperator);
     this.firstExpression = expression1;
     this.secondExpression = expression2;
 }
 /**
  * The constructor
  * @param operatorType The type of the operator for current arithmetic expression
  * @param firstExpression The first expression
  * @param secondExpression The second expression
  */
 public ArithmeticExpression(string operatorType, IExpressions firstExpression, IExpressions secondExpression)
 {
     this.operatorType = getOperatorType(operatorType);
     this.firstExpression = firstExpression;
     this.secondExpression = secondExpression;
 }