// ** This file was generated with DemFGen (vers:12/15/2010) options{ STATIC = false; } PARSER_BEGIN(TheParser) package protocol; import edu.neu.ccs.demeterf.lib.*; import edu.neu.ccs.demeterf.lib.*; import java.lang.reflect.*; import edu.neu.ccs.demeterf.lib.*; import edu.neu.ccs.demeterf.lib.*; import java.lang.reflect.*; import scg.*; 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 = { 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 ForAllExists parse_ForAllExists():{ }{ { return new ForAllExists(); } } public ExistsForAll parse_ExistsForAll():{ }{ { return new ExistsForAll(); } } public PositiveSecret parse_PositiveSecret():{ }{ { return new PositiveSecret(); } } public NegativeSecret parse_NegativeSecret():{ }{ { return new NegativeSecret(); } } public Renaissance parse_Renaissance():{ }{ { return new Renaissance(); } } public SecretRenaissance parse_SecretRenaissance():{ }{ { return new SecretRenaissance(); } } public FullyQualifiedClassName parse_FullyQualifiedClassName():{ ident name; List rest; }{ name = parse_ident() rest = parse_List$Qualifier$() { return new FullyQualifiedClassName(name,rest); } } public Qualifier parse_Qualifier():{ ident name; }{ "." name = parse_ident() { return new Qualifier(name); } } public DomainI parse_DomainI():{ DomainI sup = null; }{ ( { return sup; } ) } public InstanceI parse_InstanceI():{ InstanceI sup = null; }{ ( { return sup; } ) } public SolutionI parse_SolutionI():{ SolutionI sup = null; }{ ( { return sup; } ) } public InstanceSetI parse_InstanceSetI():{ InstanceSetI sup = null; }{ ( { return sup; } ) } public Instance parse_Instance():{ FullyQualifiedClassName instanceClassName; InstanceI instance; verbatim instanceSpec; }{ instanceClassName = parse_FullyQualifiedClassName() instance = parse_InstanceI() instanceSpec = parse_verbatim() { return new Instance(instanceClassName,instance,instanceSpec); } } public InstanceSet parse_InstanceSet():{ FullyQualifiedClassName instanceSetClassName; InstanceSetI instanceSet; verbatim instanceSetSpec; }{ instanceSetClassName = parse_FullyQualifiedClassName() instanceSet = parse_InstanceSetI() instanceSetSpec = parse_verbatim() { return new InstanceSet(instanceSetClassName,instanceSet,instanceSetSpec); } } public Solution parse_Solution():{ FullyQualifiedClassName solutionClassName; SolutionI solution; verbatim solutionSpec; }{ solutionClassName = parse_FullyQualifiedClassName() solution = parse_SolutionI() solutionSpec = parse_verbatim() { return new Solution(solutionClassName,solution,solutionSpec); } } public Claim parse_Claim():{ InstanceSet instanceSet; FullyQualifiedClassName protocolClassName; ProtocolI protocol; double quality; }{ instanceSet = parse_InstanceSet() protocolClassName = parse_FullyQualifiedClassName() protocol = parse_ProtocolI() quality = parse_double() { return new Claim(instanceSet,protocolClassName,protocol,quality); } } public ProtocolI parse_ProtocolI():{ ProtocolI sup = null; }{ ( { return sup; } ) } public ProtocolSpec parse_ProtocolSpec():{ List steps; }{ steps = parse_List$Step$() { return new ProtocolSpec(steps); } } public Step parse_Step():{ Action action; Role role; }{ action = parse_Action() "from" role = parse_Role() { return new Step(action,role); } } public Role parse_Role():{ Role sup = null; }{ ( sup = parse_Alice() { return sup; } | sup = parse_Bob() { return sup; } ) } public Alice parse_Alice():{ }{ "Alice" { return new Alice(); } } public Bob parse_Bob():{ }{ "Bob" { return new Bob(); } } public Action parse_Action():{ Action sup = null; }{ ( sup = parse_ProvideAction() { return sup; } | sup = parse_SolveAction() { return sup; } ) } public ProvideAction parse_ProvideAction():{ }{ "instance" { return new ProvideAction(); } } public SolveAction parse_SolveAction():{ int stepNo; }{ "solution" "of" stepNo = parse_int() { return new SolveAction(stepNo); } } public PlayerRequest parse_PlayerRequest():{ Request request; }{ "request[" request = parse_Request() "]" { return new PlayerRequest(request); } } public Request parse_Request():{ Request sup = null; }{ ( sup = parse_ProposeRequest() { return sup; } | sup = parse_OpposeRequest() { return sup; } | sup = parse_ProvideRequest() { return sup; } | sup = parse_SolveRequest() { return sup; } ) } public PlayerResponse parse_PlayerResponse():{ Response transaction; }{ "transaction[" transaction = parse_Response() "]" { return new PlayerResponse(transaction); } } public Response parse_Response():{ Response sup = null; }{ ( sup = parse_ProposeResponse() { return sup; } | sup = parse_OpposeResponse() { return sup; } | sup = parse_ProvideResponse() { return sup; } | sup = parse_SolveResponse() { return sup; } ) } public ProposeRequest parse_ProposeRequest():{ List forbidden; }{ "propose" forbidden = parse_List$Claim$() { return new ProposeRequest(forbidden); } } public OpposeRequest parse_OpposeRequest():{ List claims; }{ "oppose" claims = parse_List$Claim$() { return new OpposeRequest(claims); } } public ProvideRequest parse_ProvideRequest():{ Claim claim; }{ "provide" claim = parse_Claim() { return new ProvideRequest(claim); } } public SolveRequest parse_SolveRequest():{ Instance instance; Option claim; }{ "solve" instance = parse_Instance() claim = parse_Option$Claim$() { return new SolveRequest(instance,claim); } } public ProposeResponse parse_ProposeResponse():{ List claims; }{ "propose" claims = parse_List$Claim$() { return new ProposeResponse(claims); } } public OpposeResponse parse_OpposeResponse():{ List oppositions; }{ "oppose" oppositions = parse_List$OpposeAction$() { return new OpposeResponse(oppositions); } } public OpposeAction parse_OpposeAction():{ OpposeAction sup = null; }{ ( sup = parse_NoOpposition() { return sup; } | sup = parse_Strengthening() { return sup; } | sup = parse_Refuting() { return sup; } ) } public NoOpposition parse_NoOpposition():{ }{ "no" "opposition" { return new NoOpposition(); } } public Strengthening parse_Strengthening():{ double newQuality; }{ "strengthening" newQuality = parse_double() { return new Strengthening(newQuality); } } public Refuting parse_Refuting():{ }{ "refuting" { return new Refuting(); } } public ProvideResponse parse_ProvideResponse():{ Instance instance; }{ "provide" instance = parse_Instance() { return new ProvideResponse(instance); } } public SolveResponse parse_SolveResponse():{ Instance instance; }{ "solve" instance = parse_Instance() { return new SolveResponse(instance); } } public RBColor parse_RBColor():{ RBColor sup = null; }{ ( sup = parse_RED() { return sup; } | sup = parse_BLACK() { return sup; } ) } public RED parse_RED():{ }{ "red" { return new RED(); } } public BLACK parse_BLACK():{ }{ "black" { return new BLACK(); } } public List parse_List$OpposeAction$():{ List sup = null; }{ ( sup = parse_Cons$OpposeAction$() { return sup; } | sup = parse_Empty$OpposeAction$() { return sup; } ) } public Empty parse_Empty$OpposeAction$():{ }{ { return new Empty(); } } public Cons parse_Cons$OpposeAction$():{ OpposeAction first; List rest; }{ first = parse_OpposeAction() rest = parse_List$OpposeAction$() { return new Cons(first,rest); } } public List parse_List$Claim$():{ List sup = null; }{ ( sup = parse_Cons$Claim$() { return sup; } | sup = parse_Empty$Claim$() { return sup; } ) } public Empty parse_Empty$Claim$():{ }{ { return new Empty(); } } public Cons parse_Cons$Claim$():{ Claim first; List rest; }{ first = parse_Claim() rest = parse_List$Claim$() { return new Cons(first,rest); } } public Option parse_Option$Claim$():{ Option sup = null; }{ ( sup = parse_Some$Claim$() { return sup; } | sup = parse_None$Claim$() { return sup; } ) } public None parse_None$Claim$():{ }{ { return new None(); } } public Some parse_Some$Claim$():{ Claim just; }{ just = parse_Claim() { return new Some(just); } } public List parse_List$Step$():{ List sup = null; }{ ( sup = parse_Cons$Step$() { return sup; } | sup = parse_Empty$Step$() { return sup; } ) } public Empty parse_Empty$Step$():{ }{ { return new Empty(); } } public Cons parse_Cons$Step$():{ Step first; List rest; }{ first = parse_Step() rest = parse_List$Step$() { return new Cons(first,rest); } } public List parse_List$Qualifier$():{ List sup = null; }{ ( sup = parse_Cons$Qualifier$() { return sup; } | sup = parse_Empty$Qualifier$() { return sup; } ) } public Empty parse_Empty$Qualifier$():{ }{ { return new Empty(); } } public Cons parse_Cons$Qualifier$():{ Qualifier first; List rest; }{ first = parse_Qualifier() rest = parse_List$Qualifier$() { return new Cons(first,rest); } } 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"])+ > } 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","_","$"])* > }