I am trying to write a grammar for ParseKit so that it matches basic propositional logic sentences in an iphone app. Can someone please tell me where im going wrong.
@start = wff;
wff = disjunction (implies disjunction)?;
disjunction = conjuction (or conjuction)*;
conjunction = notExpression (and notExpression)*;
notExpression = (not | not primaryExpression);
primaryExpression = variable | lbracket wff rbracket;
variable = p | q | r;
p = 'P';
q = 'Q';
r = 'R';
implies = '→';
and = '∧';
or = '∨';
not = '¬';
lbracket = '(';
rbracket = ')';
Also how would i go about adding some extra call backs so that I can create a parse tree from the grammar.
Developer of ParseKit here.
I see one obvious problem:
conjunction
is misspelled in a couple of places in your grammar.ParseKit's Grammar Parser's error messages are not the greatest. Ideally, you would receive a nice error message leading you to the problem (but, hey it's open source so anyone is welcome to contribute a fix of this nature).
However, I can tell you how I find these issues:
~/Desktop/grammar.txt
~/Desktop/input.txt
DebugApp
target in Debug configuration.Run
button in the window that appears when the app runs.If there is a bug in your grammar, you will find the exception has most likely occurred in a ParseKit Assembler callback like:
print
a
to the debug console. You'll see something like:This is a printout of the
PKAssembly
object passed into your callback. Here you can see where ParseKit's grammar parser failed to parse your grammar. It appears that the ParseKit Grammar Parser failed while parsing this expression:And from the position of the
^
(caret), you can tell the parser choked right after seeing the firstconjuction
.This expression is located in just one line in your grammar:
That's how I noticed that there was a misspelling in this line.
This approach will invariably lead you to the problematic line in your grammar. Hope that helps.