setVar() 공개 메소드

public setVar ( VariableElement, var ) : void
var VariableElement,
리턴 void
예제 #1
0
     static void Main(String[] args)
 {
     Console.WriteLine("\nTesting the IfStatementElement class");
     Console.WriteLine("\n==========================================\n");
     EqualityOperationElement elem = new EqualityOperationElement();
     VariableElement var_elem = new VariableElement();
     var_elem.setText("a");
     elem.setequalityLhs(var_elem);
     IntegerElement int_elem = new IntegerElement();
     int_elem.setText("1");
     elem.setequalityRhs(int_elem);
     VariableElement elem2 = new VariableElement();
     elem2.setText("b");
     IfStatementElement if_elem = new IfStatementElement();
     if_elem.CONDITION= elem;
     ScalarVariableDeclaration scalar_elem = new ScalarVariableDeclaration();
     scalar_elem.setType("int");
     scalar_elem.setVar(var_elem);
     List<Element> Iflist = new List<Element>();
     Iflist.Add(scalar_elem);
     if_elem.IFCODE = Iflist;
     List<Element> ElseList = new List<Element>();
     ElseList.Add(int_elem);
     if_elem.ELSECODE = ElseList;
     Console.Write("IfStatement element " + var_elem1.GetType().ToString()+" "+ var_elem1.getText().ToString() + "\n");
     EqualityOperationElement eq_elem = new EqualityOperationElement();
     eq_elem = (EqualityOperationElement)if_elem.CONDITION;
     Console.Write("The condition has : "+eq_elem.ToString()+"->"+eq_elem.getequalityLhs()+" == "+eq_elem.getequalityRhs()+"\n");
     List<Element> elem_list = new List<Element>();
     elem_list = if_elem.IFCODE;
     for (int i = 0; i < elem_list.Count; i++)
     {
         Console.Write("The if loop list has " + elem_list[i].ToString() + "\n");
     }
     elem_list = if_elem.ELSECODE;
     for (int i = 0; i < elem_list.Count; i++)
     {
         Console.Write("The Else loop list has " + elem_list[i].ToString() + "\n");
     }
 }
예제 #2
0
 public override void VisitForStatementElement(ForStatementElement element)
 {
     //throw new NotImplementedException();
     if (inParallelFor == 1)
     {
         parallelString.Append("for(" + element.RANGEVARIABLE.getText() + "->");
         parallelString.Append(element.STARTINGRANGE.getText() + " to " + element.ENDINGRANGE.getText() + ")");
         parallelString.Append("\n{");
         for (int i = 0; element.CODELIST.Count != 0 && i < element.CODELIST.Count; i++)
         {
             VisitElement(element.CODELIST[i]);
         }
         parallelString.Append("\n}");
         CreateForData(element);
     }
     else
     {
     try
     {
         int start = 0; int end = 0;
         if (element.RANGEVARIABLE.getText() != null && element.STARTINGRANGE.getText() != null && element.ENDINGRANGE.getText() != null)
         {
             try
             {
                 start = int.Parse(element.STARTINGRANGE.getText());
                 end = int.Parse(element.ENDINGRANGE.getText());
              }
             catch(Exception err)
             {
                 sendres(113, "The range for the for loop is not set"); err.GetType();
             }
             if (end != 0)
             {
                 if (start <= end)
                 {
                     if (!map_contains_matrix(element.RANGEVARIABLE.getText()))
                     {
                         //local++;
                         //Hashtable localTable = new Hashtable();
                         //scope.Push(localTable);
                         ScalarVariableDeclaration scalar_elem = new ScalarVariableDeclaration();
                         scalar_elem.setType("int");
                         scalar_elem.setVar(element.RANGEVARIABLE);
                         VisitElement(scalar_elem);
                         for (int i = start; i <= end; i++)
                         {
                             AssignmentOperationElement elem = new AssignmentOperationElement();
                             elem.setLhs(element.RANGEVARIABLE);
                             IntegerElement int_elem = new IntegerElement();
                             int_elem.setText(i.ToString());
                             elem.setRhs(int_elem);
                             VisitElement(elem);
                             List<Element> codeList = new List<Element>();
                             codeList = element.CODELIST;
                             for (int j = 0; j < codeList.Count; j++)
                             {
                                 VisitElement(codeList[j]);
                             }
                         }
                         //scope.Pop();
                         //local--;
                     }
                     else
                         sendres(112, "The range variable in the for loop has already been used in the program. Please use a different variable.");
                 }
                 else
                     sendres(112, "The starting index should be less than the ending index");
             }
         }
         else
             sendres(112, "The ending index of the for loop cannot be zero");
     }
     catch(Exception err)
     {
         sendres(113, "For loop cannot be executed. Please check for semantic errors"); err.GetType();
     }
   }
 }
예제 #3
0
 static void Main(String[] args)
 {
     Console.WriteLine("\nTesting the ForStatementElement class");
     Console.WriteLine("\n==========================================\n");
     RangeElement elem = new RangeElement();
     VariableElement var_elem = new VariableElement();
     var_elem.setText("a");
     elem.RANGEVARIABLE = var_elem;
     IntegerElement int_elem = new IntegerElement();
     int_elem.setText("1");
     elem.STARTINGRANGE = int_elem;
     IntegerElement int_elem2 = new IntegerElement();
     int_elem2.setText("10");
     elem.ENDINGRANGE = int_elem2;
     ForStatementElement for_elem = new ForStatementElement();
     for_elem.RANGE = elem;
     ScalarVariableDeclaration scalar_elem = new ScalarVariableDeclaration();
     scalar_elem.setType("int");
     scalar_elem.setVar(var_elem);
     for_elem.ADDCODE = scalar_elem;
     RangeElement Relem = new RangeElement();
     Relem = for_elem.RANGE;
     Console.Write("Range is "+Relem.STARTINGRANGE.getText()+" to "+ Relem.ENDINGRANGE.getText()+"\n");
     List<Element> elem_list = new List<Element>();
     elem_list = for_elem.CODELIST;
     for(int i=0; i<elem_list.Count;i++)
     {
         Console.Write("The for statement list has " + elem_list[i].ToString()+"\n");
     }
 }
예제 #4
0
 static void Main(String[] args)
 {
     Console.WriteLine("\nTesting the ParallelForStatementElement class");
     Console.WriteLine("\n==========================================\n");
     RangeElement elem = new RangeElement();
     VariableElement var_elem = new VariableElement();
     var_elem.setText("a");
     elem.RANGEVARIABLE = var_elem;
     IntegerElement int_elem = new IntegerElement();
     int_elem.setText("1");
     elem.STARTINGRANGE = int_elem;
     IntegerElement int_elem2 = new IntegerElement();
     int_elem2.setText("10");
     elem.ENDINGRANGE = int_elem2;
     ParallelForElement for_elem = new ParallelForElement();
     for_elem.RANGE = elem;
     ScalarVariableDeclaration scalar_elem = new ScalarVariableDeclaration();
     scalar_elem.setType("int");
     scalar_elem.setVar(var_elem);
     for_elem.ADDCODE = scalar_elem;
     for_elem.syncfunction();
     VariableElement elem2 = new VariableElement();
     elem2.setText("b");
     for_elem.ADDCODE = elem2;
     for_elem.syncfunction();
     RangeElement Relem = new RangeElement();
     Relem = for_elem.RANGE;
     Console.Write("Range is " + Relem.STARTINGRANGE.getText() + " to " + Relem.ENDINGRANGE.getText() + "\n");
     List<List<Element>> elem_list = new List<List<Element>>();
     elem_list = for_elem.PARALLELCODE;
     for(int i=0; i<elem_list.Count;i++)
     {
         List<Element> code = new List<Element>();
         code = elem_list[i];
         for (int j = 0; j<code.Count; j++)
         {
             Console.Write("The parallelfor statement code list "+ (i+1) +" has "+ code[j].ToString() + "\n");
         }
     }
 }