Advertisement
makerimagesGames

Still not compiling ok

Jun 12th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.13 KB | None | 0 0
  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. package tests;
  6.  
  7. import java.io.BufferedReader;
  8. import java.io.File;
  9. import java.io.FileReader;
  10. import java.io.IOException;
  11. import java.util.logging.Level;
  12. import java.util.logging.Logger;
  13. import org.apache.commons.codec.DecoderException;
  14. import org.apache.commons.codec.binary.Hex;
  15.  
  16.  
  17. /**
  18.  *
  19.  * @author Makerimages
  20.  */
  21. public class Compilertest3
  22. {
  23.     String S;
  24.     String SClean;
  25.  
  26.     public Compilertest3(File f) throws IOException
  27.     {
  28.       //  intNames=new String[256];
  29.       //  ints=new String[256];
  30.          StringBuffer fileData = new StringBuffer();
  31.         BufferedReader reader = new BufferedReader(
  32.                 new FileReader(f));
  33.         char[] buf = new char[1024];
  34.         int numRead=0;
  35.         while((numRead=reader.read(buf)) != -1){
  36.             String readData = String.valueOf(buf, 0, numRead);
  37.             fileData.append(readData);
  38.         }
  39.         reader.close();
  40.        S=fileData.toString();
  41.     }
  42.  
  43.    
  44.    
  45.    
  46.     public void cleanFile(String input)
  47.     {
  48.         String split[]=input.split("\n");
  49.         input="\n"+input;
  50.         split[0]=" "+split[0];
  51.          int count = 0;
  52.          int intCount = 0;//change this for starting vX value (default: 0)
  53.          int funcCount=0;
  54.                 while (count < split.length) {
  55.                         if (split[count].startsWith(" define")) {
  56.                            
  57.                                 split[count] = split[count].substring(8);//remove define and space
  58.                                
  59.                                 input = input.replaceAll(split[count].split(" ")[0], split[count].substring(split[count].split(" ")[0].length()));
  60.                                 //the above replaces the first argument with all the last arguments in the define function, in the input string
  61.                               //  System.err.print(input);
  62.                         }  if (split[count].startsWith(" int")) {
  63.                                //System.out.println("int debug:");
  64.                          
  65.                                 split[count] = split[count].substring(4);//remove "int" and space
  66.                                 input = input.replaceAll(split[count], " v" + intCount + " ");
  67.                               input= input.replaceAll(split[count], " v" + intCount + " ");//just in case
  68.                                
  69.                                 intCount++;
  70.                         }
  71.                         if (split[count].startsWith("func "))
  72.                         {
  73.                             split[count] = split[count].substring(0);
  74.                             input = input.replaceAll(split[count], "~" + funcCount + " ");
  75.                            // input = input.replaceAll(split[count], " ~" + funcCount + " ");//just in case
  76.                             funcCount++;
  77.                         }
  78.                        
  79.                      
  80.                          
  81.                         count++;
  82.                 }
  83.                
  84.                 input = input.replaceAll("\n int.*.\n", "\n");//this is where the added \n at start is
  85.                 input = input.replaceAll("\n func.*.\n", "\n");
  86.                  input = input.replaceAll(" #.*.", "");
  87.                    input = input.replaceAll("\\{", "");
  88.                 while(input.contains(" int ")==true)
  89.                 {
  90.                         input = input.replaceAll("\n int.*.\n", "\n");
  91.                 }
  92.                
  93.                          while(input.contains(" func ")==true)
  94.                 {
  95.                         input = input.replaceAll("\n func.*.\n", "\n");
  96.                 }
  97.                 input=input.replaceAll("(?m)^[ \t]*\r?\n", "");//clear all empty lines
  98.                 input=input.substring(0);//gets rid of the problem caused by the adding \n thing
  99.               //  input = cleanInput(input);//cleans the input for the last time
  100.                 //System.err.print(input);
  101.                 SClean=input;
  102.                 System.err.println(SClean);
  103.                 }
  104.    
  105.  
  106.    
  107.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement