options { STATIC = false; JAVA_UNICODE_ESCAPE = true; } PARSER_BEGIN(Parser) import java.io.*; import java.util.*; import edu.neu.ccs.demeter.aplib.cd.*; import edu.neu.ccs.demeter.aplib.sg.*; 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) XAspectLanguage3 _XAspectLanguage3() : { XAspectLanguage3 it = null; AspectLanguage_List _aspectlanguage_list; } { { it=new XAspectLanguage3(); } _aspectlanguage_list=_AspectLanguage_List() { it.set_aspectlanguage_list(_aspectlanguage_list); } { return it; } } AspectLanguage _AspectLanguage() : { AspectLanguage it = null; } { ( LOOKAHEAD ( 3 )it=_ClassDictionaryL() | it=_SelectorL() ) { return it; } } void common_AspectLanguage(AspectLanguage it) : { } { { } } ClassDictionaryL _ClassDictionaryL() : { ClassDictionaryL it = null; ClassDictionaryName _classdictionaryname; ClassDict _classdict; } { { it=new ClassDictionaryL(); } "aspect" "(" "ClassDictionary" ")" _classdictionaryname=_ClassDictionaryName() { it.set_classdictionaryname(_classdictionaryname); } _classdict=_ClassDict() { it.set_classdict(_classdict); } common_AspectLanguage(it) { return it; } } SelectorL _SelectorL() : { SelectorL it = null; TraversalName _traversalname; StrategyDef_List _strategydef_list; NodeSubsetDef_List _nodesubsetdef_list; SelectorName _selectorname; ClassDictionaryName _classdictionaryname; } { { it=new SelectorL(); } "aspect" "(" "Traversal" ")" _traversalname=_TraversalName() { it.set_traversalname(_traversalname); } "{" _strategydef_list=_StrategyDef_List() { it.set_strategydef_list(_strategydef_list); } _nodesubsetdef_list=_NodeSubsetDef_List() { it.set_nodesubsetdef_list(_nodesubsetdef_list); } [ LOOKAHEAD (3) "declare" "chosen" "selector:" _selectorname=_SelectorName() { it.set_selectorname(_selectorname); } ";" ] [ LOOKAHEAD (3) "declare" "chosen" "class" "dictionary:" _classdictionaryname=_ClassDictionaryName() { it.set_classdictionaryname(_classdictionaryname); } ";" ] "}" common_AspectLanguage(it) { return it; } } StrategyDef _StrategyDef() : { StrategyDef it = null; StrategyName _strategyname; StrategyExpr _strategyexpr; } { { it=new StrategyDef(); } "declare" "strategy" ":" _strategyname=_StrategyName() { it.set_strategyname(_strategyname); } ":" _strategyexpr=_StrategyExpr() { it.set_strategyexpr(_strategyexpr); } ";" { return it; } } NodeSubsetDef _NodeSubsetDef() : { NodeSubsetDef it = null; NodeSubsetName _nodesubsetname; NodeSubsetExpression _nodesubsetexpression; } { { it=new NodeSubsetDef(); } "declare" "node" "set" ":" _nodesubsetname=_NodeSubsetName() { it.set_nodesubsetname(_nodesubsetname); } ":" _nodesubsetexpression=_NodeSubsetExpression() { it.set_nodesubsetexpression(_nodesubsetexpression); } ";" { return it; } } NodeSubsetExpression _NodeSubsetExpression() : { NodeSubsetExpression it = null; } { ( it=_Simple() | it=_BCompound() | it=_UCompound() ) { return it; } } void common_NodeSubsetExpression(NodeSubsetExpression it) : { } { { } } Simple _Simple() : { Simple it = null; } { ( it=_NodeSubsetName() | it=_ClassNameSet() | it=_GraphNodes() | it=_GraphNodeRegExp() ) { return it; } } void common_Simple(Simple it) : { } { common_NodeSubsetExpression(it) { } } BCompound _BCompound() : { BCompound it = null; BinaryOp _op; NodeSubsetExpression_PCList _args; } { { it=new BCompound(); } _op=_BinaryOp() { it.set_op(_op); } _args=_NodeSubsetExpression_PCList() { it.set_args(_args); } common_NodeSubsetExpression(it) { return it; } } UCompound _UCompound() : { UCompound it = null; UnaryOp _op; NodeSubsetExpression _arg; } { { it=new UCompound(); } _op=_UnaryOp() { it.set_op(_op); } _arg=_NodeSubsetExpression() { it.set_arg(_arg); } common_NodeSubsetExpression(it) { return it; } } ClassNameSet _ClassNameSet() : { ClassNameSet it = null; ClassName_BCList _classname_bclist; } { { it=new ClassNameSet(); } _classname_bclist=_ClassName_BCList() { it.set_classname_bclist(_classname_bclist); } common_Simple(it) { return it; } } GraphNodes _GraphNodes() : { GraphNodes it = null; StrategyName _strategyname; } { { it=new GraphNodes(); } "nodes" _strategyname=_StrategyName() { it.set_strategyname(_strategyname); } common_Simple(it) { return it; } } GraphNodeRegExp _GraphNodeRegExp() : { GraphNodeRegExp it = null; ClassName _classname; WildCard _wildcard; } { { it=new GraphNodeRegExp(); } "regexp" _classname=_ClassName() { it.set_classname(_classname); } _wildcard=_WildCard() { it.set_wildcard(_wildcard); } common_Simple(it) { return it; } } WildCard _WildCard() : { WildCard it = null; } { { it=new WildCard(); } "*" { return it; } } BinaryOp _BinaryOp() : { BinaryOp it = null; } { ( it=_Union() | it=_Intersection() ) { return it; } } void common_BinaryOp(BinaryOp it) : { } { common_Operator(it) { } } UnaryOp _UnaryOp() : { UnaryOp it = null; } { ( it=_Complement() ) { return it; } } void common_UnaryOp(UnaryOp it) : { } { common_Operator(it) { } } Union _Union() : { Union it = null; } { { it=new Union(); } "or" common_BinaryOp(it) { return it; } } Intersection _Intersection() : { Intersection it = null; } { { it=new Intersection(); } "and" common_BinaryOp(it) { return it; } } Complement _Complement() : { Complement it = null; } { { it=new Complement(); } "!" common_UnaryOp(it) { return it; } } ClassName _ClassName() : { ClassName it = null; Name _name; } { { it=new ClassName(); } _name=_Name() { it.set_name(_name); } { return it; } } Name _Name() : { Name it = null; Nonempty_Name _first; } { { it=new Name(); } _first=_Nonempty_Name() { it.set_first(_first); } { return it; } } ClassDict _ClassDict() : { ClassDict it = null; ConstText _cdtext; } { { it=new ClassDict(); } _cdtext=_ConstText() { it.set_cdtext(_cdtext); } { return it; } } StrategyExpr _StrategyExpr() : { StrategyExpr it = null; String _strategyString; } { { it=new StrategyExpr(); } _strategyString=_String() { it.set_strategyString(_strategyString); } { return it; } } SelectorName _SelectorName() : { SelectorName it = null; ConstIdent _name; } { { it=new SelectorName(); } _name=_ConstIdent() { it.set_name(_name); } { return it; } } TraversalName _TraversalName() : { TraversalName it = null; ConstIdent _name; } { { it=new TraversalName(); } _name=_ConstIdent() { it.set_name(_name); } { return it; } } StrategyName _StrategyName() : { StrategyName it = null; ConstIdent _name; } { { it=new StrategyName(); } _name=_ConstIdent() { it.set_name(_name); } { return it; } } NodeSubsetName _NodeSubsetName() : { NodeSubsetName it = null; ConstIdent _name; } { { it=new NodeSubsetName(); } _name=_ConstIdent() { it.set_name(_name); } common_Simple(it) { return it; } } ClassDictionaryName _ClassDictionaryName() : { ClassDictionaryName it = null; ConstIdent _name; } { { it=new ClassDictionaryName(); } _name=_ConstIdent() { it.set_name(_name); } { return it; } } Operator _Operator() : { Operator it = null; } { ( it=_BinaryOp() | it=_UnaryOp() ) { return it; } } void common_Operator(Operator it) : { } { { } } ConstIdent _ConstIdent() : { ConstIdent it = null; Ident _ident; } { { it=new ConstIdent(); } _ident=_Ident() { it.set_ident(_ident); } { return it; } } ConstText _ConstText() : { ConstText it = null; Text _text; } { { it=new ConstText(); } _text=_Text() { it.set_text(_text); } { return it; } } Main _Main() : { Main it = null; } { { it=new Main(); } { return it; } } AspectLanguage_List _AspectLanguage_List() : { AspectLanguage_List it = null; Nonempty_AspectLanguage_List _first; } { { it=new AspectLanguage_List(); } [ LOOKAHEAD ( 3 ) _first=_Nonempty_AspectLanguage_List() { it.set_first(_first); } ] { return it; } } StrategyDef_List _StrategyDef_List() : { StrategyDef_List it = null; Nonempty_StrategyDef_List _first; } { { it=new StrategyDef_List(); } [ LOOKAHEAD ( 3 ) _first=_Nonempty_StrategyDef_List() { it.set_first(_first); } ] { return it; } } NodeSubsetDef_List _NodeSubsetDef_List() : { NodeSubsetDef_List it = null; Nonempty_NodeSubsetDef_List _first; } { { it=new NodeSubsetDef_List(); } [ LOOKAHEAD ( 3 ) _first=_Nonempty_NodeSubsetDef_List() { it.set_first(_first); } ] { return it; } } NodeSubsetExpression_PCList _NodeSubsetExpression_PCList() : { NodeSubsetExpression_PCList it = null; Nonempty_NodeSubsetExpression_PCList _first; } { { it=new NodeSubsetExpression_PCList(); } "(" _first=_Nonempty_NodeSubsetExpression_PCList() { it.set_first(_first); } ")" { return it; } } ClassName_BCList _ClassName_BCList() : { ClassName_BCList it = null; Nonempty_ClassName_BCList _first; } { { it=new ClassName_BCList(); } "{" _first=_Nonempty_ClassName_BCList() { it.set_first(_first); } "}" { return it; } } Nonempty_Name _Nonempty_Name() : { Nonempty_Name it = null; ConstIdent _it; Nonempty_Name _next; } { { it=new Nonempty_Name(); } _it=_ConstIdent() { it.set_it(_it); } [ "." _next=_Nonempty_Name() { it.set_next(_next); } ] { return it; } } Nonempty_AspectLanguage_List _Nonempty_AspectLanguage_List() : { Nonempty_AspectLanguage_List it = null; AspectLanguage _it; Nonempty_AspectLanguage_List _next; } { { it=new Nonempty_AspectLanguage_List(); } _it=_AspectLanguage() { it.set_it(_it); } [ LOOKAHEAD ( 3 ) _next=_Nonempty_AspectLanguage_List() { it.set_next(_next); } ] { return it; } } Nonempty_StrategyDef_List _Nonempty_StrategyDef_List() : { Nonempty_StrategyDef_List it = null; StrategyDef _it; Nonempty_StrategyDef_List _next; } { { it=new Nonempty_StrategyDef_List(); } _it=_StrategyDef() { it.set_it(_it); } [ LOOKAHEAD ( 3 ) _next=_Nonempty_StrategyDef_List() { it.set_next(_next); } ] { return it; } } Nonempty_NodeSubsetDef_List _Nonempty_NodeSubsetDef_List() : { Nonempty_NodeSubsetDef_List it = null; NodeSubsetDef _it; Nonempty_NodeSubsetDef_List _next; } { { it=new Nonempty_NodeSubsetDef_List(); } _it=_NodeSubsetDef() { it.set_it(_it); } [ LOOKAHEAD ( 3 ) _next=_Nonempty_NodeSubsetDef_List() { it.set_next(_next); } ] { return it; } } Nonempty_NodeSubsetExpression_PCList _Nonempty_NodeSubsetExpression_PCList() : { Nonempty_NodeSubsetExpression_PCList it = null; NodeSubsetExpression _it; Nonempty_NodeSubsetExpression_PCList _next; } { { it=new Nonempty_NodeSubsetExpression_PCList(); } _it=_NodeSubsetExpression() { it.set_it(_it); } [ "," _next=_Nonempty_NodeSubsetExpression_PCList() { it.set_next(_next); } ] { return it; } } Nonempty_ClassName_BCList _Nonempty_ClassName_BCList() : { Nonempty_ClassName_BCList it = null; ClassName _it; Nonempty_ClassName_BCList _next; } { { it=new Nonempty_ClassName_BCList(); } _it=_ClassName() { it.set_it(_it); } [ "," _next=_Nonempty_ClassName_BCList() { 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 }