options { STATIC = false; JAVA_UNICODE_ESCAPE = true; } PARSER_BEGIN(Parser) import edu.neu.ccs.demeter.*; public class Parser { // oit is uugly. Why isn't there a Character.valueOf(String)? static char unescapifyChar(String s) { char c = s.charAt(0); if (c == '\\') { switch (s.charAt(1)) { case 'n': c = '\n'; break; case 't': c = '\t'; break; case 'b': c = '\b'; break; case 'r': c = '\r'; break; case 'f': c = '\f'; break; case '\\': c = '\\'; break; case '\'': c = '\''; break; case '\"': c = '\"'; break; default: c = (char) Integer.parseInt(s.substring(1, s.length()), 8); break; } } return c; } // Even uglier... static String unescapify(String s) { char str[] = new char[s.length()]; int i = 0, o = 0; while (i < s.length()) { char c = s.charAt(i++); if (c == '\\') { int j = i + 1; while (j < s.length() && Character.digit(s.charAt(j), 8) != -1) { j++; } c = unescapifyChar(s.substring(i-1, j)); i = j; } str[o++] = c; } return String.valueOf(str, 0, o); } } PARSER_END(Parser) Main _Main() : { Main it = null; String _s; } { { it=new Main(); } _s=_String() { it.set_s(_s); } { return it; } } PathwayModelingLanguage _PathwayModelingLanguage() : { PathwayModelingLanguage it = null; DomDecl_List _domains; GrpDecl_List _groups; ComDecl_List _compartments; } { { it=new PathwayModelingLanguage(); } _domains=_DomDecl_List() { it.set_domains(_domains); } _groups=_GrpDecl_List() { it.set_groups(_groups); } _compartments=_ComDecl_List() { it.set_compartments(_compartments); } { return it; } } DomDecl _DomDecl() : { DomDecl it = null; DomainId _domainid; DomExp _domexp; } { { it=new DomDecl(); } "domain" _domainid=_DomainId() { it.set_domainid(_domainid); } "=" _domexp=_DomExp() { it.set_domexp(_domexp); } { return it; } } DomExp _DomExp() : { DomExp it = null; } { ( it=_DomainExpression() | it=_DomainId() ) { return it; } } void common_DomExp(DomExp it) : { } { { } } DomainExpression _DomainExpression() : { DomainExpression it = null; Bridge _bridge; SiteId_Seq _siteid_seq; DomDesc _domdesc; RuleId_Seq _ruleid_seq; } { { it=new DomainExpression(); } [ _bridge=_Bridge() { it.set_bridge(_bridge); } ] "dom" _siteid_seq=_SiteId_Seq() { it.set_siteid_seq(_siteid_seq); } _domdesc=_DomDesc() { it.set_domdesc(_domdesc); } "init" "=" "[" _ruleid_seq=_RuleId_Seq() { it.set_ruleid_seq(_ruleid_seq); } "]" "end" common_DomExp(it) { return it; } } DomDesc _DomDesc() : { DomDesc it = null; } { { it=new DomDesc(); } "domdesc" { return it; } } Bridge _Bridge() : { Bridge it = null; } { { it=new Bridge(); } "bridge" { return it; } } GrpDecl _GrpDecl() : { GrpDecl it = null; GroupId _groupid; GrpExp _grpexp; } { { it=new GrpDecl(); } "group" _groupid=_GroupId() { it.set_groupid(_groupid); } "=" _grpexp=_GrpExp() { it.set_grpexp(_grpexp); } { return it; } } GrpExp _GrpExp() : { GrpExp it = null; } { { it=new GrpExp(); } "grpexp" { return it; } } ComDecl _ComDecl() : { ComDecl it = null; CompartmentId _compartmentid; ComExp _comexp; } { { it=new ComDecl(); } "compartment" _compartmentid=_CompartmentId() { it.set_compartmentid(_compartmentid); } "=" _comexp=_ComExp() { it.set_comexp(_comexp); } { return it; } } ComExp _ComExp() : { ComExp it = null; } { { it=new ComExp(); } "comexp" { return it; } } SiteId _SiteId() : { SiteId it = null; Ident _ident; } { { it=new SiteId(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } RuleId _RuleId() : { RuleId it = null; Ident _ident; } { { it=new RuleId(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } DomainId _DomainId() : { DomainId it = null; Ident _ident; } { { it=new DomainId(); } _ident=_Ident() { it.set_ident(_ident); } common_DomExp(it) { return it; } } GroupId _GroupId() : { GroupId it = null; Ident _ident; } { { it=new GroupId(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } CompartmentId _CompartmentId() : { CompartmentId it = null; Ident _ident; } { { it=new CompartmentId(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } DomDecl_List _DomDecl_List() : { DomDecl_List it = null; Nonempty_DomDecl_List _first; } { { it=new DomDecl_List(); } [ _first=_Nonempty_DomDecl_List() { it.set_first(_first); } ] { return it; } } GrpDecl_List _GrpDecl_List() : { GrpDecl_List it = null; Nonempty_GrpDecl_List _first; } { { it=new GrpDecl_List(); } [ _first=_Nonempty_GrpDecl_List() { it.set_first(_first); } ] { return it; } } ComDecl_List _ComDecl_List() : { ComDecl_List it = null; Nonempty_ComDecl_List _first; } { { it=new ComDecl_List(); } [ _first=_Nonempty_ComDecl_List() { it.set_first(_first); } ] { return it; } } SiteId_Seq _SiteId_Seq() : { SiteId_Seq it = null; Nonempty_SiteId_Seq _first; } { { it=new SiteId_Seq(); } "(" _first=_Nonempty_SiteId_Seq() { it.set_first(_first); } ")" { return it; } } RuleId_Seq _RuleId_Seq() : { RuleId_Seq it = null; Nonempty_RuleId_Seq _first; } { { it=new RuleId_Seq(); } "(" _first=_Nonempty_RuleId_Seq() { it.set_first(_first); } ")" { return it; } } Nonempty_DomDecl_List _Nonempty_DomDecl_List() : { Nonempty_DomDecl_List it = null; DomDecl _it; Nonempty_DomDecl_List _next; } { { it=new Nonempty_DomDecl_List(); } _it=_DomDecl() { it.set_it(_it); } [ _next=_Nonempty_DomDecl_List() { it.set_next(_next); } ] { return it; } } Nonempty_GrpDecl_List _Nonempty_GrpDecl_List() : { Nonempty_GrpDecl_List it = null; GrpDecl _it; Nonempty_GrpDecl_List _next; } { { it=new Nonempty_GrpDecl_List(); } _it=_GrpDecl() { it.set_it(_it); } [ _next=_Nonempty_GrpDecl_List() { it.set_next(_next); } ] { return it; } } Nonempty_ComDecl_List _Nonempty_ComDecl_List() : { Nonempty_ComDecl_List it = null; ComDecl _it; Nonempty_ComDecl_List _next; } { { it=new Nonempty_ComDecl_List(); } _it=_ComDecl() { it.set_it(_it); } [ _next=_Nonempty_ComDecl_List() { it.set_next(_next); } ] { return it; } } Nonempty_SiteId_Seq _Nonempty_SiteId_Seq() : { Nonempty_SiteId_Seq it = null; SiteId _it; Nonempty_SiteId_Seq _next; } { { it=new Nonempty_SiteId_Seq(); } _it=_SiteId() { it.set_it(_it); } [ "," _next=_Nonempty_SiteId_Seq() { it.set_next(_next); } ] { return it; } } Nonempty_RuleId_Seq _Nonempty_RuleId_Seq() : { Nonempty_RuleId_Seq it = null; RuleId _it; Nonempty_RuleId_Seq _next; } { { it=new Nonempty_RuleId_Seq(); } _it=_RuleId() { it.set_it(_it); } [ "," _next=_Nonempty_RuleId_Seq() { it.set_next(_next); } ] { return it; } } boolean _boolean() : { Token t; }{ ( t= { return true; } | t= { return false; } ) } char _char() : { Token t; } { t= { String s = t.image; return unescapifyChar(s.substring(1, s.length()-1)); } } byte _byte() : { int i; } { i=_int() { return (byte) i; } } short _short() : { int i; } { i=_int() { return (short) i; } } int _int() : { Number num; } { num=_Number() { return num.intValue(); } } long _long() : { Number num; } { num=_Number() { return num.longValue(); } } float _float() : { Number num; } { num=_Number() { return num.floatValue(); } } double _double() : { Number num; } { num=_Number() { return num.doubleValue(); } } Boolean _Boolean() : { Token t; }{ ( t= { return Boolean.TRUE; } | t= { return Boolean.FALSE; } ) } Character _Character() : { char c; } { c=_char() { return new Character(c); } } Integer _Integer() : { int i; } { i = _int() { return new Integer(i); } } Long _Long() : { long l; } { l=_long() { return new Long(l); } } Float _Float() : { float f; } { f=_float() { return new Float(f); } } Double _Double() : { double d; } { d=_double() { return new Double(d); } } Number _Number() : { Token t; String s = null; int radix = 0; Number num = null; } { ( ( t= { s = t.image; radix = 10; } | t= { // Strip off the "0x". s = t.image.substring(2, t.image.length()); radix = 16; } | t= { s = t.image; radix = 8; } ) { switch (s.charAt(s.length()-1)) { case 'l': case 'L': s = s.substring(0, s.length()-1); num = new Long(new java.math.BigInteger(s, radix).longValue()); break; default: num = new Integer(new java.math.BigInteger(s, radix).intValue()); break; } } | t= { s = t.image; switch (s.charAt(s.length()-1)) { case 'd': case 'D': num = Double.valueOf(s.substring(0, s.length()-1)); break; case 'f': case 'F': num = Float.valueOf(s.substring(0, s.length()-1)); break; default: num = Float.valueOf(s); break; } } ) { return num; } } String _String() : { Token t; } { t= { String s = t.image; return unescapify(s.substring(1, s.length()-1)); } } StringBuffer _StringBuffer() : { String s; } { s=_String() { return new StringBuffer(s); } } Ident _Ident() : { Token t; } { t= { return new Ident(t.image); } } Text _Text() : { Token t; } { t= { String s = t.image; return new Text(s.substring(2, s.length()-2)); } } Line _Line() : { Token t; } { { token_source.SwitchTo(1); } t= { return new Line(t.image); } } Word _Word() : { Token t; } { { token_source.SwitchTo(2); } t= { return new Word(t.image); } } // Lexical specification (largely taken from Java.jack): SKIP : { " " | "\t" | "\n" | "\r" | <"//" (~["\n","\r"])* ("\n"|"\r\n")> | <"/*" (~["*"])* "*" (~["/"] (~["*"])* "*")* "/"> } TOKEN : { /* LITERALS */ < DECIMAL_LITERAL: ["1"-"9"] (["0"-"9"])* (["l","L"])? > | < HEX_LITERAL: "0" ["x","X"] (["0"-"9","a"-"f","A"-"F"])+ (["l","L"])? > | < OCTAL_LITERAL: "0" (["0"-"7"])* (["l","L"])? > | < FLOATING_POINT_LITERAL: (["0"-"9"])+ "." (["0"-"9"])+ ()? (["f","F","d","D"])? | "." (["0"-"9"])+ ()? (["f","F","d","D"])? | (["0"-"9"])+ (["f","F","d","D"])? | (["0"-"9"])+ ()? ["f","F","d","D"] > | < #EXPONENT: ["e","E"] (["+","-"])? (["0"-"9"])+ > | < CHARACTER_LITERAL: "'" ( (~["\'","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) ) "'" > | < STRING_LITERAL: "\"" ( (~["\"","\\","\n","\r"]) | ("\\" ( ["n","t","b","r","f","\\","\'","\""] | ["0"-"7"] ( ["0"-"7"] )? | ["0"-"3"] ["0"-"7"] ["0"-"7"] ) ) )* "\"" > | < TEXT_LITERAL: ( "(@" (~["@"])* ( "@" ~[")"] (~["@"])* )* "@)" ) | ( "{{" (~["}"])* ( "}" ~["}"] (~["}"])* )* "}}" ) > | < TRUE: "true" > | < FALSE: "false" > } TOKEN : { /* IDENTIFIERS */ < IDENTIFIER: (|)* > | < #LETTER: [ "\u0024", "\u0041"-"\u005a", "\u005f", "\u0061"-"\u007a", "\u00c0"-"\u00d6", "\u00d8"-"\u00f6", "\u00f8"-"\u00ff", "\u0100"-"\u1fff", "\u3040"-"\u318f", "\u3300"-"\u337f", "\u3400"-"\u3d2d", "\u4e00"-"\u9fff", "\uf900"-"\ufaff" ] > | < #DIGIT: [ "\u0030"-"\u0039", "\u0660"-"\u0669", "\u06f0"-"\u06f9", "\u0966"-"\u096f", "\u09e6"-"\u09ef", "\u0a66"-"\u0a6f", "\u0ae6"-"\u0aef", "\u0b66"-"\u0b6f", "\u0be7"-"\u0bef", "\u0c66"-"\u0c6f", "\u0ce6"-"\u0cef", "\u0d66"-"\u0d6f", "\u0e50"-"\u0e59", "\u0ed0"-"\u0ed9", "\u1040"-"\u1049" ] > } TOKEN : { < LINE: (~["\n","\r"])* > : DEFAULT } SKIP : { " " | "\t" | "\n" | "\r" } TOKEN : { < WORD: (~[" ","\t","\n","\r"])* > : DEFAULT }