/// <summary> /// This method calculates the result of all the operands in the OperandList /// </summary> /// <param name="text1"></param> /// <param name="text2"></param> private void _calculate(double operand, string operatorString) { OperandList.Add(operand); if (OperandList.Count > 1) { switch (operatorString) { case "+": this.Result = this.OperandList[0] + this.OperandList[1]; break; case "-": this.Result = this.OperandList[0] - this.OperandList[1]; break; case "x": this.Result = this.OperandList[0] * this.OperandList[1]; break; case "÷": this.Result = this.OperandList[0] / this.OperandList[1]; break; } this.OperandList.Clear(); this.OperandList.Add(this.Result); this.IsOperandTwo = false; } this.CurrentOperator = operatorString; }
public MachineCode AssembleFromOperands([NotNull] OperandList operands) => new MachineCodeBuilder() .Opcode(builder.opcode_delegate(operands)) .Function(builder.function_delegate(operands)) .R1(builder.r1_delegate(operands)) .R2(builder.r2_delegate(operands)) .Immediate(builder.immediate_delegate(operands)) .Build();
// Constructors /////////////////////////////////////////////////////// /// <summary> /// Construct from format and operand list. /// </summary> /// <exception cref="ArgumentException"> /// If the format of the operands given is different from /// </exception> public SourceInstruction([NotNull] InstructionFormat format, [NotNull] OperandList operands) { if (!format.OperandFormat.Equals(operands.Format)) { throw new ArgumentException("Operand formats do not match."); } Format = format; Operands = operands; }
/// <summary> /// This method sets operand1 as the first operand of the operation /// </summary> private void _calculate(double operand, string operatorString) { if (OperandList.Count > 1) { double result = 0; if (operatorString == "=") { operatorString = this.CurrentOperator; } Debug.WriteLine("Current Operator: " + CurrentOperator); switch (operatorString) { case "+": result = OperandList[0] + OperandList[1]; break; case "-": result = OperandList[0] - OperandList[1]; break; case "x": result = OperandList[0] * OperandList[1]; break; case "÷": result = OperandList[0] / OperandList[1]; break; case "±": result = operand * -1; break; } OperandList.Clear(); this.OperandList.Add(result); this.Result = result; } else { this.OperandList.Add(operand); } }
// Functions ////////////////////////////////////////////////////////// /// <summary> /// Assemble this instruction with the given operands. /// </summary> /// <exception cref="ArgumentException"> /// If the format of the operands given is different to the format expected. /// </exception> public MachineCode AssembleWithOperands(OperandList operands) { if (operands.Format.Equals(Format.OperandFormat)) { return(field_mapping.AssembleFromOperands(operands)); } else { throw new ArgumentException("The given operands are not in the expected format."); } }
/// <summary> /// This method displays the result in the ResultTextBox /// </summary> /// <returns></returns> private void _showResult(double operand) { Debug.WriteLine("OperandList Count: " + OperandList.Count); if (OperandList.Count > 0) { OperandList.Add(operand); this._calculate(operand, "="); } ResultTextBox.Text = this.Result.ToString(); }
private OperandList TokenizeOperands([CanBeNull] Group match_group) { if ((match_group == null) || !match_group.Success) { return(OperandList.CreateEmpty()); } var operands = match_group .Captures.Cast <Capture>() .Select(cap => cap.Value) // Get string token. .Select(val => val.Replace(" ", "")) // Remove all spaces. .Select(val => new OperandParser().Parse(val)) // Parse as token. .ToArray(); return(new OperandList(operands)); }
/// <summary> /// This method calculates the result of all the operands in the OperandList /// </summary> /// <param name="text1"></param> /// <param name="text2"></param> private void _calculate(double operand, string operatorString) { OperandList.Add(operand); if (OperandList.Count > 1) { switch (operatorString) { case "+": this.Result = this.OperandList[0] + this.OperandList[1]; break; case "-": this.Result = this.OperandList[0] - this.OperandList[1]; break; case "x": this.Result = this.OperandList[0] * this.OperandList[1]; break; case "÷": try { if (this.OperandList[1] != 0) { this.Result = this.OperandList[0] / this.OperandList[1]; } else { this.ResultTextBox.Text = "Can't be divisile by zero"; } } catch (Exception exception) { Debug.WriteLine(exception.Message); } break; } this.OperandList.Clear(); this.OperandList.Add(this.Result); this.IsOperandTwo = false; } this.CurrentOperator = operatorString; }
/// <summary> /// This method calculates the result of all the operands in the operator list /// </summary> /// <param name="text1"></param> /// <param name="text2"></param> private void _calculate(double operand, string operatorString) { OperandList.Add(operand); if (OperandList.Count > 1) { switch (operatorString) //Have to do multiply and divide for lab { case "+": this.Result = this.OperandList[0] + this.OperandList[1]; break; case "-": this.Result = this.OperandList[0] - this.OperandList[1]; break; } } this.CurrentOperator = operatorString; }
// Functions ////////////////////////////////////////////////////////// /// <summary> /// Assemble this instruction with the given operands. /// </summary> /// <exception cref="ArgumentException"> /// If the format of the operands given is different to the format expected. /// </exception> /// <exception cref="InvalidOperationException"> /// If the assembler delegate returns null. /// </exception> public MachineCode AssembleWithOperands(OperandList operands) { if (operands.Format.Equals(Format.OperandFormat)) { var machine_code = assembler_delegate(operands); if (machine_code == null) { throw new InvalidOperationException("The assembler delegate returned null."); } else { return(machine_code); } } else { throw new ArgumentException("The given operands are not in the expected format."); } }
/// <summary> /// This method calculates the result of all the operands in the OperandList /// </summary> /// <param name="text1"></param> /// <param name="text2"></param> private void _calculate(double operand, string operatorString) { OperandList.Add(operand); if (OperandList.Count > 1) { switch (operatorString) { case "+": this.Result = this.OperandList[0] + this.OperandList[1]; break; case "-": this.Result = this.OperandList[0] - this.OperandList[1]; break; case "x": this.Result = this.OperandList[0] * this.OperandList[1]; break; case "÷": if (this.OperandList[1] != 0) { this.Result = this.OperandList[0] / this.OperandList[1]; } else { this.ResultTextBox.Text = "Cannot by divide by zero"; } break; } this.OperandList.Clear(); this.OperandList.Add(this.Result); this.IsOperandTwo = false; } this.CurrentOperator = operatorString; }
/// <summary> /// Construct from mnemonic and operand list. /// </summary> public SourceInstruction([NotNull] string mnemonic, [NotNull] OperandList operands) : this(new InstructionFormat(mnemonic, operands.Format), operands) { }