Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is wrong with this ParseKit BNF?

I'm using ParseKit for objective-C which takes a BNF-like syntax for specifying grammers:

@start = command+;
command = new;
new = 'new' object ';';
object = 'house' | other;

Inclusion of the last line causes an error. Basically I want to say an object can be a house or something else. The non-terminal element "other" is supposed to catch whatever word was there that wasn't house.

Am I going about the "anything-here" idea the wrong way?

Thanks!

like image 679
FBryant87 Avatar asked Jul 21 '11 13:07

FBryant87


1 Answers

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;
like image 180
Todd Ditchendorf Avatar answered Sep 27 '22 23:09

Todd Ditchendorf