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; } } Policies _Policies() : { Policies it = null; Policy_List _policy_list; Stream_List _stream_list; Filter_List _filter_list; } { { it=new Policies(); } _policy_list=_Policy_List() { it.set_policy_list(_policy_list); } [ "streams" _stream_list=_Stream_List() { it.set_stream_list(_stream_list); } ] [ "filters" _filter_list=_Filter_List() { it.set_filter_list(_filter_list); } ] { return it; } } Policy _Policy() : { Policy it = null; PolicyName _policyname; PolicyKind _policykind; } { { it=new Policy(); } "policy" _policyname=_PolicyName() { it.set_policyname(_policyname); } _policykind=_PolicyKind() { it.set_policykind(_policykind); } { return it; } } PolicyKind _PolicyKind() : { PolicyKind it = null; } { ( it=_FilterIndependent() | it=_ImageStreamAccess() | it=_FilterAccess() ) { return it; } } void common_PolicyKind(PolicyKind it) : { } { { } } FilterIndependent _FilterIndependent() : { FilterIndependent it = null; } { ( it=_Change() ) { return it; } } void common_FilterIndependent(FilterIndependent it) : { } { common_PolicyKind(it) { } } ChangeKind _ChangeKind() : { ChangeKind it = null; } { ( it=_Cut() | it=_Blurr() ) { return it; } } void common_ChangeKind(ChangeKind it) : { } { { } } Cut _Cut() : { Cut it = null; } { { it=new Cut(); } "cut" common_ChangeKind(it) { return it; } } Blurr _Blurr() : { Blurr it = null; } { { it=new Blurr(); } "blurr" common_ChangeKind(it) { return it; } } Change _Change() : { Change it = null; ChangeKind _changekind; AreaKind _areakind; StreamName _streamname; UserName _username; } { { it=new Change(); } _changekind=_ChangeKind() { it.set_changekind(_changekind); } "area" _areakind=_AreaKind() { it.set_areakind(_areakind); } [ "in" "stream" _streamname=_StreamName() { it.set_streamname(_streamname); } ] [ "viewed" "by" _username=_UserName() { it.set_username(_username); } ] common_FilterIndependent(it) { return it; } } ImageStreamAccess _ImageStreamAccess() : { ImageStreamAccess it = null; UserName _username; StreamName _streamname; Condition _condition; } { { it=new ImageStreamAccess(); } "stream" "access" _username=_UserName() { it.set_username(_username); } _streamname=_StreamName() { it.set_streamname(_streamname); } "if" _condition=_Condition() { it.set_condition(_condition); } common_PolicyKind(it) { return it; } } FilterAccess _FilterAccess() : { FilterAccess it = null; UserName _username; FilterName _filtername; StreamName _streamname; } { { it=new FilterAccess(); } "filter" "access" _username=_UserName() { it.set_username(_username); } _filtername=_FilterName() { it.set_filtername(_filtername); } _streamname=_StreamName() { it.set_streamname(_streamname); } common_PolicyKind(it) { return it; } } Condition _Condition() : { Condition it = null; } { ( it=_TimeRange() | it=_FilterInstalled() ) { return it; } } void common_Condition(Condition it) : { } { { } } TimeRange _TimeRange() : { TimeRange it = null; Time _start; Time _end; } { { it=new TimeRange(); } "time" "range" _start=_Time() { it.set_start(_start); } _end=_Time() { it.set_end(_end); } common_Condition(it) { return it; } } FilterInstalled _FilterInstalled() : { FilterInstalled it = null; FilterName _filtername; } { { it=new FilterInstalled(); } "filter" _filtername=_FilterName() { it.set_filtername(_filtername); } "installed" common_Condition(it) { return it; } } Time _Time() : { Time it = null; String _string; } { { it=new Time(); } _string=_String() { it.set_string(_string); } { return it; } } AreaKind _AreaKind() : { AreaKind it = null; LU _lu; LR _lr; } { { it=new AreaKind(); } _lu=_LU() { it.set_lu(_lu); } _lr=_LR() { it.set_lr(_lr); } { return it; } } LU _LU() : { LU it = null; } { ( it=_Lower() | it=_Upper() ) { return it; } } void common_LU(LU it) : { } { { } } LR _LR() : { LR it = null; } { ( it=_Left() | it=_Right() ) { return it; } } void common_LR(LR it) : { } { { } } Lower _Lower() : { Lower it = null; } { { it=new Lower(); } "lower" common_LU(it) { return it; } } Upper _Upper() : { Upper it = null; } { { it=new Upper(); } "upper" common_LU(it) { return it; } } Left _Left() : { Left it = null; } { { it=new Left(); } "left" common_LR(it) { return it; } } Right _Right() : { Right it = null; } { { it=new Right(); } "right" common_LR(it) { return it; } } Filter _Filter() : { Filter it = null; FilterName _filtername; } { { it=new Filter(); } _filtername=_FilterName() { it.set_filtername(_filtername); } { return it; } } Stream _Stream() : { Stream it = null; StreamName _streamname; } { { it=new Stream(); } _streamname=_StreamName() { it.set_streamname(_streamname); } { return it; } } StreamName _StreamName() : { StreamName it = null; Ident _ident; } { { it=new StreamName(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } UserName _UserName() : { UserName it = null; Ident _ident; } { { it=new UserName(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } FilterName _FilterName() : { FilterName it = null; Ident _ident; } { { it=new FilterName(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } PolicyName _PolicyName() : { PolicyName it = null; Ident _ident; } { { it=new PolicyName(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } Policy_List _Policy_List() : { Policy_List it = null; Nonempty_Policy_List _first; } { { it=new Policy_List(); } [ _first=_Nonempty_Policy_List() { it.set_first(_first); } ] { return it; } } Stream_List _Stream_List() : { Stream_List it = null; Nonempty_Stream_List _first; } { { it=new Stream_List(); } [ _first=_Nonempty_Stream_List() { it.set_first(_first); } ] { return it; } } Filter_List _Filter_List() : { Filter_List it = null; Nonempty_Filter_List _first; } { { it=new Filter_List(); } [ _first=_Nonempty_Filter_List() { it.set_first(_first); } ] { return it; } } Nonempty_Policy_List _Nonempty_Policy_List() : { Nonempty_Policy_List it = null; Policy _it; Nonempty_Policy_List _next; } { { it=new Nonempty_Policy_List(); } _it=_Policy() { it.set_it(_it); } [ _next=_Nonempty_Policy_List() { it.set_next(_next); } ] { return it; } } Nonempty_Stream_List _Nonempty_Stream_List() : { Nonempty_Stream_List it = null; Stream _it; Nonempty_Stream_List _next; } { { it=new Nonempty_Stream_List(); } _it=_Stream() { it.set_it(_it); } [ _next=_Nonempty_Stream_List() { it.set_next(_next); } ] { return it; } } Nonempty_Filter_List _Nonempty_Filter_List() : { Nonempty_Filter_List it = null; Filter _it; Nonempty_Filter_List _next; } { { it=new Nonempty_Filter_List(); } _it=_Filter() { it.set_it(_it); } [ _next=_Nonempty_Filter_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 }