// ** This class was generated with DemFGen (vers:09/12/2009) options{ STATIC = false; } PARSER_BEGIN(TheParser) package gen; import java.io.FileInputStream; import edu.neu.ccs.demeterf.lib.*; import edu.neu.ccs.demeterf.control.Fields; import edu.neu.ccs.demeterf.lib.ident; import edu.neu.ccs.demeterf.lib.verbatim; 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 = { 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 = { 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 = { return Double.parseDouble(t.image); } } Double parse_Double():{ double d; }{ d = parse_double() { return d; } } float parse_float():{ Token t; }{ t = { return Float.parseFloat(t.image); } } Float parse_Float():{ float f; }{ f = parse_float() { return f; } } String parse_String():{ Token t; }{ t = { return unescape(t.image.substring(1,t.image.length()-1)); } } boolean parse_boolean():{ Token t; }{ t = { return true; } | t = { return false; } } Boolean parse_Boolean():{ boolean b; }{ b = parse_boolean() { return b; } } char parse_char():{ Token t; }{ t = { 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 = { return new ident(t.image); } } verbatim parse_verbatim():{ Token t; }{ t = { return new verbatim(t.image.substring(2,t.image.length()-2)); } } public Outcome parse_Outcome():{ String string; }{ string = parse_String() { return new Outcome(string); } } public Value parse_Value():{ }{ "VAL" { return new Value(); } } public Predicate parse_Predicate():{ String pred; }{ "pred" pred = parse_String() { return new Predicate(pred); } } public Belief parse_Belief():{ Predicate predicate; float fraction; }{ "belief" predicate = parse_Predicate() fraction = parse_float() { return new Belief(predicate,fraction); } } public Challenge parse_Challenge():{ String name; Price price; Belief belief; }{ "challenge" "[" name = parse_String() price = parse_Price() belief = parse_Belief() "]" { return new Challenge(name,price,belief); } } public QualifiedProblem parse_QualifiedProblem():{ Predicate predicate; Problem instance; }{ "problem" "[" predicate = parse_Predicate() instance = parse_Problem() "]" { return new QualifiedProblem(predicate,instance); } } public Problem parse_Problem():{ String string; }{ string = parse_String() { return new Problem(string); } } public SolvedProblem parse_SolvedProblem():{ QualifiedProblem rm; Outcome ip; Quality quality; }{ "solved" "[" rm = parse_QualifiedProblem() ip = parse_Outcome() quality = parse_Quality() "]" { return new SolvedProblem(rm,ip,quality); } } public Price parse_Price():{ double val; }{ val = parse_double() { return new Price(val); } } public Quality parse_Quality():{ double val; }{ val = parse_double() { return new Quality(val); } } public History parse_History():{ List rounds; }{ "history" "[" rounds = parse_List$Round$() "]" { return new History(rounds); } } public Round parse_Round():{ List ptransactions; }{ "round" "[" ptransactions = parse_List$PlayerTransaction$() "]" { return new Round(ptransactions); } } public PlayerTransaction parse_PlayerTransaction():{ String playerName; List transactions; }{ playerName = parse_String() transactions = parse_List$Transaction$() { return new PlayerTransaction(playerName,transactions); } } public Transaction parse_Transaction():{ TransactionType ttype; Challenge challenge; }{ ttype = parse_TransactionType() challenge = parse_Challenge() { return new Transaction(ttype,challenge); } } public TransactionType parse_TransactionType():{ TransactionType sup = null; }{ ( sup = parse_Buy() { return sup; } | sup = parse_Create() { return sup; } | sup = parse_Reoffer() { return sup; } | sup = parse_Deliver() { return sup; } | sup = parse_Finish() { return sup; } ) } public Buy parse_Buy():{ }{ "BUY" { return new Buy(); } } public Create parse_Create():{ }{ "CREATE" { return new Create(); } } public Reoffer parse_Reoffer():{ }{ "REOFFER" { return new Reoffer(); } } public Deliver parse_Deliver():{ }{ "DELIVER" { return new Deliver(); } } public Finish parse_Finish():{ }{ "FINISH" { return new Finish(); } } public SCG parse_SCG():{ List players; List> account; List> store; Config config; }{ "SCG" "players" players = parse_List$Player$() "accounts" account = parse_List$Pair$PlayerID$Double$$() "store" store = parse_List$Pair$PlayerID$PlayerStore$$() "config" config = parse_Config() { return new SCG(players,account,store,config); } } public Player parse_Player():{ PlayerID id; String name; }{ "player" id = parse_PlayerID() name = parse_String() { return new Player(id,name); } } public PlayerStore parse_PlayerStore():{ List forSale; List bought; }{ "pstore" forSale = parse_List$Challenge$() bought = parse_List$BoughtDeriv$() { return new PlayerStore(forSale,bought); } } public BoughtDeriv parse_BoughtDeriv():{ Challenge d; PlayerID seller; Option r; Option f; }{ "bought" d = parse_Challenge() seller = parse_PlayerID() r = parse_Option$QualifiedProblem$() f = parse_Option$SolvedProblem$() { return new BoughtDeriv(d,seller,r,f); } } public Config parse_Config():{ double init; int maxTurns; int timeslot; double mindec; }{ init = parse_double() maxTurns = parse_int() timeslot = parse_int() mindec = parse_double() { return new Config(init,maxTurns,timeslot,mindec); } } public PlayerID parse_PlayerID():{ int id; }{ id = parse_int() { return new PlayerID(id); } } public Option parse_Option$SolvedProblem$():{ Option sup = null; }{ ( sup = parse_Some$SolvedProblem$() { return sup; } | sup = parse_None$SolvedProblem$() { return sup; } ) } public None parse_None$SolvedProblem$():{ }{ { return new None(); } } public Some parse_Some$SolvedProblem$():{ SolvedProblem just; }{ just = parse_SolvedProblem() { return new Some(just); } } public Option parse_Option$QualifiedProblem$():{ Option sup = null; }{ ( sup = parse_Some$QualifiedProblem$() { return sup; } | sup = parse_None$QualifiedProblem$() { return sup; } ) } public None parse_None$QualifiedProblem$():{ }{ { return new None(); } } public Some parse_Some$QualifiedProblem$():{ QualifiedProblem just; }{ just = parse_QualifiedProblem() { return new Some(just); } } public List parse_List$BoughtDeriv$():{ List sup = null; }{ ( sup = parse_Cons$BoughtDeriv$() { return sup; } | sup = parse_Empty$BoughtDeriv$() { return sup; } ) } public Empty parse_Empty$BoughtDeriv$():{ }{ { return new Empty(); } } public Cons parse_Cons$BoughtDeriv$():{ BoughtDeriv first; List rest; }{ first = parse_BoughtDeriv() rest = parse_List$BoughtDeriv$() { return new Cons(first,rest); } } public List parse_List$Challenge$():{ List sup = null; }{ ( sup = parse_Cons$Challenge$() { return sup; } | sup = parse_Empty$Challenge$() { return sup; } ) } public Empty parse_Empty$Challenge$():{ }{ { return new Empty(); } } public Cons parse_Cons$Challenge$():{ Challenge first; List rest; }{ first = parse_Challenge() rest = parse_List$Challenge$() { return new Cons(first,rest); } } public List> parse_List$Pair$PlayerID$PlayerStore$$():{ List> sup = null; }{ ( sup = parse_Cons$Pair$PlayerID$PlayerStore$$() { return sup; } | sup = parse_Empty$Pair$PlayerID$PlayerStore$$() { return sup; } ) } public Empty> parse_Empty$Pair$PlayerID$PlayerStore$$():{ }{ { return new Empty>(); } } public Cons> parse_Cons$Pair$PlayerID$PlayerStore$$():{ Pair first; List> rest; }{ first = parse_Pair$PlayerID$PlayerStore$() rest = parse_List$Pair$PlayerID$PlayerStore$$() { return new Cons>(first,rest); } } public Pair parse_Pair$PlayerID$PlayerStore$():{ PlayerID a; PlayerStore b; }{ a = parse_PlayerID() b = parse_PlayerStore() { return new Pair(a,b); } } public List> parse_List$Pair$PlayerID$Double$$():{ List> sup = null; }{ ( sup = parse_Cons$Pair$PlayerID$Double$$() { return sup; } | sup = parse_Empty$Pair$PlayerID$Double$$() { return sup; } ) } public Empty> parse_Empty$Pair$PlayerID$Double$$():{ }{ { return new Empty>(); } } public Cons> parse_Cons$Pair$PlayerID$Double$$():{ Pair first; List> rest; }{ first = parse_Pair$PlayerID$Double$() rest = parse_List$Pair$PlayerID$Double$$() { return new Cons>(first,rest); } } public Pair parse_Pair$PlayerID$Double$():{ PlayerID a; Double b; }{ a = parse_PlayerID() b = parse_Double() { return new Pair(a,b); } } public List parse_List$Player$():{ List sup = null; }{ ( sup = parse_Cons$Player$() { return sup; } | sup = parse_Empty$Player$() { return sup; } ) } public Empty parse_Empty$Player$():{ }{ { return new Empty(); } } public Cons parse_Cons$Player$():{ Player first; List rest; }{ first = parse_Player() rest = parse_List$Player$() { return new Cons(first,rest); } } public List parse_List$Transaction$():{ List sup = null; }{ ( sup = parse_Cons$Transaction$() { return sup; } | sup = parse_Empty$Transaction$() { return sup; } ) } public Empty parse_Empty$Transaction$():{ }{ { return new Empty(); } } public Cons parse_Cons$Transaction$():{ Transaction first; List rest; }{ first = parse_Transaction() rest = parse_List$Transaction$() { return new Cons(first,rest); } } public List parse_List$PlayerTransaction$():{ List sup = null; }{ ( sup = parse_Cons$PlayerTransaction$() { return sup; } | sup = parse_Empty$PlayerTransaction$() { return sup; } ) } public Empty parse_Empty$PlayerTransaction$():{ }{ { return new Empty(); } } public Cons parse_Cons$PlayerTransaction$():{ PlayerTransaction first; List rest; }{ first = parse_PlayerTransaction() rest = parse_List$PlayerTransaction$() { return new Cons(first,rest); } } public List parse_List$Round$():{ List sup = null; }{ ( sup = parse_Cons$Round$() { return sup; } | sup = parse_Empty$Round$() { return sup; } ) } public Empty parse_Empty$Round$():{ }{ { return new Empty(); } } public Cons parse_Cons$Round$():{ Round first; List rest; }{ first = parse_Round() rest = parse_List$Round$() { return new Cons(first,rest); } } SKIP : { " " | "\t" | "\n" | "\r" | "\r\n" } SKIP : { < "//" (~["\n","\r"])* ("\n"|"\r\n") > | < "/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/" > } TOKEN: { < TRUE : "true" > | < FALSE : "false" > } TOKEN: { < INT : ("+" | "-")? ( (["0"-"9"])+ | ("0" ["x","X"]) (["0"-"9","a"-"f","A"-"F"])+ ) > | < DOUBLE : ("-")?(["0"-"9"])+ "." (["0"-"9"])+ ()? | "." (["0"-"9"])+ ()? > | < #EXPON: ["e","E"] (["+","-"])? (["0"-"9"])+ > } 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","_","$"])* > }