public override void VisitAssignmentOperationElement(AssignmentOperationElement element) { VisitElement(element.getLhs()); Console.Write(":= "); VisitElement(element.getRhs()); Console.WriteLine(";"); }
public override void VisitAssignmentOperationElement(AssignmentOperationElement element) { String variable_name = element.getLhs().getText(); Element rhs = element.getRhs(); VisitElement(rhs); int result = mStack.Pop(); mVariableMap[variable_name] = result; }
//----< visit Assignment Operation >------------------------------ public override void VisitAssignmentOperationElement(AssignmentOperationElement element) { String variable_name = element.getLhs().getText(); Element rhs = element.getRhs(); VisitElement(rhs); if (rhs is MatrixElement) { MatrixElement result = mStack.Pop(); mVariableMap[variable_name] = result; } if (rhs is IntegerElement) { IntegerElement result = mIntStack.Pop(); mIntVariableMap[variable_name] = result; } if (rhs is MatrixAdditionOperationElement) { MatrixAdditionOperationElement maoe = (MatrixAdditionOperationElement)rhs; if (maoe.getLhs() is IntegerElement) { IntegerElement result = mIntStack.Pop(); mIntVariableMap[variable_name] = result; } if (maoe.getLhs() is MatrixElement) { MatrixElement result = mStack.Pop(); mVariableMap[variable_name] = result; } if (maoe.getLhs() is VariableElement) { MatrixElement result = mStack.Pop(); mVariableMap[variable_name] = result; } } if (rhs is MatrixMultiplicationOperationElement) { MatrixMultiplicationOperationElement mmoe = (MatrixMultiplicationOperationElement)rhs; { MatrixElement result = mStack.Pop(); mVariableMap[variable_name] = result; } } }
//-----------<Test Stub>-------- static void main(string[] args) { Console.WriteLine("\nTesting the AssignmentOperationElement class"); Console.WriteLine("\n==========================================\n"); AssignmentOperationElement elem_assign = new AssignmentOperationElement(); IntegerElement int_elem = new IntegerElement(); VariableElement var_elem = new VariableElement(); string lhsval = "a"; string rhsval = "3"; VariableElement lhs = var_elem; Element rhs = int_elem; int_elem.setText(rhsval); var_elem.setText(lhsval); elem_assign.setLhs(lhs); elem_assign.setRhs(rhs); var_elem=elem_assign.getLhs(); int_elem = (IntegerElement)elem_assign.getRhs(); Console.WriteLine("{0} The element at Lhs is:", int_elem.getText()); Console.WriteLine("{0} The element at the rhs is:", var_elem.getText()); }
private void HandleSingleVectorElement(AssignmentOperationElement element) { if (inParallelFor == 1) { ParallelVectorElement(element); if (parallelVars.Contains(((VectorElement)element.getLhs()).getVar().getText())) { } else { vectorData(((VectorElement)element.getLhs()).getVar().getText()); } } else { VectorElement temp = (VectorElement)(element.getLhs()); VectorVariableDeclaration matTemp = null; if (temp != null) { int mflag = -1; if (mVariableMap.ContainsKey(temp.getVar().getText())) { matTemp = (VectorVariableDeclaration)mVariableMap[temp.getVar().getText()]; mflag = 1;//Matrix entry found } else sendres(112, "Vector not declared yet\n"); int index = getIndex(temp); Element rhs = element.getRhs(); VisitElement(rhs); if (matTemp != null) { if (mat_stack.Count > 0 && mflag == 1 && matTemp.getType() == "int") { Object obj = getTopOfStack_Matrix(); int val = int.Parse(((IntegerElement)(obj)).getText()); if (index < int.Parse(matTemp.getRange().getText())) matTemp.setintValueat(index, val); else { Console.Write("Range out of bound\n"); sendres(112, "Range out of bound\n"); } } else if (mat_stack.Count > 0 && mflag == 1 && matTemp.getType() == "double") { Object obj = getTopOfStack_Matrix(); double val = double.Parse(((DoubleElement)(obj)).getText()); matTemp.setdoubleValueat(index, val); } } } } }
//Set the single matrix element public void HandleSingleMatrixElement(AssignmentOperationElement element) { if (inParallelFor == 1) { ParallelMatrixElement(element); if(parallelVars.Contains(((MatrixElement)element.getLhs()).getVar().getText())) { } else { matrixData(((MatrixElement)element.getLhs()).getVar().getText()); } } else { MatrixElement temp = (MatrixElement)(element.getLhs()); MatrixVariableDeclaration matTemp = null; if (temp != null) { int mflag = -1; if (mVariableMap.ContainsKey(temp.getVar().getText())) { matTemp = (MatrixVariableDeclaration)mVariableMap[temp.getVar().getText()]; mflag = 1;//Matrix entry found } else sendres(112, "Matrix not declared yet\n"); int row = getMatrixRow(temp); int col = getMatrixCol(temp); //int col = int.Parse(((IntegerElement)(temp.getColumn())).getText()); Element rhs = element.getRhs(); VisitElement(rhs); if (matTemp != null) { if (mat_stack.Count > 0 && mflag == 1 && matTemp.getType() == "int") { Object obj = getTopOfStack_Matrix(); int val = int.Parse(((IntegerElement)(obj)).getText()); if (row < int.Parse(matTemp.getRow().getText()) && col < int.Parse(matTemp.getColumn().getText())) matTemp.setintValueat(row, col, val); else { Console.Write("Range out of bound\n"); sendres(112, "Range out of bound\n"); } if (parallelSwarm == 1) writeIntResult(((MatrixElement)element.getLhs()).getVar().getText(), row, col, val); } else if (mat_stack.Count > 0 && mflag == 1 && matTemp.getType() == "double") { Object obj = getTopOfStack_Matrix(); double val = double.Parse(((DoubleElement)(obj)).getText()); matTemp.setdoubleValueat(row, col, val); //if (parallelSwarm == 1) //writeDoubleResult(((MatrixElement)element.getLhs()).getVar().getText(), row, col, val); } } } } }
private void ParallelVectorElement(AssignmentOperationElement element) { VectorElement temp = (VectorElement)(element.getLhs()); parallelString.Append(temp.getVar().getText()); parallelString.Append("["); if (temp.getRange() is VariableElement) parallelString.Append(((VariableElement)temp.getRange()).getText()); else if (temp.getRange() is IntegerElement) parallelString.Append(((IntegerElement)temp.getRange()).getText()); parallelString.Append("]"); parallelString.Append("="); VisitElement(element.getRhs()); }
public override void VisitAssignmentOperationElement(AssignmentOperationElement element) { StructAssignDeclaration temp; StructDeclaration structTemp = null; int flag = -1; //Handle struct if (GetTypeOfElement(element.getLhs()) == 4) { temp = (StructAssignDeclaration)(element.getLhs()); if (mVariableMap.ContainsKey(((VariableElement)(temp.getObjName())).getText())) //getName())) { structTemp = (StructDeclaration)mVariableMap[((VariableElement)(temp.getObjName())).getText()]; //.getName()]; flag = 1; } else sendres(112, "Structure " + ((VariableElement)(temp.getObjName())).getText() + " not found\n"); Element rhs = element.getRhs(); VisitElement(rhs); if (mat_stack.Count > 0 && flag == 1) { Object obj = getTopOfStack_Matrix(); List<ScalarVariableDeclaration> l1 = structTemp.getVarType(); for (int i = 0; i < l1.Count; i++) if (l1[i].getVar().getText() == ((VariableElement)temp.getDataMember()).getText()) { if (obj is IntegerElement) result("Struct member set:" + ((IntegerElement)obj).getText()); else if (obj is DoubleElement) result("Struct member set:" + ((DoubleElement)obj).getText()); if (obj is StringElement) result("Struct member set:" + ((StringElement)obj).getText()); } //temp.setObjName((Element)(obj)); //.setObj((Element)(obj)); } } else if (GetTypeOfElement(element.getLhs()) == 5) { HandleSingleMatrixElement(element); } else if (GetTypeOfElement(element.getLhs()) == 15) HandleSingleVectorElement(element); else if (mVariableMap.ContainsKey(((VariableElement)(element.getLhs())).getText())) { if (inParallelFor == 1) { parallelString.Append((((VariableElement)(element.getLhs())).getText())); parallelString.Append("="); VisitElement(element.getRhs()); if (mVariableMap[(((VariableElement)(element.getLhs())).getText())] is MatrixVariableDeclaration) matrixData((((VariableElement)(element.getLhs())).getText())); else if (mVariableMap[(((VariableElement)(element.getLhs())).getText())] is IntegerElement) varData((((VariableElement)(element.getLhs())).getText())); else if (mVariableMap[(((VariableElement)(element.getLhs())).getText())] is DoubleElement) varData((((VariableElement)(element.getLhs())).getText())); } else { string var_name = ((VariableElement)(element.getLhs())).getText(); Element rhs = element.getRhs(); VisitElement(rhs); if (mat_stack.Count > 0 && flag == -1) { Object obj = getTopOfStack_Matrix(); if (GetTypeOfElement(element.getLhs()) == GetTypeOfElement(((Element)obj))) { /*if ((GetTypeOfElement(element.getLhs()) == 3)) { MatrixVariableDeclaration tempmat = ((MatrixVariableDeclaration)((mVariableMap[((VariableElement)(element.getLhs())).getText()]))); if (tempmat.getType() == (((MatrixVariableDeclaration)(((Element)obj))).getType())) { if (tempmat.getRow() == (((MatrixVariableDeclaration)(((Element)obj))).getRow()) && tempmat.getColumn() == (((MatrixVariableDeclaration)(((Element)obj))).getColumn())) { mVariableMap.Remove(var_name); mVariableMap.Add(var_name, obj); } else Console.Write("Rows and columns of matrices do not match\n"); } else Console.Write("Matrices are of different types\n"); } else {*/ mVariableMap.Remove(var_name); mVariableMap.Add(var_name, obj); //} } else { Console.Write("Datatypes mismatch\n"); sendres(112, "Datatypes mismatch\n"); } } else { Console.Write("Variable not found"); sendres(112, "Variable not found"); } } } else { Console.Write("Variable not declared"); sendres(112, "Variable not declared"); } }
public override void VisitAssignmentOperationElement(AssignmentOperationElement element){ String variable_name = element.getLhs().getText(); Element rhs = element.getRhs(); VisitElement(rhs); List<int> inputlist = new List<int>(); if (mStack.Count != 0) { int result = mStack.Pop(); inputlist.Add(result); mVariableMap[variable_name] = inputlist; } else { for (int i = 0; i < mList.Count; i++) { inputlist.Add(mList[i]); } mVariableMap[variable_name] = inputlist; //if (mList.Count != 0) //{ // mList.Clear(); //} } }