This week's book giveaway is in the Features new in Java 9 forum.
We're giving away four copies of Java 9 Revealed and have Kishori Sharan on-line!
See this thread for details.
Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Help with SQL Where clause parser and infinate recursion  RSS feed

 
Rj Ewing
Ranch Hand
Posts: 120
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to write a PEG parser using parboiled to construct an AST that I can generate sql from.

The part that is giving me trouble are and/or expressions. My rules are written as follows:


The string I'm trying to parse is val = 1 AND val2 = 1 OR val2 = 0 AND val3 = 0

The tree should start with an OR Expression with a left expression of val = 1 AND val2 = 1 and a right expression of val2 = 0 AND val3 = 0

I'm not sure of the best way to get the following structure. The recursive call LogicalExpression() -> Expression() -> LogicalExpression() is where the issue stems.

Any thoughts/help with how to eliminate the left recursion would be great.
 
Rj Ewing
Ranch Hand
Posts: 120
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, so it turns out I need to break down my rules a bit more and think about precedence, with separate rules for AND & OR. Heres a peek at what I ended up with

 
Tony Docherty
Saloon Keeper
Posts: 3214
78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for posting your solution and well done for working it out.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!