## Wednesday, September 25, 2013

### String Logic Parsing

As the Peirce Logic team has taken on more members (and with them more ambitious goals), the breadth of topics being covered has really ballooned.  People are now working on touch controls, UI, collision changes, back-end storage, and of course bug fixes aplenty.  But to make sure all this new stuff works and our system remains stable, sometimes old code needs to be re-worked as well.  Enter parsing!  Currently, Peirce Logic can parse a user's logic string and create an object to be drawn as a graph.  Below is a diagram showing roughly the function our parsing provides.

The current code we use for parsing was written by scratch and, while it works perfectly now, it is written in a way that makes adding functionality difficult.  To make sure we have robust and easily modified code, we are writing a new parser using the Open Source tool Peg.js.  Peg.js takes a file specifying a grammar and creates a JavaScript file tailored to parse that specified grammar.  This means that we can keep a short, easy to read, and easy to change grammar file, and swap in the Peg.js generated parser to keep our system up to date and functioning.  Simple!

As a side note, there was some disagreement among operator precedence, some members thought conjunction and disjunction should have equal precedence, but we ended up going with the "standard" we found online, which is as follows:
OperatorPrecedence
¬1
$\wedge$2
$\vee$3
4
$\leftrightarrow$5
Peirce out