示例#1
0
 private void param_decl_list(CommonTree tr) {
   if (tr.getChildren() == null) return;
   currentFunc.pNum = tr.getChildren().size() / 2;
   for (int i = 0; tr.getChildren() != null && i < tr.getChildren().size(); i += 2) {
     // Child_i stores Type, Child_i+1 stores Id
     Symbol sym = new Symbol(getChToken(tr, i + 1), getChToken(tr, i));
     sym.irname = "$P" + Integer.toString(i / 2 + 1);
     // System.out.println("Param: ID:"+getChToken(tr,i+1)+" Type:"+getChToken(tr,i)+"
     // Parm:"+sym.irname);
     currentSymTab.put(getChToken(tr, i + 1), sym);
     currentSymTab.put(sym.irname, sym); // Also put this so we can use $Px to search Symbol
   }
 }
示例#2
0
 private void var_decl(CommonTree tr) {
   // var_decl   :  VAR_DECL var_type var_id_list
   // var_id_list:  var_id (COMMA var_id)*
   // Child_0 store var_type, others store var_id_list
   if (tr.getChildren() == null) return;
   String type = getChToken(tr, 0);
   int var_num = tr.getChildren().size() - 1;
   for (int i = 1; i < tr.getChildren().size(); i++) {
     Symbol sym = new Symbol(getChToken(tr, i), type);
     if (currentFunc != null) {
       sym.irname = "$L" + Integer.toString(currentFunc.lNum + i);
       currentSymTab.put(sym.irname, sym); // Also put this so we can use $Lx to search Symbol
     }
     currentSymTab.put(getChToken(tr, i), sym);
   }
   if (currentFunc != null) currentFunc.lNum += var_num;
   // System.out.println(Integer.toString(tr.getChildren().size()-1)+" var in VAR_DECL,
   // type:"+type+"\n");
 }