public ArithmeticBinaryExpression(ArithmeticOperator operation, IExpression left, IExpression right) : base(left, right) { this.operation = operation; switch (operation) { case ArithmeticOperator.Add: this.function = AddOrConcatenateObjects; break; case ArithmeticOperator.Subtract: this.function = Operators.SubtractObject; break; case ArithmeticOperator.Multiply: this.function = Operators.MultiplyObject; break; case ArithmeticOperator.Divide: this.function = Operators.DivideObject; break; case ArithmeticOperator.IntegerDivide: this.function = Operators.IntDivideObject; break; case ArithmeticOperator.Modulo: this.function = Operators.ModObject; break; default: throw new ArgumentException("Invalid operator"); } }
private IExpression ParseBinaryExpressionLevelMultiply() { IExpression expression = this.ParseBinaryExpressionLevelAdd(); if (expression == null) { return(null); } Token token = this.NextToken(); while (token != null && token.Type == TokenType.Operator && (token.Value == "*" || token.Value == "/")) { ArithmeticOperator oper = token.Value == "*" ? ArithmeticOperator.Multiply : ArithmeticOperator.Divide; expression = new ArithmeticBinaryExpression(oper, expression, this.ParseBinaryExpressionLevelAdd()); token = this.NextToken(); } if (token != null) { this.PushToken(token); } return(expression); }
public ArithmeticExpression(IComparisonOperand left, IComparisonOperand right, ArithmeticOperator op) { _op = op; _left = left; _right = right; }
public ArithmeticExpression(IComparisonOperand left, IComparisonOperand right, ArithmeticOperator op) { this._op = op; this._left = left; this._right = right; }
public static ArithmeticOperator FromChar(this ArithmeticOperator op, char opchar) { if (op != null) { switch (opchar) { case '+': op.Operator = OperatorType.Add; break; case '-': op.Operator = OperatorType.Subtract; break; case '*': op.Operator = OperatorType.Multiply; break; case '/': op.Operator = OperatorType.Divide; break; default: op.Operator = OperatorType.None; break; } } return(op); }
private IExpression ParseBinaryExpressionLevelAdd() { IExpression expression = this.ParseDotExpression(); if (expression == null) { return(null); } Token token = this.NextToken(); while (token != null && token.Type == TokenType.Operator && (token.Value == "+" || token.Value == "-")) { ArithmeticOperator oper = token.Value == "+" ? ArithmeticOperator.Add : ArithmeticOperator.Subtract; expression = new ArithmeticBinaryExpression(oper, expression, this.ParseDotExpression()); token = this.NextToken(); } if (token != null) { this.PushToken(token); } return(expression); }
public static ArithmeticEvaluationStatement CreatePrefix(ArithmeticOperator op, EvaluationStatement operand, StatementInfo info, IStatement parentStatement = null) { return(new ArithmeticEvaluationStatement(null, op, operand, info) { ParentStatement = parentStatement }); }
public ArithmeticOperation(byte _arg1, byte _arg2, ArithmeticOperator _op, short _target, RegisterFileMap _registerFileMap, bool _conditional, short _address) : base(_registerFileMap, CYCLES, _address) { this.arg1 = _arg1; this.arg2 = _arg2; this.op = _op; this.targetAddress = _target; }
public BinaryArithmeticExpressionImpl(SQLVendorImpl vendor, ArithmeticOperator op, NonBooleanExpression left, NonBooleanExpression right) : base(vendor, op) { ArgumentValidator.ValidateNotNull(nameof(left), left); ArgumentValidator.ValidateNotNull(nameof(right), right); this._left = left; this._right = right; }
public void Arithmetic(ArithmeticOperator op, Source source, Register destination, Register alternate = null) { AddLine(new Line(new ArithmeticInstruction { ArithmeticOperator = op, Left = destination, Right = source, Destination = alternate ?? destination })); }
private string TranslateOperator(ArithmeticOperator op) { switch (op) { case ArithmeticOperator.ADDITION: return("+"); case ArithmeticOperator.MULTIPLICATION: return("*"); default: return(string.Empty); } }
public UnaryArithmeticExpressionImpl(SQLVendorImpl vendor, ArithmeticOperator op, NonBooleanExpression expression) : base(vendor, op) { ArgumentValidator.ValidateNotNull(nameof(expression), expression); if (ArithmeticOperator.Minus != op || ArithmeticOperator.Plus != op) { throw new ArgumentException("Unary arithmetic expression operator must be either plus or minus."); } this._expr = expression; }
public ArithmeticExpression(ArithmeticExpression _LeftOperandExpression, ArithmeticOperator _Operator, ArithmeticTerm _RightOperandTerm) { if (_Operator != ArithmeticOperator.PLUS && _Operator != ArithmeticOperator.MINUS) { throw new InvalidOperationException(); } LeftOperandExpression = _LeftOperandExpression; Operator = _Operator; RightOperandTerm = _RightOperandTerm; }
public ArithmeticTerm(ArithmeticTerm _LeftOperandTerm, ArithmeticOperator _Operator, IExpression <Value> _RightOperandFactor) { if (_Operator != ArithmeticOperator.MULTIPLY && _Operator != ArithmeticOperator.DIVIDE) { throw new InvalidOperationException(); } LeftOperandTerm = _LeftOperandTerm; Operator = _Operator; RightOperandFactor = _RightOperandFactor; }
public ArithmeticEvaluationStatement(EvaluationStatement left, ArithmeticOperator @operator, EvaluationStatement right, StatementInfo info, IStatement parentStatement = null) { CanBeEmbedded = false; Left = left; Operator = @operator; Right = right; Info = info; ParentStatement = parentStatement; TraversableChildren = StatementHelpers.CreateChildren(left, @operator, right); }
protected override void setJSON(JObject obj, BaseClassIfc host, SetJsonOptions options) { base.setJSON(obj, host, options); setAttribute(obj, "Name", Name); setAttribute(obj, "Description", Description); if (mAppliedValue != null) { IfcValue value = mAppliedValue as IfcValue; if (value != null) { obj["AppliedValue"] = DatabaseIfc.extract(value); } else { obj["AppliedValue"] = mAppliedValue.getJson(this, options); } } if (mUnitBasis > 0) { obj["UnitBasis"] = UnitBasis.getJson(this, options); } //todo setAttribute(obj, "Category", Category); setAttribute(obj, "Condition", Condition); if (mArithmeticOperator != IfcArithmeticOperatorEnum.NONE) { obj["ArithmeticOperator"] = ArithmeticOperator.ToString(); } if (mComponents.Count > 0) { obj["Components"] = new JArray(Components.ToList().ConvertAll(x => x.getJson(this, options))); } if (mHasExternalReference.Count > 0) { obj["HasExternalReference"] = new JArray(HasExternalReference.ToList().ConvertAll(x => x.getJson(this, options))); } if (mHasConstraintRelationships.Count > 0) { JArray array = new JArray(); foreach (IfcResourceConstraintRelationship r in HasConstraintRelationships) { if (r.mIndex != host.mIndex) { array.Add(r.getJson(this, options)); } } if (array.Count > 0) { obj["HasConstraintRelationships"] = array; } } }
protected override void GenerateOperator(BinaryExpression node, TypeExpression result) { ArithmeticOperator arithmeticOperator = ((ArithmeticExpression)node).Operator; bool isConcat = false; switch (arithmeticOperator) { case ArithmeticOperator.Minus: this.codeGenerator.sub(this.indent); break; case ArithmeticOperator.Plus: if (TypeExpression.Is <StringType>(result)) { isConcat = true; this.codeGenerator.concat(this.indent); } else { this.codeGenerator.add(this.indent); } break; case ArithmeticOperator.Mult: this.codeGenerator.mul(this.indent); break; case ArithmeticOperator.Div: this.codeGenerator.div(this.indent); break; case ArithmeticOperator.Mod: this.codeGenerator.rem(this.indent); break; default: // Error this.codeGenerator.Comment("ERROR"); break; } if (!isConcat && !IsValueType(node.ExpressionType) && !(node.ExpressionType is StringType)) { this.codeGenerator.Box(indent, result); } if (!string.IsNullOrEmpty(label_result)) { this.codeGenerator.stloc(this.indent, label_result); } if (result == null) { codeGenerator.WriteThrowNonSuitableObjectException(indent, StringType.Instance.FullName, arithmeticOperator.ToString()); } }
private IExpression ParseUnaryExpression() { if (this.TryParse(TokenType.Operator, "+", "-", "!")) { Token oper = this.lexer.NextToken(); IExpression unaryExpression = this.ParseUnaryExpression(); if (oper.Value == "!") { return(new NotExpression(unaryExpression)); } ArithmeticOperator op = oper.Value == "+" ? ArithmeticOperator.Plus : ArithmeticOperator.Minus; return(new ArithmeticUnaryExpression(op, unaryExpression)); } if (this.TryParse(TokenType.Operator, "++", "--")) { Token oper = this.lexer.NextToken(); IExpression expression = this.ParseTermExpression(); IncrementOperator op = oper.Value == "++" ? IncrementOperator.PreIncrement : IncrementOperator.PreDecrement; return(new IncrementExpression(expression, op)); } if (this.TryParse(TokenType.Operator, "<-", "@")) { this.lexer.NextToken(); IExpression expression = this.ParseTermExpression(); return(new GetValueExpression(expression)); } IExpression termexpr = this.ParseTermExpression(); if (this.TryParse(TokenType.Operator, "++", "--")) { Token oper = this.lexer.NextToken(); IncrementOperator op = oper.Value == "++" ? IncrementOperator.PostIncrement : IncrementOperator.PostDecrement; return(new IncrementExpression(termexpr, op)); } return(termexpr); }
string GetOperator(ArithmeticOperator op) { switch (op) { case ArithmeticOperator.Addition: return "+"; case ArithmeticOperator.Subtraction: return "-"; case ArithmeticOperator.Division: case ArithmeticOperator.IntegerDivision: return "/"; case ArithmeticOperator.Modulo: return "%"; case ArithmeticOperator.Multiplication: return "*"; } throw new ArgumentOutOfRangeException("Unsupported operator"); }
private IExpression ParseUnaryExpression() { if (this.TryParse(TokenType.Operator, "+", "-")) { Token oper = this.lexer.NextToken(); IExpression unaryExpression = this.ParseUnaryExpression(); ArithmeticOperator op = oper.Value == "+" ? ArithmeticOperator.Plus : ArithmeticOperator.Minus; return(new ArithmeticUnaryExpression(op, unaryExpression)); } return(this.ParseTermExpression()); }
public ArithmeticUnaryExpression(ArithmeticOperator operation, IExpression expression) : base(expression) { this.operation = operation; switch (operation) { case ArithmeticOperator.Minus: this.function = Operators.NegateObject; break; case ArithmeticOperator.Plus: this.function = Operators.PlusObject; break; default: throw new ArgumentException("Invalid operator"); } }
public override string GetStepParameters() { var parameters = new List <string>(); parameters.Add(Name != null ? Name.ToStepValue() : "$"); parameters.Add(Description != null ? Description.ToStepValue() : "$"); parameters.Add(AppliedValue != null ? AppliedValue.ToStepValue() : "$"); parameters.Add(UnitBasis != null ? UnitBasis.ToStepValue() : "$"); parameters.Add(ApplicableDate != null ? ApplicableDate.ToStepValue() : "$"); parameters.Add(FixedUntilDate != null ? FixedUntilDate.ToStepValue() : "$"); parameters.Add(Category != null ? Category.ToStepValue() : "$"); parameters.Add(Condition != null ? Condition.ToStepValue() : "$"); parameters.Add(ArithmeticOperator.ToStepValue()); parameters.Add(Components != null ? Components.ToStepValue() : "$"); return(string.Join(", ", parameters.ToArray())); }
public static double Evaluate(this double lhs, double rhs, ArithmeticOperator op) { switch (op) { case ArithmeticOperator.Addition: return(lhs + rhs); case ArithmeticOperator.Subtraction: return(lhs - rhs); case ArithmeticOperator.Multiplication: return(lhs * rhs); case ArithmeticOperator.Division: return(lhs / rhs); case ArithmeticOperator.IntegerDivision: return(Math.Floor(lhs / rhs)); case ArithmeticOperator.Modulo: return((int)lhs % (int)rhs); } throw new LocalizedInvalidOperationException(); }
public string Generate(ArithmeticOperator @operator) { switch (@operator) { case ArithmeticOperator.Addition: return("+"); case ArithmeticOperator.Division: return("/"); case ArithmeticOperator.Multiplication: return("*"); case ArithmeticOperator.Subtraction: return("-"); } throw new NotImplementedException(); }
public static string GetTypeName(ArithmeticOperator type) { switch (type) { case ArithmeticOperator.Plus: return("+"); case ArithmeticOperator.Minus: return("-"); case ArithmeticOperator.Multiply: return("*"); case ArithmeticOperator.Divide: return("/"); default: return("?"); } }
protected string RenderOperator(ArithmeticOperator arithmeticOperator) { switch (arithmeticOperator) { case ArithmeticOperator.Minus: return(Strings.Math.Minus); case ArithmeticOperator.Plus: return(Strings.Math.Plus); case ArithmeticOperator.Times: return(Strings.Math.Times); case ArithmeticOperator.Divide: return(Strings.Math.Divide); default: throw new NotSupportedException(); } }
private void AddOperator(ArithmeticOperator op) { if (calculation.IsEvaluable) { ResultDisplay.Text = "Only one arithmetic operation per calculation is allowed."; printOperator = false; } else if (!string.IsNullOrEmpty(number)) { calculation.FirstNumber = double.Parse(number); number = string.Empty; calculation.Operator = op; printOperator = true; } else { MessageDisplay.Text = "Please enter a number."; } }
private IExpression ParseBinaryExpressionSecondLevel() { IExpression expression = this.ParseUnaryExpression(); if (expression == null) { return(null); } while (this.TryParse(TokenType.Operator, "*", "/", @"\")) { Token oper = this.lexer.NextToken(); IExpression right = this.ParseUnaryExpression(); ArithmeticOperator op = oper.Value == "*" ? ArithmeticOperator.Multiply : (oper.Value == "/" ? ArithmeticOperator.Divide : ArithmeticOperator.IntegerDivide); expression = new ArithmeticBinaryExpression(op, expression, right); } return(expression); }
private IExpression ParseBinaryExpressionFirstLevel() { IExpression expression = this.ParseBinaryExpressionSecondLevel(); if (expression == null) { return(null); } while (this.TryParse(TokenType.Operator, "+", "-")) { Token oper = this.lexer.NextToken(); IExpression right = this.ParseBinaryExpressionSecondLevel(); ArithmeticOperator op = oper.Value == "+" ? ArithmeticOperator.Add : ArithmeticOperator.Subtract; expression = new ArithmeticBinaryExpression(op, expression, right); } return(expression); }
/// <summary> /// Create an arithmetic expression /// </summary> /// <param name="op"></param> /// <param name="index"></param> /// <param name="prevOperator"></param> /// <param name="prevOperand"></param> /// <param name="errMsg"></param> /// <returns></returns> public static ArithmeticExpression <ICalculator> CreateArithmeticExpression(char op, int index, ref bool prevOperator, ref bool prevOperand, ref string errMsg) { ArithmeticExpression <ICalculator> curExpression = null; if (op == '+' || op == '-') { if (prevOperator) { errMsg += $"Operand is missing before character: {op} [index={index}]."; return(null); } curExpression = new AddSubtractExpression <ICalculator>(); if (!prevOperand) { curExpression.Operands.Add(new ArithmeticOperand <ICalculator> { SimpleValue = new IntCalculator { Value = 0 } }); } } else if (op == '*' || op == '/') { if (prevOperator || !prevOperand) { errMsg += $"Operand is missing before character: {op} [index={index}]."; return(null); } curExpression = new MultiplyDivideExpression <ICalculator>(); } curExpression.Operators.Add(ArithmeticOperator.FromChar(op)); prevOperator = true; prevOperand = false; return(curExpression); }
private IExpression ParseFactorExpression() { IExpression expression = this.ParseSimpleExpression(); Token token = this.NextToken(); while (token != null && token.TokenType == TokenType.Operator) { if (token.Value.Equals("*") || token.Value.Equals("/")) { ArithmeticOperator oper = token.Value.Equals("*") ? ArithmeticOperator.Multiply : ArithmeticOperator.Divide; expression = new BinaryArithmeticExpression(expression, this.ParseSimpleExpression(), oper); token = this.NextToken(); continue; } break; } this.PushToken(token); return(expression); }
public IExpression ParseExpression() { IExpression expression = this.ParseFactorExpression(); Token token = this.NextToken(); while (token != null && token.TokenType == TokenType.Operator) { if (token.Value.Equals("+") || token.Value.Equals("-")) { ArithmeticOperator oper = token.Value.Equals("+") ? ArithmeticOperator.Add : ArithmeticOperator.Subtract; expression = new BinaryArithmeticExpression(expression, this.ParseFactorExpression(), oper); token = this.NextToken(); continue; } break; } this.PushToken(token); return(expression); }
private void processBIDMAS(ArithmeticOperator op) { //iterate through the operators LinkedListNode<ArithmeticOperator> currentOperator = p_Operators.First; LinkedListNode<ArithmeticOperand> currentOperand = p_Operands.First; while (currentOperator != null) { //operator we want to process? ArithmeticOperator currentOp = currentOperator.Value; if (op != currentOp) { currentOperator = currentOperator.Next; currentOperand = currentOperand.Next; continue; } //get the 2 operands for the operator ArithmeticOperand opAnd1 = currentOperand.Value; ArithmeticOperand opAnd2 = currentOperand.Next.Value; //group this operator into a scope ArithmeticQueue queue = new ArithmeticQueue(); queue.AddOperation(currentOp, opAnd1, opAnd2); //replace the operand with the queue currentOperand.Value = new ArithmeticOperand(queue); //since we have processed the second operand and //the operator, remove it LinkedListNode<ArithmeticOperator> nextOp = currentOperator.Next; p_Operands.Remove(currentOperand.Next); p_Operators.Remove(currentOperator); currentOperator = nextOp; } }
private static object EvaluateArithmeticUnaryOperator(ArithmeticOperator operation, object value) { IExpression expression = new ArithmeticUnaryExpression(operation, new ConstantExpression(value)); return expression.Evaluate(null); }
public BaseOperation getNextOperation(short _codeAdress) { this.address = _codeAdress; // mask Operation-Byte --> xxxx xxxx 0000 0000 short operation = (short)((short)programMemory[_codeAdress] & 0xFF00); // mask Parameter-Byte --> 0000 0000 xxxx xxxx short parameter = (short)((short)programMemory[_codeAdress] & 0x00FF); if (parameter < 0) throw new Exception("negative parameter"); switch (operation) { /* ------------------------------------------------------ */ /* -------- ARITHMETIC OPERATIONS ----------------------- */ case ParserConstants.ADDWF: // arithmetical operator ArithOp = ArithmeticOperator.PLUS; // target address target = getTargetAddress(parameter); // operating bytes byte1 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); byte2 = registerFileMap.Get(getAddressFromParameter(parameter)); return new ArithmeticOperation(byte1, byte2, ArithOp, target, registerFileMap, address); case ParserConstants.ADDLW_1: case ParserConstants.ADDLW_2: ArithOp = ArithmeticOperator.PLUS; target = RegisterConstants.WORKING_REGISTER_ADDRESS; byte1 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); byte2 = getLiteralFromParameter(parameter); return new ArithmeticOperation(byte1, byte2, ArithOp, target, registerFileMap, address); case ParserConstants.INCF: ArithOp = ArithmeticOperator.PLUS; target = getTargetAddress(parameter); byte1 = 0x01; byte2 = registerFileMap.Get(getAddressFromParameter(parameter)); return new ArithmeticOperation(byte1, byte2, ArithOp, target, registerFileMap, address); case ParserConstants.SUBWF: ArithOp = ArithmeticOperator.MINUS; target = getTargetAddress(parameter); byte1 = registerFileMap.Get(getAddressFromParameter(parameter)); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new ArithmeticOperation(byte1, byte2, ArithOp, target, registerFileMap, address); case ParserConstants.SUBLW_1: case ParserConstants.SUBLW_2: ArithOp = ArithmeticOperator.MINUS; target = RegisterConstants.WORKING_REGISTER_ADDRESS; byte1 = getLiteralFromParameter(parameter); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new ArithmeticOperation(byte1, byte2, ArithOp, target, registerFileMap, address); case ParserConstants.DECF: ArithOp = ArithmeticOperator.MINUS; target = getTargetAddress(parameter); byte1 = registerFileMap.Get(getAddressFromParameter(parameter)); byte2 = 0x01; return new ArithmeticOperation(byte1, byte2, ArithOp, target, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- BIT OPERATIONS ------------------------------ */ case ParserConstants.BCF_1: case ParserConstants.BCF_2: case ParserConstants.BCF_3: case ParserConstants.BCF_4: // bit operator BitOp = BitOperator.BITCLEAR; // target address target = getAddressFromParameter(parameter); // bit-number bit = getBitNumberFromOperationCall(operation, parameter); return new BitOperation(target, bit, BitOp, registerFileMap, address); case ParserConstants.BSF_1: case ParserConstants.BSF_2: case ParserConstants.BSF_3: case ParserConstants.BSF_4: BitOp = BitOperator.BITSET; target = getAddressFromParameter(parameter); bit = getBitNumberFromOperationCall(operation, parameter); return new BitOperation(target, bit, BitOp, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- CALL OPERATIONS ----------------------------- */ case ParserConstants.CALL_1: case ParserConstants.CALL_2: case ParserConstants.CALL_3: case ParserConstants.CALL_4: case ParserConstants.CALL_5: case ParserConstants.CALL_6: case ParserConstants.CALL_7: case ParserConstants.CALL_8: target = getTargetAddress(operation, parameter); return new CallOperation(target, operationStack, programCounter, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- GOTO OPERATION ------------------------------ */ case ParserConstants.GOTO_1: case ParserConstants.GOTO_2: case ParserConstants.GOTO_3: case ParserConstants.GOTO_4: case ParserConstants.GOTO_5: case ParserConstants.GOTO_6: case ParserConstants.GOTO_7: case ParserConstants.GOTO_8: target = getTargetAddress(operation, parameter); return new GotoOperation(target, programCounter, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- CLEAR OPERATIONS ---------------------------- */ case ParserConstants.CLRF_CLRW: target = getTargetAddress(parameter); return new ClearOperation(target, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- COMPLEMENT OPERATIONS ----------------------- */ case ParserConstants.COMF: target = getTargetAddress(parameter); if (target == RegisterConstants.WORKING_REGISTER_ADDRESS) return new ComplementOperation(getAddressFromParameter(parameter), target, registerFileMap, address); else return new ComplementOperation(target, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- LOGIC OPERATIONS ---------------------------- */ case ParserConstants.ANDWF: LogOp = LogicOperator.AND; target = getTargetAddress(parameter); byte1 = registerFileMap.Get(getAddressFromParameter(parameter)); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new LogicOperation(byte1, byte2, LogOp, target, registerFileMap, address); case ParserConstants.ANDLW: LogOp = LogicOperator.AND; target = RegisterConstants.WORKING_REGISTER_ADDRESS; byte1 = getLiteralFromParameter(parameter); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new LogicOperation(byte1, byte2, LogOp, target, registerFileMap, address); case ParserConstants.IORWF: LogOp = LogicOperator.IOR; target = getTargetAddress(parameter); byte1 = registerFileMap.Get(getAddressFromParameter(parameter)); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new LogicOperation(byte1, byte2, LogOp, target, registerFileMap, address); case ParserConstants.IORLW: LogOp = LogicOperator.IOR; target = RegisterConstants.WORKING_REGISTER_ADDRESS; byte1 = getLiteralFromParameter(parameter); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new LogicOperation(byte1, byte2, LogOp, target, registerFileMap, address); case ParserConstants.XORWF: LogOp = LogicOperator.XOR; target = getTargetAddress(parameter); byte1 = registerFileMap.Get(getAddressFromParameter(parameter)); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new LogicOperation(byte1, byte2, LogOp, target, registerFileMap, address); case ParserConstants.XORLW: LogOp = LogicOperator.XOR; target = RegisterConstants.WORKING_REGISTER_ADDRESS; byte1 = getLiteralFromParameter(parameter); byte2 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new LogicOperation(byte1, byte2, LogOp, target, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- MOVE OPERATIONS ----------------------------- */ case ParserConstants.MOVF: target = getTargetAddress(parameter); source = getAddressFromParameter(parameter); return new MoveOperation(source, target, registerFileMap, address); case ParserConstants.MOVLW_1: case ParserConstants.MOVLW_2: case ParserConstants.MOVLW_3: case ParserConstants.MOVLW_4: byte1 = getLiteralFromParameter(parameter); target = RegisterConstants.WORKING_REGISTER_ADDRESS; return new MoveOperation(byte1, target, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- ROTATE OPERATIONS --------------------------- */ case ParserConstants.RLF: RotDir = RotationDirection.LEFT; target = getTargetAddress(parameter); source = getAddressFromParameter(parameter); return new RotateOperation(source, target, RotDir, registerFileMap, address); case ParserConstants.RRF: RotDir = RotationDirection.RIGHT; target = getTargetAddress(parameter); source = getAddressFromParameter(parameter); return new RotateOperation(source, target, RotDir, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- SWAP OPERATIONS ----------------------------- */ case ParserConstants.SWAPF: target = getTargetAddress(parameter); source = getAddressFromParameter(parameter); return new SwapOperation(source, target, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- BIT TEST OPERATIONS ----------------------------- */ case ParserConstants.DECFSZ: TestOp = TestOperator.DECFSZ; target = getTargetAddress(parameter); source = getAddressFromParameter(parameter); return new TestOperation(source, TestOp, target, programCounter, registerFileMap, address); case ParserConstants.INCFSZ: TestOp = TestOperator.INCFSZ; target = getTargetAddress(parameter); source = getAddressFromParameter(parameter); return new TestOperation(source, TestOp, target, programCounter, registerFileMap, address); case ParserConstants.BTFSC_1: case ParserConstants.BTFSC_2: case ParserConstants.BTFSC_3: case ParserConstants.BTFSC_4: BitTestOp = BitTestOperator.BTFSC; source = getAddressFromParameter(parameter); bit = getBitNumberFromOperationCall(operation, parameter); return new BitTestOperation(source, bit, BitTestOp, programCounter, registerFileMap, address); case ParserConstants.BTFSS_1: case ParserConstants.BTFSS_2: case ParserConstants.BTFSS_3: case ParserConstants.BTFSS_4: BitTestOp = BitTestOperator.BTFSS; source = getAddressFromParameter(parameter); bit = getBitNumberFromOperationCall(operation, parameter); return new BitTestOperation(source, bit, BitTestOp, programCounter, registerFileMap, address); /* ------------------------------------------------------ */ /* ------------------------------------------------------ */ /* -------- RETURN OPERATIONS --------------------------- */ case ParserConstants.RETLW_1: case ParserConstants.RETLW_2: case ParserConstants.RETLW_3: case ParserConstants.RETLW_4: RetOp = ReturnOperator.RETLW; byte1 = getLiteralFromParameter(parameter); return new ReturnOperation(programCounter, operationStack, RetOp, byte1, registerFileMap, address); /* ------------------------------------------------------ */ case 0x0000: if(parameter > 127) { // MOVWF target = getAddressFromParameter(parameter); byte1 = registerFileMap.Get(RegisterConstants.WORKING_REGISTER_ADDRESS); return new MoveOperation(byte1, target, registerFileMap, address); } switch (parameter) { case ParserConstants.CLRWDT: return new ClearWdtOperation(pic, registerFileMap, address); case ParserConstants.RETFIE: RetOp = ReturnOperator.RETFIE; return new ReturnOperation(programCounter, operationStack, RetOp, registerFileMap, address); case ParserConstants.RETURN: RetOp = ReturnOperator.RETURN; return new ReturnOperation(programCounter, operationStack, RetOp, registerFileMap, address); case ParserConstants.SLEEP: return new SleepOperation(pic, registerFileMap, address); case ParserConstants.NOP_1: case ParserConstants.NOP_2: case ParserConstants.NOP_3: case ParserConstants.NOP_4: return new NopOperation(registerFileMap, address); default: break; } break; default: throw new Exception("unknown operation"); } throw new Exception("unknown error"); }
public SQLArithmeticExpression(string strLeftFieldName, ArithmeticOperator eOperator, object objRightValue) : this(new SQLFieldExpression(strLeftFieldName), eOperator, new SQLValueExpression(objRightValue)) { }
public ArithmeticCondition(NumericCondition c1, ArithmeticOperator op, NumericCondition c2) { this.c1 = c1; this.c2 = c2; this.op = op; }
public SQLArithmeticExpression(string strLeftFieldName, ArithmeticOperator eOperator, SQLExpression objRightExpression) : this(new SQLFieldExpression(strLeftFieldName), eOperator, objRightExpression) { }
public ArithmeticOperationExpr (ExprSingle left, ExprSingle right, ArithmeticOperator oper) : base (left, right) { this.oper = oper; }
public ArithmeticQueue AddOperation(ArithmeticOperator op, ArithmeticOperand opAnd1, ArithmeticOperand opAnd2) { //there must be no operators/operands present since it would otherwise //create an invalid calculation queue if (p_Operands.Count != 0) { throw new Exception("This call must be used only when there are no operands to chain off. Consider AddOperation(op,operand)"); } //operand larger than the result size? if so, set the result size to that of the operand sbyte opAnd1Size = 0; sbyte opAnd2Size = 0; if (opAnd1.IsNumeric) { if (opAnd1.IsDecimal) { p_HasDecimal = true; } opAnd1Size = ArithmeticNumeric.SizeOfNumericObj(opAnd1.Value); } if (opAnd2.IsNumeric) { if (opAnd2.IsDecimal) { p_HasDecimal = true; } opAnd2Size = ArithmeticNumeric.SizeOfNumericObj(opAnd2.Value); } if (opAnd1Size > p_ResultSize) { p_ResultSize = opAnd1Size; } if (opAnd2Size > p_ResultSize) { p_ResultSize = opAnd2Size; } //add it p_Operators.AddLast(op); p_Operands.AddLast(opAnd1); p_Operands.AddLast(opAnd2); p_BIDMASSorted = false; //division? if (op == ArithmeticOperator.Divide) { HasDecimal = true; } return this; }
public ArithmeticQueue AddOperation(ArithmeticOperator op, ArithmeticOperand operand) { //valid call? (there must be operands already) otherwise this call would //make the arithmatic queue invalid. if (p_Operands.Count == 0) { throw new Exception("Cannot add on to chain when there is no operands to chain off. Consider using AddOperation(op,opAnd1,opAnd2)."); } //operand larger than the result size? if so, set the result size to that of the operand sbyte operandSize = 0; if (operand.IsNumeric) { if (operand.IsDecimal) { p_HasDecimal = true; } operandSize = ArithmeticNumeric.SizeOfNumericObj(operand.Value); } if (operandSize > p_ResultSize) { p_ResultSize = operandSize; } //add it p_Operators.AddLast(op); p_Operands.AddLast(operand); p_BIDMASSorted = false; //division if (op == ArithmeticOperator.Divide) { HasDecimal = true; } return this; }
private void performCalc(ref ArithmeticNumeric current, ArithmeticOperator op, ArithmeticOperand opAnd) { //get the operand as decimal ArithmeticNumeric opAndDecimal = getOperandValue(opAnd); //perform the calculation switch (op) { case ArithmeticOperator.Addition: current += opAndDecimal; break; case ArithmeticOperator.Subtract: current -= opAndDecimal; break; case ArithmeticOperator.Multiply: current *= opAndDecimal; break; case ArithmeticOperator.Divide: current /= opAndDecimal; break; case ArithmeticOperator.Modulus: current %= opAndDecimal; break; case ArithmeticOperator.Power: current = Math.Pow( Convert.ToDouble(current.RAWObject), Convert.ToDouble(opAndDecimal.RAWObject)); break; } }
private static object EvaluateArithmeticBinaryOperator(ArithmeticOperator operation, object left, object right) { IExpression expression = new ArithmeticBinaryExpression(operation, new ConstantExpression(left), new ConstantExpression(right)); return expression.Evaluate(null); }
public SQLArithmeticExpression(SQLExpression objLeftExpression, ArithmeticOperator eOperator, SQLExpression objRightExpression) { pobjLeft = objLeftExpression; peOperator = eOperator; pobjRight = objRightExpression; }
private void CheckArithmeticOperands(ArithmeticOperator @operator) { // Pop the operand types from the stack. var right = this.operands.Pop(); var left = this.operands.Pop(); // Enumerate all the possible combinations. switch (left) { case VESType.Int32: if (right != VESType.Int32 && right != VESType.NativeInt && (right != VESType.ManagedPointer || @operator != ArithmeticOperator.Add)) throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); PushStackOperand(right); break; case VESType.Int64: if (right != VESType.Int64) throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); PushStackOperand(VESType.Int64); break; case VESType.NativeInt: if (right != VESType.Int32 && right != VESType.NativeInt && (right != VESType.ManagedPointer || @operator != ArithmeticOperator.Add)) throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); PushStackOperand(right == VESType.ManagedPointer ? VESType.ManagedPointer : VESType.NativeInt); break; case VESType.Float: if (right != VESType.Float) throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); PushStackOperand(VESType.Float); break; case VESType.ManagedPointer: if (@operator == ArithmeticOperator.Add) { if (right != VESType.Int32 && right != VESType.NativeInt) throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); } else if (@operator == ArithmeticOperator.Subtract) { if (right != VESType.Int32 && right != VESType.NativeInt && right != VESType.ManagedPointer) throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); } else throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); PushStackOperand(right == VESType.ManagedPointer ? VESType.NativeInt : VESType.ManagedPointer); break; case VESType.Object: throw new InvalidOperationException(string.Format("Invalid stack operand(s) ({0} {1} {2}).", @operator, left, right)); } }
public static ArithmeticExpression CreateArithmetic(ArithmeticOperator @operator, double left, double right) { return new ArithmeticExpression(@operator, new NumericExpression(left), new NumericExpression(right)); }