0

I want to make a propositional calculus parser with Javascript, which will elaborate the input and tell if the logical proposition is correct. For example, I would type

(A && B) || (B && A) => not(A)

and then i would insert in another prompt the possible values of A and B.

I'm not asking someone to get the work done for me, it's just I don't know where to start. I'd like to have some hints: how could I correctly represent with Javascript the semantic, the syntax of the propositional calculus?

Thanks in advance!

elmazzun
  • 1,066
  • 2
  • 18
  • 44
  • 3
    Have you tried [PEG.js](http://pegjs.majda.cz/online)? – acdcjunior Apr 02 '14 at 20:48
  • 2
    For anything non-trivial, you're probably going to want either a recursive-descent parser or a state machine (either your own, or something you can configure). Mentioning them primarily so you know what to search for. Don't get sucked into trying to find a JavaScript-based regular expression solution, it will be a massive waste of time. – T.J. Crowder Apr 02 '14 at 20:49
  • I was asked to make a labeled lambda calculus parser and resolutor, but since I'm not accustomed to code like this, I thought to start from a simpler formalism, like the propositional calculus. If you say that recursive-descent parser or a state machine are two possibile ways to implement this project, I'll check it out. Thanks to both of you :) – elmazzun Apr 02 '14 at 20:52

1 Answers1

1

you could try using antlr v3's javascript target.

here's a question that has the grammer you're looking for: ANTLR Propositional Logic Evaluator

and another question you might find helpful: ANTLR JavaScript Target

Community
  • 1
  • 1
Jeremy Danyow
  • 26,470
  • 12
  • 87
  • 133