Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Logic expression parser

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?

like image 933
Adam Avatar asked Oct 28 '25 21:10

Adam


1 Answers

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.

like image 90
Denis Troller Avatar answered Oct 31 '25 01:10

Denis Troller