I'm trying to create a logic expression parser for expressions like: ((VariableA -> VariableB) AND NOT VariableC) The parser should be able to return, whether the result is true or false for given values of variables.
Basically, the expressions will only contain variables, logical operators (or, and, implication, equivalence, negation and parentheses).
I would like to ask what is the best way to implement this kind of parser (using AST tree, or Reverse Polish Notation)? Or maybe there already exist some open source parsers that can do the job?
What language are you targeting?
If you want to create a parser, maybe ANTLR will do the trick for you. It is originally java-based but it has generators for a variety of languages (I use it for generating a C# parser for example) and is no too difficult to pick-up. It has a nice editor (ANTLRWorks) that allows testing the grammar, which is a nice plus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With