Last active
          December 13, 2015 19:39 
        
      - 
      
- 
        Save wallstop/4964551 to your computer and use it in GitHub Desktop. 
    Basic evaluator for SMCM Code Golf
  
        
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
  | import java.io.BufferedReader; | |
| import java.io.FileReader; | |
| public class CodeGolfParser | |
| { | |
| public static void parse(String fileName) throws Exception | |
| { | |
| BufferedReader fReader; | |
| int characterCount; | |
| int currentChar; | |
| boolean pythonFile; | |
| boolean readingNewLine; //Used to check for 4-space like tabs in python files | |
| readingNewLine = false; | |
| characterCount = 0; | |
| fReader = new BufferedReader(new FileReader(fileName)); | |
| //Checks for python file, which may be using 4 spaces instead of tabs | |
| if(fileName.indexOf(".py") == fileName.length() - 3) | |
| pythonFile = true; | |
| else | |
| pythonFile = false; | |
| while((currentChar = fReader.read()) != -1) | |
| { | |
| if(pythonFile && (currentChar == '\n' || currentChar == '\r')) //Checks for newline characters, | |
| readingNewLine = true; | |
| else if(readingNewLine && currentChar != ' ') //Otherwise checks for the end of leading spaces | |
| readingNewLine = false; | |
| if(!readingNewLine && (currentChar > 31 && currentChar < 0xBB)) | |
| characterCount++; | |
| } | |
| System.out.printf("%d total characters.\n", characterCount); | |
| } | |
| public static void main(String [] args) | |
| { | |
| try | |
| { | |
| parse(args[0]); | |
| } | |
| catch(Exception e) | |
| { | |
| System.err.println("Illegal program execution: " + e); | |
| System.err.println("Please restart with proper arguments."); | |
| } | |
| } | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment