title: Parsing regular expressions based on a context free grammar
body: <p>Good evening, Stack Overflow.
  I'd like to develop an interpreter for expressions based on a pretty simple context-free grammar:</p>
  
  <p><a href="http://i.stack.imgur.com/JdHDT.png" rel="nofollow">Grammar</a></p>
  
  <p>Basically, the language is constituted by 2 base statements</p>
  
  <pre><code>( SET var 25 ) // Output: var = 25
  ( GET ( MUL var 5 ) ) // Output: 125
  ( SET var2 ( MUL 30 5 ) ) //Output: var2 = 150
  </code></pre>
  
  <p>Now, I'm pretty sure about what should I do in order to interpret a statement: 1) Lexical analysis to turn a statement into a sequence of tokens 2) Syntax analysis to get a symbol table (HashMap with the variables and their values) and a syntactic tree (to perform the GET statements) to 3) perform an inorder visit of the tree to get the results I want. </p>
  
  <p>I'd like some advice on the parsing method to read the source file. Considering the parser should ignore any whitespace, tabulation or newline, is it possible to use a Java Pattern to get a general statement I want to analyze? Is there a good way to read a statement weirdly formatted (and possibly more complex) like this</p>
  
  <pre><code>(
    SET var
  
   25
   )
  </code></pre>
  
  <p>without confusing the parser with the open and closed parenthesises?</p>
  
  <p>For example</p>
  
  <pre><code>Scanner scan; //scanner reading the source file
  String pattern = "..." //ideal pattern I've found to represent an expression
  while(scan.hasNext(pattern))
    Interpreter.computeStatement(scan.next(pattern));
  </code></pre>
  
  <p>would it be a viable option for this problem?</p>