0

I have a number of strings in a query-like format (using column names, 'and', 'or', parentheses, and the relational operators) that I need to parse in the form:

"column1 > 100"

"column1 = 120 and column3 = 200"

"((column2 = 100) or (column3 = 50 and column1 = 20))"

What would be the best way that I could parse and store each expression for use? I think parsing the string using a bunch of string.substring() and string.indexOf would be good, but I'm unsure how I could store each expression in a useful way to pop() them.

user1546716
  • 101
  • 1
  • 7
  • the simplest way would be to use an already existing api. – Distjubo Apr 25 '15 at 18:03
  • The simplest way or the best way? The best way is likely a parse tool like ANTLR, but if you don't want the hassle of learning a new tool, and your expressions are *very* simple, you can probably just stick with Java Standard APIs. – pathfinderelite Apr 25 '15 at 18:05
  • Depends on how you want them to be parsed. Easiest way is using some existing library, and then comes some sort of regex pattern I guess. – Bubletan Apr 25 '15 at 18:08

0 Answers0