title: Which is the best way to parse a file containing Assembly language using Java.?
body: <p>I have read about <code>StringTokenizer</code>, <code>StreamTokenizer</code>, <code>Scanner</code>, <code>Pattern</code> and <code>Matcher</code> from the <code>java.util.regex</code> package. I have also read about opinions on them and I am realy confused: which one is the best to use?</p>
  
  <p>What I need to do is to make an Assambler, that is, to parse a file containing Assembly language from that file and I need to transform it into Machine Code.</p>
  
  <p>For example if I have the assembly code: </p>
  
  <p><code>MOV R15,R12</code> </p>
  
  <p>This should translate to hexa numbers coresponding to each instruction and register.</p>
  
  <p>Let's just say that the translation is as follows:</p>
  
  <ul>
  <li><code>MOV</code> becomes <code>10 F3</code> </li>
  <li><code>R15</code> becomes <code>11 F2</code> </li>
  <li><code>R12</code> becomes <code>20 1E</code></li>
  </ul>
  
  <p>Thus, my output file should be:</p>
  
  <p><code>10 F3 11 F2 20 1E</code>  </p>
  
  <p>Now I need to parse the Assembly file to identify each instruction and what comes after it.</p>
  
  <p>For those who know microcontroller there are many ways for an instruction to appear. My question is: </p>
  
  <p>Using Java, which is the best method to transform each word from my file into tokens (using any of the aforementioned classes), so that I can find the matching one and write it into a file.</p>
  
  <p><code>ldi R13,0x31</code>  </p>
  
  <p>I need to have <code>ldi</code> in one token, <code>r13</code> in another and <code>31</code> in another</p>