What is wrong with this ParseKit BNF?
Developer of ParseKit here. Carmine's answer above is excellent and you should take his advice. One small additional note:
If you want to make it easy for your Parser delegate to notice when 'house' was matched vs. any other random word, I would change the last line of your grammar above to:
object = house | other;house = 'house';other = Word;
Then you should implement the two following callback methods in your Parser delegate:
- (void)parser:(PKParser *)p didMatchHouse:(PKAssembly *)a;- (void)parser:(PKParser *)p didMatchOther:(PKAssembly *)a;
If you want to allow other
to match any token at all (not just words, but also numbers, symbols, quoted strings, etc), you can use the builtin Any
type. In that case, you would change the last line of my example above to:
other = Any;
As suggested in the comments, you should either replace other
with Word
or add a new rule:
other = Word;
Since 'house'
is a Word
, you can also directly replace the object
rule with:
object = Word;
A Word
in ParseKit is a contiguous sequence of characters ([a-zA-Z]
), numbers ([0-9]
), and the symbols -
, _
, and '
, that starts with a character. You can find more information about ParseKit tokens in the documentation.