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) DAJ _DAJ() : { DAJ it = null; TraversalAspect_List _traversalaspect_list; } { { it=new DAJ(); } _traversalaspect_list=_TraversalAspect_List() { it.set_traversalaspect_list(_traversalaspect_list); } { return it; } } TraversalAspect _TraversalAspect() : { TraversalAspect it = null; AspectName _aspectname; Definition_CurlyList _decls; } { { it=new TraversalAspect(); } "aspect" _aspectname=_AspectName() { it.set_aspectname(_aspectname); } _decls=_Definition_CurlyList() { it.set_decls(_decls); } { return it; } } Definition _Definition() : { Definition it = null; DefinitionBody _definitionbody; } { { it=new Definition(); } "declare" _definitionbody=_DefinitionBody() { it.set_definitionbody(_definitionbody); } ";" { return it; } } DefinitionBody _DefinitionBody() : { DefinitionBody it = null; } { ( it=_CG() | it=_Strategy() | it=_AdaptiveMethod() ) { return it; } } void common_DefinitionBody(DefinitionBody it) : { } { { } } CG _CG() : { CG it = null; ClassGraphName _classgraphname; } { { it=new CG(); } "ClassGraph" _classgraphname=_ClassGraphName() { it.set_classgraphname(_classgraphname); } common_DefinitionBody(it) { return it; } } Strategy _Strategy() : { Strategy it = null; StrategyName _strategyname; StrategyExpression _strategyexpression; } { { it=new Strategy(); } "Strategy" _strategyname=_StrategyName() { it.set_strategyname(_strategyname); } "=" _strategyexpression=_StrategyExpression() { it.set_strategyexpression(_strategyexpression); } common_DefinitionBody(it) { return it; } } StrategyExpression _StrategyExpression() : { StrategyExpression it = null; } { ( it=_Simple() | it=_Compound() ) { return it; } } void common_StrategyExpression(StrategyExpression it) : { } { { } } Simple _Simple() : { Simple it = null; } { ( it=_StrategyName() | it=_StrategyString() ) { return it; } } void common_Simple(Simple it) : { } { common_StrategyExpression(it) { } } StrategyString _StrategyString() : { StrategyString it = null; String _string; } { { it=new StrategyString(); } _string=_String() { it.set_string(_string); } common_Simple(it) { return it; } } Compound _Compound() : { Compound it = null; Op _op; StrategyExpression_List _strategyexpression_list; } { { it=new Compound(); } "(" _op=_Op() { it.set_op(_op); } _strategyexpression_list=_StrategyExpression_List() { it.set_strategyexpression_list(_strategyexpression_list); } ")" common_StrategyExpression(it) { return it; } } Op _Op() : { Op it = null; } { ( it=_And() ) { return it; } } void common_Op(Op it) : { } { { } } And _And() : { And it = null; } { { it=new And(); } "&&" common_Op(it) { return it; } } AdaptiveMethod _AdaptiveMethod() : { AdaptiveMethod it = null; MethodSignature _methodsignature; MethodBody _methodbody; } { { it=new AdaptiveMethod(); } "Method" _methodsignature=_MethodSignature() { it.set_methodsignature(_methodsignature); } _methodbody=_MethodBody() { it.set_methodbody(_methodbody); } common_DefinitionBody(it) { return it; } } MethodSignature _MethodSignature() : { MethodSignature it = null; MethodKeyword_List _keywords; JavaType _returnType; MethodName _name; MethodParm_Commalist _parms; Throws _throwsclause; } { { it=new MethodSignature(); } _keywords=_MethodKeyword_List() { it.set_keywords(_keywords); } _returnType=_JavaType() { it.set_returnType(_returnType); } _name=_MethodName() { it.set_name(_name); } "(" [ _parms=_MethodParm_Commalist() { it.set_parms(_parms); } ] ")" _throwsclause=_Throws() { it.set_throwsclause(_throwsclause); } { return it; } } MethodKeyword _MethodKeyword() : { MethodKeyword it = null; } { ( it=_PublicMethod() | it=_ProtectedMethod() | it=_PrivateMethod() | it=_StaticMethod() | it=_FinalMethod() ) { return it; } } void common_MethodKeyword(MethodKeyword it) : { } { { } } PublicMethod _PublicMethod() : { PublicMethod it = null; } { { it=new PublicMethod(); } "public" common_MethodKeyword(it) { return it; } } ProtectedMethod _ProtectedMethod() : { ProtectedMethod it = null; } { { it=new ProtectedMethod(); } "protected" common_MethodKeyword(it) { return it; } } PrivateMethod _PrivateMethod() : { PrivateMethod it = null; } { { it=new PrivateMethod(); } "private" common_MethodKeyword(it) { return it; } } StaticMethod _StaticMethod() : { StaticMethod it = null; } { { it=new StaticMethod(); } "static" common_MethodKeyword(it) { return it; } } FinalMethod _FinalMethod() : { FinalMethod it = null; } { { it=new FinalMethod(); } "final" common_MethodKeyword(it) { return it; } } MethodParm _MethodParm() : { MethodParm it = null; JavaType _type; ParmName _name; ArraySpec_List _array; } { { it=new MethodParm(); } _type=_JavaType() { it.set_type(_type); } _name=_ParmName() { it.set_name(_name); } _array=_ArraySpec_List() { it.set_array(_array); } { return it; } } Throws _Throws() : { Throws it = null; ClassName_Commalist _exceptions; } { { it=new Throws(); } [ "throws" _exceptions=_ClassName_Commalist() { it.set_exceptions(_exceptions); } ] { return it; } } MethodBody _MethodBody() : { MethodBody it = null; StrategyExpression _trv; VisitorRef _vis; } { { it=new MethodBody(); } _trv=_StrategyExpression() { it.set_trv(_trv); } _vis=_VisitorRef() { it.set_vis(_vis); } { return it; } } VisitorRef _VisitorRef() : { VisitorRef it = null; ClassName_Commalist _visitorClasses; } { { it=new VisitorRef(); } "(" _visitorClasses=_ClassName_Commalist() { it.set_visitorClasses(_visitorClasses); } ")" { return it; } } JavaType _JavaType() : { JavaType it = null; Name _type; ArraySpec_List _array; } { { it=new JavaType(); } _type=_Name() { it.set_type(_type); } _array=_ArraySpec_List() { it.set_array(_array); } { return it; } } ArraySpec _ArraySpec() : { ArraySpec it = null; } { { it=new ArraySpec(); } "[" "]" { return it; } } Name _Name() : { Name it = null; Nonempty_Name _first; } { { it=new Name(); } _first=_Nonempty_Name() { it.set_first(_first); } { return it; } } ClassGraphName _ClassGraphName() : { ClassGraphName it = null; Ident _ident; } { { it=new ClassGraphName(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } StrategyName _StrategyName() : { StrategyName it = null; Ident _ident; } { { it=new StrategyName(); } _ident=_Ident() { it.set_ident(_ident); } common_Simple(it) { return it; } } MethodName _MethodName() : { MethodName it = null; Ident _ident; } { { it=new MethodName(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } ClassName _ClassName() : { ClassName it = null; Name _name; } { { it=new ClassName(); } _name=_Name() { it.set_name(_name); } { return it; } } ParmName _ParmName() : { ParmName it = null; Ident _name; } { { it=new ParmName(); } _name=_Ident() { it.set_name(_name); } { return it; } } AspectName _AspectName() : { AspectName it = null; Name _name; } { { it=new AspectName(); } _name=_Name() { it.set_name(_name); } { return it; } } Main _Main() : { Main it = null; String _s; } { { it=new Main(); } _s=_String() { it.set_s(_s); } { return it; } } TraversalAspect_List _TraversalAspect_List() : { TraversalAspect_List it = null; Nonempty_TraversalAspect_List _first; } { { it=new TraversalAspect_List(); } [ _first=_Nonempty_TraversalAspect_List() { it.set_first(_first); } ] { return it; } } Definition_CurlyList _Definition_CurlyList() : { Definition_CurlyList it = null; Nonempty_Definition_CurlyList _first; } { { it=new Definition_CurlyList(); } "{" _first=_Nonempty_Definition_CurlyList() { it.set_first(_first); } "}" { return it; } } StrategyExpression_List _StrategyExpression_List() : { StrategyExpression_List it = null; Nonempty_StrategyExpression_List _first; } { { it=new StrategyExpression_List(); } [ _first=_Nonempty_StrategyExpression_List() { it.set_first(_first); } ] { return it; } } MethodKeyword_List _MethodKeyword_List() : { MethodKeyword_List it = null; Nonempty_MethodKeyword_List _first; } { { it=new MethodKeyword_List(); } [ _first=_Nonempty_MethodKeyword_List() { it.set_first(_first); } ] { return it; } } MethodParm_Commalist _MethodParm_Commalist() : { MethodParm_Commalist it = null; Nonempty_MethodParm_Commalist _first; } { { it=new MethodParm_Commalist(); } _first=_Nonempty_MethodParm_Commalist() { it.set_first(_first); } { return it; } } ArraySpec_List _ArraySpec_List() : { ArraySpec_List it = null; Nonempty_ArraySpec_List _first; } { { it=new ArraySpec_List(); } [ _first=_Nonempty_ArraySpec_List() { it.set_first(_first); } ] { return it; } } ClassName_Commalist _ClassName_Commalist() : { ClassName_Commalist it = null; Nonempty_ClassName_Commalist _first; } { { it=new ClassName_Commalist(); } _first=_Nonempty_ClassName_Commalist() { it.set_first(_first); } { return it; } } Nonempty_Name _Nonempty_Name() : { Nonempty_Name it = null; Ident _it; Nonempty_Name _next; } { { it=new Nonempty_Name(); } _it=_Ident() { it.set_it(_it); } [ "." _next=_Nonempty_Name() { it.set_next(_next); } ] { return it; } } Nonempty_TraversalAspect_List _Nonempty_TraversalAspect_List() : { Nonempty_TraversalAspect_List it = null; TraversalAspect _it; Nonempty_TraversalAspect_List _next; } { { it=new Nonempty_TraversalAspect_List(); } _it=_TraversalAspect() { it.set_it(_it); } [ _next=_Nonempty_TraversalAspect_List() { it.set_next(_next); } ] { return it; } } Nonempty_Definition_CurlyList _Nonempty_Definition_CurlyList() : { Nonempty_Definition_CurlyList it = null; Definition _it; Nonempty_Definition_CurlyList _next; } { { it=new Nonempty_Definition_CurlyList(); } _it=_Definition() { it.set_it(_it); } [ _next=_Nonempty_Definition_CurlyList() { it.set_next(_next); } ] { return it; } } Nonempty_StrategyExpression_List _Nonempty_StrategyExpression_List() : { Nonempty_StrategyExpression_List it = null; StrategyExpression _it; Nonempty_StrategyExpression_List _next; } { { it=new Nonempty_StrategyExpression_List(); } _it=_StrategyExpression() { it.set_it(_it); } [ _next=_Nonempty_StrategyExpression_List() { it.set_next(_next); } ] { return it; } } Nonempty_MethodKeyword_List _Nonempty_MethodKeyword_List() : { Nonempty_MethodKeyword_List it = null; MethodKeyword _it; Nonempty_MethodKeyword_List _next; } { { it=new Nonempty_MethodKeyword_List(); } _it=_MethodKeyword() { it.set_it(_it); } [ _next=_Nonempty_MethodKeyword_List() { it.set_next(_next); } ] { return it; } } Nonempty_MethodParm_Commalist _Nonempty_MethodParm_Commalist() : { Nonempty_MethodParm_Commalist it = null; MethodParm _it; Nonempty_MethodParm_Commalist _next; } { { it=new Nonempty_MethodParm_Commalist(); } _it=_MethodParm() { it.set_it(_it); } [ "," _next=_Nonempty_MethodParm_Commalist() { it.set_next(_next); } ] { return it; } } Nonempty_ArraySpec_List _Nonempty_ArraySpec_List() : { Nonempty_ArraySpec_List it = null; ArraySpec _it; Nonempty_ArraySpec_List _next; } { { it=new Nonempty_ArraySpec_List(); } _it=_ArraySpec() { it.set_it(_it); } [ _next=_Nonempty_ArraySpec_List() { it.set_next(_next); } ] { return it; } } Nonempty_ClassName_Commalist _Nonempty_ClassName_Commalist() : { Nonempty_ClassName_Commalist it = null; ClassName _it; Nonempty_ClassName_Commalist _next; } { { it=new Nonempty_ClassName_Commalist(); } _it=_ClassName() { it.set_it(_it); } [ "," _next=_Nonempty_ClassName_Commalist() { 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 }