// ** This file was generated with DemFGen (vers:12/15/2010)

options{ STATIC = false;  }
PARSER_BEGIN(TheParser)
package gen;

import edu.neu.ccs.demeterf.lib.*;
import edu.neu.ccs.demeterf.*;
import java.lang.Integer;
import edu.neu.ccs.demeterf.lib.*;
import edu.neu.ccs.demeterf.*;
import java.lang.Integer;
import edu.neu.ccs.demeterf.lib.*;
import edu.neu.ccs.demeterf.*;
import java.lang.Integer;
import edu.neu.ccs.demeterf.Fields;
import edu.neu.ccs.demeterf.lib.ident;
import edu.neu.ccs.demeterf.lib.verbatim;

  public class TheParser{

   public static String unescape(String str){
      String retval = "";
      int index = 0;
      char ch, ch1;
      int ordinal = 0;
      while (index < str.length()) {
         if(str.charAt(index) != '\\') { retval += str.charAt(index++); continue; }
         ch = str.charAt(++index);
         if(ch == 'b') { retval += '\b'; index++; continue; }
         if(ch == 't') { retval += '\t'; index++; continue; }
         if(ch == 'n') { retval += '\n'; index++; continue; }
         if(ch == 'f') { retval += '\f'; index++; continue; }
         if(ch == 'r') { retval += '\r'; index++; continue; }
         if(ch == '"') { retval += '\"'; index++; continue; }
         if(ch == '\'') { retval += '\''; index++; continue; }
         if(ch == '\\') { retval += '\\'; index++; continue; }
         if(ch >= '0' && ch <= '7'){
            ordinal = ((int)ch) - ((int)'0'); index++;
            ch1 = str.charAt(index);
            if(ch1 >= '0' && ch1 <= '7'){
               ordinal = ordinal*8 + ((int)ch1) - ((int)'0'); index++;
               ch1 = str.charAt(index);
               if(ch <= '3' && ch1 >= '0' && ch1 <= '7'){
                  ordinal = ordinal*8 + ((int)ch1) - ((int)'0'); index++;
               }
            }
            retval += (char)ordinal;
            continue;
         }
         if(ch == 'u'){
            ordinal = 0;
            for(int i = 0; i < 4; i++){
               index++; ch = str.charAt(index);
               ordinal = ordinal*16+hexval(ch);
            }
            index++;
            retval += (char)ordinal;
            continue;
         }
      }
      return retval;
   }
   static int hexval(char c){
      int r = "0123456789ABCDEF".indexOf(Character.toUpperCase(c));
      if(r >= 0)return r;
      throw new RuntimeException(" ** Bad Escaped Character");
   }
  }
PARSER_END(TheParser)

byte parse_byte():{ int i; }{
    i = parse_int() { return (byte)i; }
}
Byte parse_Byte():{ byte b; }{
    b = parse_byte() { return b; }
}
short parse_short():{ int i; }{
    i = parse_int() { return (short)i; }
}
Short parse_Short():{ short s; }{
    s = parse_short() { return s; }
}
int parse_int():{ Token t; }{
    t = <INT>
    { if(t.image.length() > 1 && Character.toLowerCase(t.image.charAt(1)) == 'x')
          return Integer.parseInt(t.image.substring(2), 16);
      return Integer.parseInt(t.image); }
}
Integer parse_Integer():{ int i; }{
    i = parse_int() { return i; }
}
long parse_long():{ Token t; }{
    t = <INT>
    { if(t.image.length() > 1 && Character.toLowerCase(t.image.charAt(1)) == 'x')
          return Long.parseLong(t.image.substring(2), 16);
    return Long.parseLong(t.image); }
}
Long parse_Long():{ long l; }{
    l = parse_long() { return l; }
}
double parse_double():{ Token t; }{
    t = <DOUBLE>
    { return Double.parseDouble(t.image); }
}
Double parse_Double():{ double d; }{
    d = parse_double() { return d; }
}
float parse_float():{ Token t; }{
    t = <DOUBLE>
    { return Float.parseFloat(t.image); }
}
Float parse_Float():{ float f; }{
    f = parse_float() { return f; }
}
String parse_String():{ Token t; }{
    t = <STRING>
    { return unescape(t.image.substring(1,t.image.length()-1)); }
}
boolean parse_boolean():{ Token t; }{
    t = <TRUE> { return true; } |
    t = <FALSE> { return false; }
}
Boolean parse_Boolean():{ boolean b; }{
    b = parse_boolean() { return b; }
}
char parse_char():{ Token t; }{
    t = <CHAR>
    { return unescape(t.image.substring(1,t.image.length()-1)).charAt(0); }
}
Character parse_Character():{ char c; }{
    c = parse_char() { return c; }
}
ident parse_ident():{ Token t; }{
    t = <IDENT>
    { return new ident(t.image); }
}
verbatim parse_verbatim():{ Token t; }{
    t = <TEXT>
    { return new verbatim(t.image.substring(2,t.image.length()-2)); }
}

public InstanceSet parse_InstanceSet():{
}{
    "game-specific intensional definition"
    { return new InstanceSet(); }
}

public Claim parse_Claim():{
     InstanceSet is;
     Protocol p;
}{
    "claim"
    is = parse_InstanceSet()
    p = parse_Protocol()
    { return new Claim(is,p); }
}

public Protocol parse_Protocol():{
     State state;
}{
    "protocol"
    state = parse_State()
    { return new Protocol(state); }
}

public State parse_State():{
    State sup = null;
}{
(   sup = parse_Start() { return sup; } | 
    sup = parse_End() { return sup; } | 
    sup = parse_BobProvides() { return sup; } | 
    sup = parse_AliceSolves() { return sup; } | 
    sup = parse_AliceProvides() { return sup; } | 
    sup = parse_BobSolves() { return sup; } )
}

public BobProvides parse_BobProvides():{
}{
    "BP"
    { return new BobProvides(); }
}

public AliceProvides parse_AliceProvides():{
}{
    "AP"
    { return new AliceProvides(); }
}

public BobSolves parse_BobSolves():{
}{
    "BS"
    { return new BobSolves(); }
}

public AliceSolves parse_AliceSolves():{
}{
    "AS"
    { return new AliceSolves(); }
}

public Start parse_Start():{
}{
    "START"
    { return new Start(); }
}

public End parse_End():{
}{
    "END"
    { return new End(); }
}

public PlayerProxy parse_PlayerProxy():{
}{

    { return new PlayerProxy(); }
}

public EP parse_EP():{
     Expectation e;
     PlayerProxy p;
     boolean ok;
}{
    e = parse_Expectation()
    p = parse_PlayerProxy()
    ok = parse_boolean()
    { return new EP(e,p,ok); }
}

public Expectation parse_Expectation():{
}{

    { return new Expectation(); }
}

public Transaction parse_Transaction():{
}{

    { return new Transaction(); }
}

public ClaimInterface parse_ClaimInterface():{
    ClaimInterface sup = null;
}{
(  { return sup; } )
}

public ProtocolInterface parse_ProtocolInterface():{
    ProtocolInterface sup = null;
}{
(  { return sup; } )
}

public Test2 parse_Test2():{
     Instance i;
     Solution s;
     Domain d;
     Claim c;
}{
    i = parse_Instance()
    s = parse_Solution()
    d = parse_Domain()
    c = parse_Claim()
    <EOF>
    { return new Test2(i,s,d,c); }
}

public Instance parse_Instance():{
     int n;
     int k;
}{
    "claim"
    "HSR"
    n = parse_int()
    k = parse_int()
    { return new Instance(n,k); }
}

public Solution parse_Solution():{
     DecisionTree d;
}{
    d = parse_DecisionTree()
    { return new Solution(d); }
}

public Domain parse_Domain():{
}{
    "domain"
    { return new Domain(); }
}

public DecisionTree parse_DecisionTree():{
}{
    "dt"
    { return new DecisionTree(); }
}

public DomainInterface parse_DomainInterface():{
    DomainInterface sup = null;
}{
(  { return sup; } )
}

public Test1 parse_Test1():{
     Instance i;
     Solution s;
     Domain d;
}{
    i = parse_Instance()
    s = parse_Solution()
    d = parse_Domain()
    <EOF>
    { return new Test1(i,s,d); }
}

TOKEN: { < INT : ("+" | "-")? ( (["0"-"9"])+ 
                                  | ("0" ["x","X"]) (["0"-"9","a"-"f","A"-"F"])+ ) >
       | < DOUBLE : ("-")?(["0"-"9"])+ "." (["0"-"9"])+ (<EXPON>)?
                            | "." (["0"-"9"])+  (<EXPON>)? >
       | < #EXPON: ["e","E"] (["+","-"])? (["0"-"9"])+ > }
SKIP : { " " | "\t" | "\n" | "\r" | "\r\n" }
SKIP : { < "//" (~["\n","\r"])* ("\n"|"\r\n") >
       | < "/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/" > }
TOKEN: { < TRUE : "true" >
       | < FALSE : "false" > }
TOKEN: { < CHAR: "\'" 
              ( (~["\'","\\","\n","\r"]) | 
                ("\\" ( ["n","t","b","r","f","\\","\'","\""] |
                            ["0"-"7"] ( ["0"-"7"] )? |
                            ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )
              "\'" >
       | < STRING :
              "\""
              (   (~["\"","\\","\n","\r"])
                | ("\\"
                    ( ["n","t","b","r","f","\\","'","\""]
                    | ["0"-"7"] ( ["0"-"7"] )?
                    | ["0"-"3"] ["0"-"7"] ["0"-"7"]
                    )
                  )
              )*
              "\"" >
       | < TEXT : ( "{{" (~["}"])* ( "}" ~["}"] (~["}"])* )* "}}" ) >
       | < IDENT : ["a"-"z","A"-"Z","$","_"]
                   (["a"-"z","A"-"Z","0"-"9","_","$"])* > }