<commit_before>package com.rox.emu.p6502;

import com.rox.emu.UnknownOpCodeException;
import com.rox.emu.p6502.op.AddressingMode;
import com.rox.emu.p6502.op.OpCode;

import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Compiler {
    public static final String VALUE_PREFIX = "$";
    public static final String IMMEDIATE_PREFIX = "#" + VALUE_PREFIX;

    private static final Pattern PREFIX_REGEX = Pattern.compile("^[(#$)?|($)?]\\D+"); //XXX This doesn't pick up 'ADC $10'
    private static final Pattern VALUE_REGEX = Pattern.compile("\\d+");

    private final String programText;

    public Compiler(String programText){
        this.programText = programText;
    }

    public int[] getBytes() {
        return compileProgram();
    }

    private int[] compileProgram() throws UnknownOpCodeException{
        int[] program = new int[2000];
        int i=0;

        StringTokenizer tokenizer = new StringTokenizer(programText);
        while (tokenizer.hasMoreTokens()){
            String opCodeToken = tokenizer.nextToken();

            //  OpCodeName [ Param1 | Param1 Param2 ]

            switch(opCodeToken){
                case "TAX":
                case "TAY":
                case "TYA":
                case "TXA":
                case "TXS":
                case "TXY":
                case "TSX":
                case "PHA":
                case "PLA":
                case "PHP":
                case "PLP":
                case "INY":
                case "DEY":
                case "INX":
                case "DEX":
                case "RTS":
                case "JSR":
                case "BPL":
                case "BMI":
                case "BVC":
                case "BVS":
                case "BCC":
                case "BCS":
                case "BNE":
                case "BEQ":
                case "SEC":
                case "CLC":
                case "SEI":
                case "SED":
                case "CLD":
                case "CLI":
                case "CLV":
                case "BRK":
                case "NOP":
                    program[i++] = OpCode.from(opCodeToken).getByteValue();
                    break;
                case "ADC":
                case "LDA":
                case "AND":
                case "ORA":
                case "EOR":
                case "SBC":
                case "LDY":
                case "LDX":
                case "CMP":
                case "CPX":
                case "CPY":
                    final String valueToken = tokenizer.nextToken().trim();
                    final String prefix = extractFirstOccurrence(PREFIX_REGEX, valueToken, opCodeToken);
                    final String value = extractFirstOccurrence(VALUE_REGEX, valueToken, opCodeToken);
<commit_msg>A little clean up<commit_after>package com.rox.emu.p6502;

import com.rox.emu.UnknownOpCodeException;
import com.rox.emu.p6502.op.AddressingMode;
import com.rox.emu.p6502.op.OpCode;

import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Compiler {
    public static final String VALUE_PREFIX = "$";
    public static final String IMMEDIATE_PREFIX = "#" + VALUE_PREFIX;

    private static final Pattern PREFIX_REGEX = Pattern.compile("^[(#$)?|($)?]\\D+"); //XXX This doesn't pick up 'ADC $10'
    private static final Pattern VALUE_REGEX = Pattern.compile("\\d+");

    private final String programText;

    public Compiler(String programText){
        this.programText = programText;
    }

    public int[] getBytes() {
        return compileProgram();
    }

    private int[] compileProgram() throws UnknownOpCodeException{
        int[] program = new int[2000];
        int i=0;

        StringTokenizer tokenizer = new StringTokenizer(programText);
        while (tokenizer.hasMoreTokens()){
            String opCodeToken = tokenizer.nextToken();

            //  OpCodeName [ Param1 | Param1 Param2 ]

            switch(opCodeToken){
                case "TAX": case "TAY":
                case "TYA": case "TXA": case "TXS": case "TXY": case "TSX":
                case "PHA": case "PLA":
                case "PHP": case "PLP":
                case "INY": case "DEY":
                case "INX": case "DEX":
                case "RTS":
                case "JSR":
                case "BPL": case "BMI": case "BVC": case "BVS": case "BCC": case "BCS": case "BNE": case "BEQ":
                case "SEC": case "CLC":
                case "SEI": case "SED":
                case "CLD": case "CLI": case "CLV":
                case "BRK":
                case "NOP":
                    program[i++] = OpCode.from(opCodeToken).getByteValue();
                    break;
                case "ADC":
                case "LDA":
                case "AND":
                case "ORA":
                case "EOR":
                case "SBC":
                case "LDY":
                case "LDX":
                case "CMP":
                case "CPX":
                case "CPY":
                    final String valueToken = tokenizer.nextToken().trim();
                    final String prefix = extractFirstOccurrence(PREFIX_REGEX, valueToken, opCodeToken);
                    final String value = extractFirstOccurrence(VALUE_REGEX, valueToken, opCodeToken);

{'fraction_non_alphanumeric': 0.11393805309734513, 'fraction_numerical': 0.008112094395280236, 'mean_word_length': 1.556550424128181, 'pattern_counts': {'":': 90, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '244584', 'n_tokens_mistral': 1596, 'n_tokens_neox': 1471, 'n_words': 397}