options { STATIC = false; JAVA_UNICODE_ESCAPE = true; } PARSER_BEGIN(Parser) import java.lang.*; import java.io.*; import edu.neu.ccs.demeter.dj.*; import java.util.*; 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) Bank _Bank() : { Bank it = null; BusinessUnit_List _businessunit_list; } { { it=new Bank(); } _businessunit_list=_BusinessUnit_List() { it.set_businessunit_list(_businessunit_list); } { return it; } } BusinessUnit _BusinessUnit() : { BusinessUnit it = null; Index _index; Country _country; Location _location; Party_List _party_list; } { { it=new BusinessUnit(); } _index=_Index() { it.set_index(_index); } _country=_Country() { it.set_country(_country); } _location=_Location() { it.set_location(_location); } _party_list=_Party_List() { it.set_party_list(_party_list); } { return it; } } Party _Party() : { Party it = null; } { ( it=_Individual() | it=_CorporateBody() ) { return it; } } void common_Party(Party it) : { Agreement _agreement; PartyId _partyid; } { _agreement=_Agreement() { it.set_agreement(_agreement); } _partyid=_PartyId() { it.set_partyid(_partyid); } { } } Individual _Individual() : { Individual it = null; FirstName _firstname; LastName _lastname; Date _birthdate; } { { it=new Individual(); } "individual" _firstname=_FirstName() { it.set_firstname(_firstname); } _lastname=_LastName() { it.set_lastname(_lastname); } _birthdate=_Date() { it.set_birthdate(_birthdate); } common_Party(it) { return it; } } CorporateBody _CorporateBody() : { CorporateBody it = null; CompanyName _companyname; Rating _rating; } { { it=new CorporateBody(); } "corporate" _companyname=_CompanyName() { it.set_companyname(_companyname); } _rating=_Rating() { it.set_rating(_rating); } common_Party(it) { return it; } } Agreement _Agreement() : { Agreement it = null; Contract_List _contract_list; Agr_Rule_List _agr_rule_list; Day _statement_ending; } { { it=new Agreement(); } _contract_list=_Contract_List() { it.set_contract_list(_contract_list); } _agr_rule_list=_Agr_Rule_List() { it.set_agr_rule_list(_agr_rule_list); } _statement_ending=_Day() { it.set_statement_ending(_statement_ending); } { return it; } } FirstName _FirstName() : { FirstName it = null; String _string; } { { it=new FirstName(); } _string=_String() { it.set_string(_string); } { return it; } } LastName _LastName() : { LastName it = null; String _string; } { { it=new LastName(); } _string=_String() { it.set_string(_string); } { return it; } } CompanyName _CompanyName() : { CompanyName it = null; String _string; } { { it=new CompanyName(); } _string=_String() { it.set_string(_string); } { return it; } } PartyId _PartyId() : { PartyId it = null; int _partyId; } { { it=new PartyId(); } _partyId=_int() { it.set_partyId(_partyId); } { return it; } } Rating _Rating() : { Rating it = null; } { ( it=_C0() | it=_C1() | it=_C9() | it=_D0() | it=_D1() | it=_D3() | it=_D4() ) { return it; } } void common_Rating(Rating it) : { } { { } } Contract _Contract() : { Contract it = null; Index _index; Location _location; Portfolio_List _portfolios; } { { it=new Contract(); } _index=_Index() { it.set_index(_index); } _location=_Location() { it.set_location(_location); } _portfolios=_Portfolio_List() { it.set_portfolios(_portfolios); } { return it; } } Agr_Rule _Agr_Rule() : { Agr_Rule it = null; Rule _rule; Description _description; } { { it=new Agr_Rule(); } _rule=_Rule() { it.set_rule(_rule); } _description=_Description() { it.set_description(_description); } { return it; } } Rule _Rule() : { Rule it = null; boolean _rule; } { { it=new Rule(); } _rule=_boolean() { it.set_rule(_rule); } { return it; } } Portfolio _Portfolio() : { Portfolio it = null; Index _index; Description _description; Account_List _accounts; } { { it=new Portfolio(); } _index=_Index() { it.set_index(_index); } _description=_Description() { it.set_description(_description); } _accounts=_Account_List() { it.set_accounts(_accounts); } { return it; } } Account _Account() : { Account it = null; Posting_List _postings; AccountID _accountid; AccountType _accounttype; Agreement _agreement; } { { it=new Account(); } _postings=_Posting_List() { it.set_postings(_postings); } _accountid=_AccountID() { it.set_accountid(_accountid); } _accounttype=_AccountType() { it.set_accounttype(_accounttype); } [ _agreement=_Agreement() { it.set_agreement(_agreement); } ] { return it; } } Posting _Posting() : { Posting it = null; } { ( it=_Credit() | it=_Debit() ) { return it; } } void common_Posting(Posting it) : { Amount _amount; Date _date; } { _amount=_Amount() { it.set_amount(_amount); } _date=_Date() { it.set_date(_date); } { } } AccountID _AccountID() : { AccountID it = null; int _account_id; } { { it=new AccountID(); } _account_id=_int() { it.set_account_id(_account_id); } { return it; } } Amount _Amount() : { Amount it = null; int _amount; } { { it=new Amount(); } _amount=_int() { it.set_amount(_amount); } { return it; } } Credit _Credit() : { Credit it = null; } { { it=new Credit(); } "credit" common_Posting(it) { return it; } } Debit _Debit() : { Debit it = null; } { { it=new Debit(); } "debit" common_Posting(it) { return it; } } AccountType _AccountType() : { AccountType it = null; } { ( it=_Savings() | it=_Checking() | it=_Overdraft() | it=_CD() | it=_Loan() ) { return it; } } void common_AccountType(AccountType it) : { } { { } } Savings _Savings() : { Savings it = null; } { { it=new Savings(); } "savings" common_AccountType(it) { return it; } } Checking _Checking() : { Checking it = null; } { { it=new Checking(); } "checking" common_AccountType(it) { return it; } } Overdraft _Overdraft() : { Overdraft it = null; } { { it=new Overdraft(); } "overdraft" common_AccountType(it) { return it; } } CD _CD() : { CD it = null; } { { it=new CD(); } "cd" common_AccountType(it) { return it; } } Loan _Loan() : { Loan it = null; } { { it=new Loan(); } "loan" common_AccountType(it) { return it; } } Description _Description() : { Description it = null; String _string; } { { it=new Description(); } _string=_String() { it.set_string(_string); } { return it; } } Index _Index() : { Index it = null; int _index; } { { it=new Index(); } _index=_int() { it.set_index(_index); } { return it; } } Location _Location() : { Location it = null; String _string; } { { it=new Location(); } _string=_String() { it.set_string(_string); } { return it; } } Country _Country() : { Country it = null; String _string; } { { it=new Country(); } _string=_String() { it.set_string(_string); } { return it; } } Date _Date() : { Date it = null; Month _month; Day _day; Year _year; } { { it=new Date(); } _month=_Month() { it.set_month(_month); } _day=_Day() { it.set_day(_day); } _year=_Year() { it.set_year(_year); } { return it; } } Month _Month() : { Month it = null; int _month; } { { it=new Month(); } _month=_int() { it.set_month(_month); } { return it; } } Day _Day() : { Day it = null; int _day; } { { it=new Day(); } _day=_int() { it.set_day(_day); } { return it; } } Year _Year() : { Year it = null; int _year; } { { it=new Year(); } _year=_int() { it.set_year(_year); } { return it; } } C0 _C0() : { C0 it = null; } { { it=new C0(); } "c0" common_Rating(it) { return it; } } C1 _C1() : { C1 it = null; } { { it=new C1(); } "c1" common_Rating(it) { return it; } } C9 _C9() : { C9 it = null; } { { it=new C9(); } "c9" common_Rating(it) { return it; } } D0 _D0() : { D0 it = null; } { { it=new D0(); } "d0" common_Rating(it) { return it; } } D1 _D1() : { D1 it = null; } { { it=new D1(); } "d1" common_Rating(it) { return it; } } D3 _D3() : { D3 it = null; } { { it=new D3(); } "d3" common_Rating(it) { return it; } } D4 _D4() : { D4 it = null; } { { it=new D4(); } "d4" common_Rating(it) { return it; } } Main _Main() : { Main it = null; String _s; } { { it=new Main(); } _s=_String() { it.set_s(_s); } { return it; } } BusinessUnit_List _BusinessUnit_List() : { BusinessUnit_List it = null; Nonempty_BusinessUnit_List _first; } { { it=new BusinessUnit_List(); } "(" [ _first=_Nonempty_BusinessUnit_List() { it.set_first(_first); } ] ")" { return it; } } Party_List _Party_List() : { Party_List it = null; Nonempty_Party_List _first; } { { it=new Party_List(); } "(" [ _first=_Nonempty_Party_List() { it.set_first(_first); } ] ")" { return it; } } Contract_List _Contract_List() : { Contract_List it = null; Nonempty_Contract_List _first; } { { it=new Contract_List(); } "(" [ _first=_Nonempty_Contract_List() { it.set_first(_first); } ] ")" { return it; } } Agr_Rule_List _Agr_Rule_List() : { Agr_Rule_List it = null; Nonempty_Agr_Rule_List _first; } { { it=new Agr_Rule_List(); } "(" [ _first=_Nonempty_Agr_Rule_List() { it.set_first(_first); } ] ")" { return it; } } Portfolio_List _Portfolio_List() : { Portfolio_List it = null; Nonempty_Portfolio_List _first; } { { it=new Portfolio_List(); } "(" [ _first=_Nonempty_Portfolio_List() { it.set_first(_first); } ] ")" { return it; } } Account_List _Account_List() : { Account_List it = null; Nonempty_Account_List _first; } { { it=new Account_List(); } "(" [ _first=_Nonempty_Account_List() { it.set_first(_first); } ] ")" { return it; } } Posting_List _Posting_List() : { Posting_List it = null; Nonempty_Posting_List _first; } { { it=new Posting_List(); } "(" [ _first=_Nonempty_Posting_List() { it.set_first(_first); } ] ")" { return it; } } Nonempty_BusinessUnit_List _Nonempty_BusinessUnit_List() : { Nonempty_BusinessUnit_List it = null; BusinessUnit _it; Nonempty_BusinessUnit_List _next; } { { it=new Nonempty_BusinessUnit_List(); } _it=_BusinessUnit() { it.set_it(_it); } [ _next=_Nonempty_BusinessUnit_List() { it.set_next(_next); } ] { return it; } } Nonempty_Party_List _Nonempty_Party_List() : { Nonempty_Party_List it = null; Party _it; Nonempty_Party_List _next; } { { it=new Nonempty_Party_List(); } _it=_Party() { it.set_it(_it); } [ _next=_Nonempty_Party_List() { it.set_next(_next); } ] { return it; } } Nonempty_Contract_List _Nonempty_Contract_List() : { Nonempty_Contract_List it = null; Contract _it; Nonempty_Contract_List _next; } { { it=new Nonempty_Contract_List(); } _it=_Contract() { it.set_it(_it); } [ _next=_Nonempty_Contract_List() { it.set_next(_next); } ] { return it; } } Nonempty_Agr_Rule_List _Nonempty_Agr_Rule_List() : { Nonempty_Agr_Rule_List it = null; Agr_Rule _it; Nonempty_Agr_Rule_List _next; } { { it=new Nonempty_Agr_Rule_List(); } _it=_Agr_Rule() { it.set_it(_it); } [ _next=_Nonempty_Agr_Rule_List() { it.set_next(_next); } ] { return it; } } Nonempty_Portfolio_List _Nonempty_Portfolio_List() : { Nonempty_Portfolio_List it = null; Portfolio _it; Nonempty_Portfolio_List _next; } { { it=new Nonempty_Portfolio_List(); } _it=_Portfolio() { it.set_it(_it); } [ _next=_Nonempty_Portfolio_List() { it.set_next(_next); } ] { return it; } } Nonempty_Account_List _Nonempty_Account_List() : { Nonempty_Account_List it = null; Account _it; Nonempty_Account_List _next; } { { it=new Nonempty_Account_List(); } _it=_Account() { it.set_it(_it); } [ _next=_Nonempty_Account_List() { it.set_next(_next); } ] { return it; } } Nonempty_Posting_List _Nonempty_Posting_List() : { Nonempty_Posting_List it = null; Posting _it; Nonempty_Posting_List _next; } { { it=new Nonempty_Posting_List(); } _it=_Posting() { it.set_it(_it); } [ _next=_Nonempty_Posting_List() { 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 }