Beispiel #1
0
 public override void VisitForStatementElement(ForStatementElement element)
 {
     Console.Write("for");
       VisitElement(element.RANGE);
       Console.Write("\n{\n\t");
       List<Element> code = element.CODELIST;
       for (int i = 0; i < code.Count; i++)
       {
       VisitElement(code[i]);
       if (i != (code.Count - 1))
       {
           Console.Write("\n\t");
       }
       else
       {
           Console.Write("\n");
       }
       }
       Console.Write("}\n");
 }
Beispiel #2
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");
     }
 }
Beispiel #3
0
 public abstract void VisitForStatementElement(ForStatementElement element);
Beispiel #4
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();
     }
   }
 }
Beispiel #5
0
        private void CreateForData(ForStatementElement element)
        {

        }
Beispiel #6
0
 public override void VisitForStatementElement(ForStatementElement element)
 {
     //throw new NotImplementedException();
 }