Parser implementation that evaluates propositional logic formulas using lexical analysis (tokenization) and parsing techniques. It supports the recognition of atomic propositions, logical connectives (negation, conjunction, disjunction, implication, equivalence), and parentheses for grouping.
0
stars
0
forks
source link
lack of negation precedence causing parser to not parse negations correctly #1
Hi, I was looking through your code and I can see that for the unary negation expressions (~p) for example, you don't seem to have the parser set with the correct precedence. From looking through here: https://www.dabeaz.com/ply/ply.html, I could see in section 6.6 Dealing With Ambiguous Grammars that you need to do something like this:
for negation to work as it should. I think you might also need to look into the precedences in general but I'm not sure. I think this change breaks how you get variables (or at least it did for me) so that might be something else you have to change.
Hi, I was looking through your code and I can see that for the unary negation expressions (~p) for example, you don't seem to have the parser set with the correct precedence. From looking through here: https://www.dabeaz.com/ply/ply.html, I could see in section 6.6 Dealing With Ambiguous Grammars that you need to do something like this:
for negation to work as it should. I think you might also need to look into the precedences in general but I'm not sure. I think this change breaks how you get variables (or at least it did for me) so that might be something else you have to change.
give it a test with
formula = "~p | q"