title: Very simple script parser in java
body: <p>I'm currently working on a small project in java where I need to process a very lightweight scripting language for a robot that I've made up.</p>
  
  <p>It doesn't need to deal with arithmetic or any complicated functionality, it only needs to run certain commands and deal with if and while statements.</p>
  
  <p>It could look something like this:</p>
  
  <pre><code>turn(90,cw)
  move(25)
  sleep(5000)
  get(temp)
  turn(90,ccw)
  get(image)
  </code></pre>
  
  <p>This is something that I've had no problem with and was able to get it working very quickly. However once I started considering if and while statements, I realised that things might be a lot more complex.</p>
  
  <p>For instance, It would be quite simple to manage something like this:</p>
  
  <pre><code>while(temp &gt; 50)
      move(25)
      turn(90,cw)
  </code></pre>
  
  <p>But I'm getting very confused as to how I can start to process statements like this:</p>
  
  <pre><code>while(temp &gt; 50)
      if(light &lt; 100)
          move(25)
      turn(90,cw)
      move(10)
  </code></pre>
  
  <p>Looking at it, I can see things getting very confusing very quickly!</p>
  
  <p>Is there a preferred method for processing "lightweight scripts" like these? Or would I be better off just sticking with it and working out some kind of manual parser?</p>
  
  <p>Thanks for any help you can give me!</p>
  
  <p><strong>EDIT</strong> -  Thanks for the help everyone, I got it working really quickly using the Java Scripting Engine!</p>