Answer the question
In order to leave comments, you need to log in
How to properly parse conditional expressions?
There is a task from a line, readable for the user, to generate sql-request.
There is a widget that helps the user generate logical queries like (3 examples):
1) `column1`=="1044"
2) (`column1`>"302")&&(`column2`!="tree")
3) ` column2`=="cement"||(`column1`<"1000"&&`column1`>="500"
) them. While I look towards lexical analyzers. Has anyone had similar issues? In which direction to look / dig?
Answer the question
In order to leave comments, you need to log in
I think the logic here is not much different from parsing arithmetic expressions.
Either postfix / prefix form or build an expression tree. It will be more logical for you to build a tree.
You can split the source text into tokens by writing small classes for this. There are plenty of examples and recipes on the Internet.
You can use ready-made lexical analysis elements from the library www.boost.org/doc/libs/1_60_0/libs/spirit/doc/html...
Or the classic: yacc+lex.
In your case, the grammar is very simple, so it makes sense to write the tokenization classes yourself. Most likely, there are already ready-made ones in Qt.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question