Beispiel #1
0
  public static void main(String args[]) {
    String language = "java";
    ArrayList recFiles = new ArrayList();
    JFile curFile = null;

    for (int i = 0; i < args.length; i++) {
      if ("-l".equalsIgnoreCase(args[i]) || "--language".equalsIgnoreCase(args[i])) {
        language = args[i + 1].toLowerCase();
        i++;
      } else {
        recFiles.add(args[i]);
      }
    }
    if (!"c++".equals(language) && !"java".equals(language) && !"c".equals(language)) {
      System.out.println("Cannot recognize language:" + language);
      System.exit(1);
    }
    if (recFiles.size() == 0) {
      System.out.println("No record files specified. Exiting.");
      System.exit(1);
    }
    for (int i = 0; i < recFiles.size(); i++) {
      curFileName = (String) recFiles.get(i);
      File file = new File(curFileName);
      try {
        curFile = parseFile(file);
      } catch (FileNotFoundException e) {
        System.out.println("File " + (String) recFiles.get(i) + " Not found.");
        System.exit(1);
      } catch (ParseException e) {
        System.out.println(e.toString());
        System.exit(1);
      }
      System.out.println((String) recFiles.get(i) + " Parsed Successfully");
      try {
        curFile.genCode(language, new File("."));
      } catch (IOException e) {
        System.out.println(e.toString());
        System.exit(1);
      }
    }
  }
Beispiel #2
0
 public final JFile Include() throws ParseException {
   String fname;
   Token t;
   jj_consume_token(INCLUDE_TKN);
   t = jj_consume_token(CSTRING_TKN);
   JFile ret = null;
   fname = t.image.replaceAll("^\"", "").replaceAll("\"$", "");
   File file = new File(curDir, fname);
   String tmpDir = curDir;
   String tmpFile = curFileName;
   curDir = file.getParent();
   curFileName = file.getName();
   try {
     FileReader reader = new FileReader(file);
     Rcc parser = new Rcc(reader);
     try {
       ret = parser.Input();
       System.out.println(fname + " Parsed Successfully");
     } catch (ParseException e) {
       System.out.println(e.toString());
       System.exit(1);
     }
     try {
       reader.close();
     } catch (IOException e) {
     }
   } catch (FileNotFoundException e) {
     System.out.println("File " + fname + " Not found.");
     System.exit(1);
   }
   curDir = tmpDir;
   curFileName = tmpFile;
   {
     if (true) return ret;
   }
   throw new Error("Missing return statement in function");
 }