I have the following grammar in ANTLRWorks 1.4. I play with ideas for implementing a parser in a text adventure creator where the user will specify various valid commands for their game.
grammar test;
parse : cmd EOF;
cmd : putSyn1 gameObject inSyn1 gameObject;
putSyn1 : Put | Place | Drop ;
inSyn1 : In | Into | Within;
gameObject : det obj;
det : The | A | An | ;
obj : Word obj | Word;
Space : (' ' | '\t' | '\r' | '\n'){$channel=HIDDEN;};
Put : 'put';
Place : 'place';
Drop : 'drop';
In : 'in';
Into : 'into';
Within : 'within';
The : 'the';
A : 'a';
An : 'an';
Word : ('a'..'z' | 'A'..'Z')+;
I just feel the various subtleties involved (for example, here ).
This time, using ANTLR, I wonder if I can parse the input, for example:
put wood in fire place
That is, the "tree" and the "place for the fireplace" are the gameObjects above. However, "place" is also synonymous with "put". Thus, this will be equally true:
place wood in fire place
ANTLR NoViableAltException . " " gameObject.
ANTLR? ?
, , NFA, Dictionary . .
ANTLR, #, yah?