I have the following grammar in ANTLRWorks 1.4. I'm playing around with ideas for implementation of a parser in a text-adventure game creator, where the user will specify the various allowable commands for his 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'm just getting a feel for the various subtleties involved (like I did here).
This time, using ANTLR, I'm wondering if I can parse input such as:
put wood in fire place
That is, "wood" and "fire place" are the gameObjects above. However, "place" is also a synonym for "put". So this would be equally valid:
place wood in fire place
ANTLR gives me a NoViableAltException when trying to parse the last "place" token. I want to recognize "fire place" as a gameObject.
So is this sort of thing possible in ANTLR? Is it possible in grammar?
On the side, I'm working on a manual implementation that uses a weird custom data structure with bits of NFA, Dictionary's and whatnot. But I still need more time and must sacrifice a few brain cells to design the required search & insertion algorithms.
But if this is possible in ANTLR, I could just use the generated C# file, yah?