options {
  STATIC=false;
  LOOKAHEAD=2;
  ERROR_REPORTING = true;
  IGNORE_CASE = true;
  SANITY_CHECK = true;
}


PARSER_BEGIN(Advent)


public class Advent {

  public String cnoun;
  public String cverb;

    static void flushInput() {
             try {
               while (System.in.available()!=0) System.in.read();
            }
          catch (java.io.IOException ioe) { 
            System.out.println("I/O Error");
            System.exit(99);
           }
    }


  public static void main(String args[]) {
    Game theGame  = new Game();
    Advent parser = new Advent(System.in);
    System.out.println(theGame.look());

    String output=null;
    do {
       try {
                     output=parser.Input();
               if (output==null)
                 output=theGame.doit(parser.cverb,parser.cnoun);
         }
       catch (ParseException e) {
          output="I don't understand.";
          flushInput();
          parser.ReInit(System.in);
          }
       catch (TokenMgrError tme) {
          output="I don't understand.";
              flushInput();
          parser.ReInit(System.in);
          }
       if (output!=null) {
         if (output.charAt(0)=='@') 
           System.out.println(output.substring(3)); 
             else 
           System.out.println(output);
         }
       } while (output!=null && output.charAt(0)!='@');
  }
}

PARSER_END(Advent)

SKIP :
{
  " "
| "\t"
| "\r"
| "A"
| "AN"
| "THE"
| "PLEASE"
}

TOKEN :
{
  <GET: "GET" | "TAKE">
|  <HELP: "HELP">
|  <LOOK: "LOOK" | "EXAMINE">
|  <KILL: "KILL">
|  <CHEST: "CHEST" >
|  <GOLD: "GOLD">
|  <SWORD: "SWORD">
|  <DOOR: "DOOR">
|  <BEAR: "BEAR">
|  <OPEN: "OPEN">
|  <GO: "GO">
|  <NORTH: "NORTH" | "N">
|  <SOUTH: "SOUTH" | "S">
|  <EAST: "EAST" | "E">
|  <WEST: "WEST" | "W">
|  <QUIT: "QUIT">
|  <EOL: "\n">
}



String Input() :
{
}
{
  <QUIT> <EOL> { return "@@@ Bye. You didn't solve the dungeon"; }
| <HELP> <EOL> { cverb=cnoun="help"; return null; }
| <LOOK> <EOL> { cverb=cnoun="look"; return null; }
| direction() { cverb="go"; cnoun=token.image;} <EOL> { return null; }
|  verb() { cverb=token.image; } noun() { cnoun=token.image; } <EOL>
  {
   return null;
  }
}

void direction() :
{ }
{
  <NORTH>
| <SOUTH>
| <EAST>
| <WEST>
}

void verb() :
{ }
{
  <LOOK>
| <GET>
| <KILL>
| <OPEN>
| <GO>
}

void noun() :
{ }
{
  <CHEST>
| <DOOR>
| <GOLD>
| <BEAR>
| <SWORD>
| direction()
}