title: Parsing SQL like syntax, design pattern
body: <p>I am trying mock sql syntax to build a simple sql like interface to a key-value storage.
  The values are essentially POJOs</p>
  
  <p>An example would be</p>
  
  <pre><code>select A.B.C from OBJ_POOL where A.B.X = 45 AND A.B.Y &gt; '88' AND A.B.Z != 'abc';
  </code></pre>
  
  <p>OBJ_POOL is just a list of POJOs of the same class. In this example A would be the base class.</p>
  
  <pre><code>Class A
      Class B
          String C
          Integer X
          String Y
          String Z
  </code></pre>
  
  <p>Now A.B.C is equivalent A.getB().getC()</p>
  
  <p>I am using Antlr to parse the above statement to get an AST, and then <code>hoping</code> to use Apache BeanUtils to reflectively get/set the field names.</p>
  
  <p>I wrote the grammar thats builds an AST
  <img src="https://i.stack.imgur.com/E7A5H.png" alt="AST for the above statment">
  Now I am facing two problems</p>
  
  <ol>
  <li>How should the visitor be implemented for the where clause ? A.B.X = 45 implies all objects having field X as 45, how should the filtering happen is there any nice way to do this ?</li>
  <li>Is there any way to traverse the generated AST without cluttering the visitor code with custom logic (storage access,property getters/setters etc..) </li>
  </ol>
  
  <p>The second problem is more worrying since there might be many things that the statement might do.</p>
  
  <p>In a nutshell any suggestions/links/design-patterns to nicely parse a small subset of the sql select statment would be greatly appreciated</p>
  
  <p>Thanks</p>