Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Parse logical expression string in qt
tushar jambhekar last edited by
In my application, my application needs to take some action based on result of expression string provided by the application user
the expression may include
- some variables already used in my application
- Boolean and numeric constants
- logical and arithmetic(+-*/) operators
e.g. expression string might be !((var1&var2)|Var3)
in which var1, var2 and var3 are the variables already declared in my application
if any standard scripting language is supported then i can use it and syntax of expression can be changed as per requirements.
I need some guidance or tutorial which can help me to get started
DerManu last edited by
Have a look at http://qt-project.org/doc/qt-4.8/scripting.html
However this of course might be much too powerful than necessary (or even desirable) in your situation. A parser for such simple expressions can be written from scratch quite quickly. Recurse bracket-wise and decompose into operand-operator-operand blocks, which finally create a tree structure. Then just execute the logic of the tree, the value of the root is the result.