options { STATIC = false; JAVA_UNICODE_ESCAPE = true; } PARSER_BEGIN(Parser) package uci.graphedit; import java.awt.*; import java.io.*; import java.util.*; import java.lang.Math ; import 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(2, 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) UGraph _UGraph() : { UGraph it; UVertex_List _vertices; UEdge_List _edges; } { { it=new UGraph(); } "#Class" "#Dictionary" "#Graph" [ _vertices=_UVertex_List() { it.set_vertices(_vertices); } ] [ _edges=_UEdge_List() { it.set_edges(_edges); } ] { return it; } } UVertex_List _UVertex_List() : { UVertex_List it; Nonempty_UVertex_List _first; } { { it=new UVertex_List(); } "#Vertex" "#List" [ _first=_Nonempty_UVertex_List() { it.set_first(_first); } ] { return it; } } UVertex _UVertex() : { UVertex it; UID _id; UVertexName _vertexname; Coordinates _position; IEdge_List _incoming; OEdge_List _outgoing; } { ( it=_UAltVertex() | it=_UConstVertex() | it=_UTerm() ) _id=_UID() { it.set_id(_id); } _vertexname=_UVertexName() { it.set_vertexname(_vertexname); } _position=_Coordinates() { it.set_position(_position); } [ _incoming=_IEdge_List() { it.set_incoming(_incoming); } ] [ _outgoing=_OEdge_List() { it.set_outgoing(_outgoing); } ] { return it; } } IEdge_List _IEdge_List() : { IEdge_List it; Nonempty_IEdge_List _first; } { { it=new IEdge_List(); } "#Incoming" [ _first=_Nonempty_IEdge_List() { it.set_first(_first); } ] { return it; } } OEdge_List _OEdge_List() : { OEdge_List it; Nonempty_OEdge_List _first; } { { it=new OEdge_List(); } "#Outgoing" [ _first=_Nonempty_OEdge_List() { it.set_first(_first); } ] { return it; } } UConstVertex _UConstVertex() : { UConstVertex it; } { { it=new UConstVertex(); } "#ConstVertex" { return it; } } UAltVertex _UAltVertex() : { UAltVertex it; } { { it=new UAltVertex(); } "#AltVertex" { return it; } } UTerm _UTerm() : { UTerm it; } { { it=new UTerm(); } "#TermVertex" { return it; } } UEdge_List _UEdge_List() : { UEdge_List it; Nonempty_UEdge_List _first; } { { it=new UEdge_List(); } "#Edge" "#List" [ _first=_Nonempty_UEdge_List() { it.set_first(_first); } ] { return it; } } UEdge _UEdge() : { UEdge it; UID _id; UVertex _fromVertex; UVertex _toVertex; } { ( it=_UAltEdge() | it=_UConstEdge() ) _id=_UID() { it.set_id(_id); } _fromVertex=_UVertex() { it.set_fromVertex(_fromVertex); } _toVertex=_UVertex() { it.set_toVertex(_toVertex); } { return it; } } UAltEdge _UAltEdge() : { UAltEdge it; } { { it=new UAltEdge(); } "#AltEdge" { return it; } } UConstEdge _UConstEdge() : { UConstEdge it; UEdgeName _edgename; Cardinality _card; } { { it=new UConstEdge(); } "#ConstEdge" _edgename=_UEdgeName() { it.set_edgename(_edgename); } _card=_Cardinality() { it.set_card(_card); } { return it; } } Cardinality _Cardinality() : { Cardinality it; Lower _lower; Upper _upper; } { { it=new Cardinality(); } _lower=_Lower() { it.set_lower(_lower); } [ _upper=_Upper() { it.set_upper(_upper); } ] { return it; } } Lower _Lower() : { Lower it; Integer _l; } { { it=new Lower(); } _l=_Integer() { it.set_l(_l); } { return it; } } Upper _Upper() : { Upper it; String _u; } { { it=new Upper(); } "." "." _u=_String() { it.set_u(_u); } { return it; } } UID _UID() : { UID it; Integer _id; } { { it=new UID(); } _id=_Integer() { it.set_id(_id); } { return it; } } UEdgeName _UEdgeName() : { UEdgeName it; Ident _name; } { { it=new UEdgeName(); } _name=_Ident() { it.set_name(_name); } { return it; } } UVertexName _UVertexName() : { UVertexName it; Ident _name; } { { it=new UVertexName(); } _name=_Ident() { it.set_name(_name); } { return it; } } Coordinates _Coordinates() : { Coordinates it; X _x; Y _y; } { { it=new Coordinates(); } "{" _x=_X() { it.set_x(_x); } _y=_Y() { it.set_y(_y); } "}" { return it; } } X _X() : { X it; Integer _x; } { { it=new X(); } _x=_Integer() { it.set_x(_x); } { return it; } } Y _Y() : { Y it; Integer _y; } { { it=new Y(); } _y=_Integer() { it.set_y(_y); } { return it; } } Program _Program() : { Program it; JavaCode _preamble; ClassGraph _classgraph; } { { it=new Program(); } [ _preamble=_JavaCode() { it.set_preamble(_preamble); } ] _classgraph=_ClassGraph() { it.set_classgraph(_classgraph); } { return it; } } ClassGraph _ClassGraph() : { ClassGraph it; ClassDef_DList _classes; } { { it=new ClassGraph(); } _classes=_ClassDef_DList() { it.set_classes(_classes); } { return it; } } ClassDef _ClassDef() : { ClassDef it; ParamClassName _paramclassname; ClassParts _classparts; DFS_mark _dfs_mark; PP_mark _pp_mark; } { { it=new ClassDef(); } _paramclassname=_ParamClassName() { it.set_paramclassname(_paramclassname); } _classparts=_ClassParts() { it.set_classparts(_classparts); } "." [ _dfs_mark=_DFS_mark() { it.set_dfs_mark(_dfs_mark); } ] [ _pp_mark=_PP_mark() { it.set_pp_mark(_pp_mark); } ] { return it; } } ParamClassName _ParamClassName() : { ParamClassName it; ClassName _classname; ClassName_Commalist _parameters; } { { it=new ParamClassName(); } _classname=_ClassName() { it.set_classname(_classname); } [ "(" _parameters=_ClassName_Commalist() { it.set_parameters(_parameters); } ")" ] { return it; } } ClassParts _ClassParts() : { ClassParts it; } { ( it=_ConstOrAltClass() | it=_RepetitionClass() ) { return it; } } ConstOrAltClass _ConstOrAltClass() : { ConstOrAltClass it; PartOrSyntax_List _parts; ClassParents _parents; } { ( it=_ConstructionClass() | it=_AlternationClass() ) _parts=_PartOrSyntax_List() { it.set_parts(_parts); } _parents=_ClassParents() { it.set_parents(_parents); } { return it; } } PartOrSyntax _PartOrSyntax() : { PartOrSyntax it; } { ( it=_Part() | it=_OptionalPart() | it=_Syntax() ) { return it; } } Part _Part() : { Part it; PartName _partname; ClassSpec _classspec; } { { it=new Part(); } [ "<" _partname=_PartName() { it.set_partname(_partname); } ">" ] _classspec=_ClassSpec() { it.set_classspec(_classspec); } { return it; } } OptionalPart _OptionalPart() : { OptionalPart it; Part_Sandwich _part; } { { it=new OptionalPart(); } "[" _part=_Part_Sandwich() { it.set_part(_part); } "]" { return it; } } ClassParents _ClassParents() : { ClassParents it; ClassSpec _extend; ClassSpec_Commalist _implement; } { { it=new ClassParents(); } [ "*extends*" _extend=_ClassSpec() { it.set_extend(_extend); } ] [ "*implements*" _implement=_ClassSpec_Commalist() { it.set_implement(_implement); } ] { return it; } } ConstructionClass _ConstructionClass() : { ConstructionClass it; } { { it=new ConstructionClass(); } "=" { return it; } } AlternationClass _AlternationClass() : { AlternationClass it; Subclass_Barlist _subclasses; Common _common; } { { it=new AlternationClass(); } ":" _subclasses=_Subclass_Barlist() { it.set_subclasses(_subclasses); } [ _common=_Common() { it.set_common(_common); } ] { return it; } } Subclass _Subclass() : { Subclass it; ClassSpec _classspec; } { { it=new Subclass(); } _classspec=_ClassSpec() { it.set_classspec(_classspec); } { return it; } } Common _Common() : { Common it; } { { it=new Common(); } "*common*" { return it; } } RepetitionClass _RepetitionClass() : { RepetitionClass it; RepeatedPart_Sandwich _sandwiched; } { { it=new RepetitionClass(); } "~" _sandwiched=_RepeatedPart_Sandwich() { it.set_sandwiched(_sandwiched); } { return it; } } RepeatedPart _RepeatedPart() : { RepeatedPart it; ClassSpec _nonempty; ClassSpec_Sandwich _repeated; } { { it=new RepeatedPart(); } [ _nonempty=_ClassSpec() { it.set_nonempty(_nonempty); } ] "{" _repeated=_ClassSpec_Sandwich() { it.set_repeated(_repeated); } "}" { return it; } } ClassSpec _ClassSpec() : { ClassSpec it; ClassName _classname; ClassSpec_Commalist _actual_parameters; PP_mark _pp_mark; } { { it=new ClassSpec(); } _classname=_ClassName() { it.set_classname(_classname); } [ "(" _actual_parameters=_ClassSpec_Commalist() { it.set_actual_parameters(_actual_parameters); } ")" ] [ _pp_mark=_PP_mark() { it.set_pp_mark(_pp_mark); } ] { return it; } } Syntax _Syntax() : { Syntax it; } { ( it=_PlainSyntax() | it=_PrintCommand() ) { return it; } } PlainSyntax _PlainSyntax() : { PlainSyntax it; String _string; } { { it=new PlainSyntax(); } _string=_String() { it.set_string(_string); } { return it; } } PrintCommand _PrintCommand() : { PrintCommand it; } { ( it=_PrintIndent() | it=_PrintUnindent() | it=_PrintSkip() | it=_PrintSpace() ) { return it; } } PrintIndent _PrintIndent() : { PrintIndent it; } { { it=new PrintIndent(); } "+" { return it; } } PrintUnindent _PrintUnindent() : { PrintUnindent it; } { { it=new PrintUnindent(); } "-" { return it; } } PrintSkip _PrintSkip() : { PrintSkip it; } { { it=new PrintSkip(); } "*l" { return it; } } PrintSpace _PrintSpace() : { PrintSpace it; } { { it=new PrintSpace(); } "*s" { return it; } } DFS_mark _DFS_mark() : { DFS_mark it; } { { it=new DFS_mark(); } "*dfs*" { return it; } } PP_mark _PP_mark() : { PP_mark it; } { { it=new PP_mark(); } "*pp*" { return it; } } Verbatim _Verbatim() : { Verbatim it; JavaCode _javacode; } { { it=new Verbatim(); } _javacode=_JavaCode() { it.set_javacode(_javacode); } { return it; } } ClassName _ClassName() : { ClassName it; Ident _name; } { { it=new ClassName(); } _name=_Ident() { it.set_name(_name); } { return it; } } PartName _PartName() : { PartName it; Ident _name; } { { it=new PartName(); } _name=_Ident() { it.set_name(_name); } { return it; } } TraversalName _TraversalName() : { TraversalName it; Ident _name; } { { it=new TraversalName(); } _name=_Ident() { it.set_name(_name); } { return it; } } VisitorName _VisitorName() : { VisitorName it; Ident _name; } { { it=new VisitorName(); } _name=_Ident() { it.set_name(_name); } { return it; } } MethodName _MethodName() : { MethodName it; Ident _name; } { { it=new MethodName(); } _name=_Ident() { it.set_name(_name); } { return it; } } JavaCode _JavaCode() : { JavaCode it; String _code; } { { it=new JavaCode(); } _code=_String() { it.set_code(_code); } { return it; } } Parameterized _Parameterized() : { Parameterized it; Part_Commalist _part_commalist; } { { it=new Parameterized(); } _part_commalist=_Part_Commalist() { it.set_part_commalist(_part_commalist); } { return it; } } SyntaxTable _SyntaxTable() : { SyntaxTable it; PlainSyntax_List _plainsyntax_list; } { { it=new SyntaxTable(); } _plainsyntax_list=_PlainSyntax_List() { it.set_plainsyntax_list(_plainsyntax_list); } { return it; } } PrintVisitor _PrintVisitor() : { PrintVisitor it; UGraph _ugraph; } { { it=new PrintVisitor(); } _ugraph=_UGraph() { it.set_ugraph(_ugraph); } { return it; } } PlacementVisitor _PlacementVisitor() : { PlacementVisitor it; UGraph _ugraph; } { { it=new PlacementVisitor(); } _ugraph=_UGraph() { it.set_ugraph(_ugraph); } { return it; } } EdgeDistinctionVisitor _EdgeDistinctionVisitor() : { EdgeDistinctionVisitor it; String _edgetype; } { { it=new EdgeDistinctionVisitor(); } _edgetype=_String() { it.set_edgetype(_edgetype); } { return it; } } ClassNameRetVisitor _ClassNameRetVisitor() : { ClassNameRetVisitor it; ClassName _cn; } { { it=new ClassNameRetVisitor(); } _cn=_ClassName() { it.set_cn(_cn); } { return it; } } ClassNameTranspVisitor _ClassNameTranspVisitor() : { ClassNameTranspVisitor it; ParamClassName _pcn; } { { it=new ClassNameTranspVisitor(); } _pcn=_ParamClassName() { it.set_pcn(_pcn); } { return it; } } EdgeVisitor _EdgeVisitor() : { EdgeVisitor it; EdgeDistinctionVisitor _edv; ClassNameTranspVisitor _cntv; UGraph _ugraph; } { { it=new EdgeVisitor(); } _edv=_EdgeDistinctionVisitor() { it.set_edv(_edv); } _cntv=_ClassNameTranspVisitor() { it.set_cntv(_cntv); } _ugraph=_UGraph() { it.set_ugraph(_ugraph); } { return it; } } ReadVertexVisitor _ReadVertexVisitor() : { ReadVertexVisitor it; VertexContainer _elements; } { { it=new ReadVertexVisitor(); } _elements=_VertexContainer() { it.set_elements(_elements); } { return it; } } VertexContainer _VertexContainer() : { VertexContainer it; } { { it=new VertexContainer(); } { return it; } } ReadEdgeVisitor _ReadEdgeVisitor() : { ReadEdgeVisitor it; EdgeContainer _elements; } { { it=new ReadEdgeVisitor(); } _elements=_EdgeContainer() { it.set_elements(_elements); } { return it; } } EdgeContainer _EdgeContainer() : { EdgeContainer it; } { { it=new EdgeContainer(); } { return it; } } SaveGraphVisitor _SaveGraphVisitor() : { SaveGraphVisitor it; String _graphString; } { { it=new SaveGraphVisitor(); } _graphString=_String() { it.set_graphString(_graphString); } { return it; } } Main _Main() : { Main it; } { { it=new Main(); } { return it; } } CountingVisitor _CountingVisitor() : { CountingVisitor it; Integer _total; } { { it=new CountingVisitor(); } _total=_Integer() { it.set_total(_total); } { return it; } } ClassDef_DList _ClassDef_DList() : { ClassDef_DList it; Nonempty_ClassDef_DList _first; } { { it=new ClassDef_DList(); } _first=_Nonempty_ClassDef_DList() { it.set_first(_first); } { return it; } } ClassName_Commalist _ClassName_Commalist() : { ClassName_Commalist it; Nonempty_ClassName_Commalist _first; } { { it=new ClassName_Commalist(); } _first=_Nonempty_ClassName_Commalist() { it.set_first(_first); } { return it; } } PartOrSyntax_List _PartOrSyntax_List() : { PartOrSyntax_List it; Nonempty_PartOrSyntax_List _first; } { { it=new PartOrSyntax_List(); } [ _first=_Nonempty_PartOrSyntax_List() { it.set_first(_first); } ] { return it; } } Part_Sandwich _Part_Sandwich() : { Part_Sandwich it; Syntax_List _first; Part _inner; Syntax_List _second; } { { it=new Part_Sandwich(); } _first=_Syntax_List() { it.set_first(_first); } _inner=_Part() { it.set_inner(_inner); } _second=_Syntax_List() { it.set_second(_second); } { return it; } } ClassSpec_Commalist _ClassSpec_Commalist() : { ClassSpec_Commalist it; Nonempty_ClassSpec_Commalist _first; } { { it=new ClassSpec_Commalist(); } _first=_Nonempty_ClassSpec_Commalist() { it.set_first(_first); } { return it; } } Subclass_Barlist _Subclass_Barlist() : { Subclass_Barlist it; Nonempty_Subclass_Barlist _first; } { { it=new Subclass_Barlist(); } _first=_Nonempty_Subclass_Barlist() { it.set_first(_first); } { return it; } } RepeatedPart_Sandwich _RepeatedPart_Sandwich() : { RepeatedPart_Sandwich it; Syntax_List _first; RepeatedPart _inner; Syntax_List _second; } { { it=new RepeatedPart_Sandwich(); } _first=_Syntax_List() { it.set_first(_first); } _inner=_RepeatedPart() { it.set_inner(_inner); } _second=_Syntax_List() { it.set_second(_second); } { return it; } } ClassSpec_Sandwich _ClassSpec_Sandwich() : { ClassSpec_Sandwich it; Syntax_List _first; ClassSpec _inner; Syntax_List _second; } { { it=new ClassSpec_Sandwich(); } _first=_Syntax_List() { it.set_first(_first); } _inner=_ClassSpec() { it.set_inner(_inner); } _second=_Syntax_List() { it.set_second(_second); } { return it; } } Syntax_List _Syntax_List() : { Syntax_List it; Nonempty_Syntax_List _first; } { { it=new Syntax_List(); } [ _first=_Nonempty_Syntax_List() { it.set_first(_first); } ] { return it; } } Part_Commalist _Part_Commalist() : { Part_Commalist it; Nonempty_Part_Commalist _first; } { { it=new Part_Commalist(); } _first=_Nonempty_Part_Commalist() { it.set_first(_first); } { return it; } } PlainSyntax_List _PlainSyntax_List() : { PlainSyntax_List it; Nonempty_PlainSyntax_List _first; } { { it=new PlainSyntax_List(); } [ _first=_Nonempty_PlainSyntax_List() { it.set_first(_first); } ] { return it; } } Nonempty_UVertex_List _Nonempty_UVertex_List() : { Nonempty_UVertex_List it; UVertex _it; Nonempty_UVertex_List _next; } { { it=new Nonempty_UVertex_List(); } _it=_UVertex() { it.set_it(_it); } [ _next=_Nonempty_UVertex_List() { it.set_next(_next); } ] { return it; } } Nonempty_IEdge_List _Nonempty_IEdge_List() : { Nonempty_IEdge_List it; UID _it; Nonempty_IEdge_List _next; } { { it=new Nonempty_IEdge_List(); } _it=_UID() { it.set_it(_it); } [ _next=_Nonempty_IEdge_List() { it.set_next(_next); } ] { return it; } } Nonempty_OEdge_List _Nonempty_OEdge_List() : { Nonempty_OEdge_List it; UID _it; Nonempty_OEdge_List _next; } { { it=new Nonempty_OEdge_List(); } _it=_UID() { it.set_it(_it); } [ _next=_Nonempty_OEdge_List() { it.set_next(_next); } ] { return it; } } Nonempty_UEdge_List _Nonempty_UEdge_List() : { Nonempty_UEdge_List it; UEdge _it; Nonempty_UEdge_List _next; } { { it=new Nonempty_UEdge_List(); } _it=_UEdge() { it.set_it(_it); } [ _next=_Nonempty_UEdge_List() { it.set_next(_next); } ] { return it; } } Nonempty_ClassDef_DList _Nonempty_ClassDef_DList() : { Nonempty_ClassDef_DList it; ClassDef _it; Nonempty_ClassDef_DList _next; } { { it=new Nonempty_ClassDef_DList(); } _it=_ClassDef() { it.set_it(_it); } [ _next=_Nonempty_ClassDef_DList() { it.set_next(_next); } ] { return it; } } Nonempty_ClassName_Commalist _Nonempty_ClassName_Commalist() : { Nonempty_ClassName_Commalist it; 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; } } Nonempty_PartOrSyntax_List _Nonempty_PartOrSyntax_List() : { Nonempty_PartOrSyntax_List it; PartOrSyntax _it; Nonempty_PartOrSyntax_List _next; } { { it=new Nonempty_PartOrSyntax_List(); } _it=_PartOrSyntax() { it.set_it(_it); } [ _next=_Nonempty_PartOrSyntax_List() { it.set_next(_next); } ] { return it; } } Nonempty_ClassSpec_Commalist _Nonempty_ClassSpec_Commalist() : { Nonempty_ClassSpec_Commalist it; ClassSpec _it; Nonempty_ClassSpec_Commalist _next; } { { it=new Nonempty_ClassSpec_Commalist(); } _it=_ClassSpec() { it.set_it(_it); } [ "," _next=_Nonempty_ClassSpec_Commalist() { it.set_next(_next); } ] { return it; } } Nonempty_Subclass_Barlist _Nonempty_Subclass_Barlist() : { Nonempty_Subclass_Barlist it; Subclass _it; Nonempty_Subclass_Barlist _next; } { { it=new Nonempty_Subclass_Barlist(); } _it=_Subclass() { it.set_it(_it); } [ "|" _next=_Nonempty_Subclass_Barlist() { it.set_next(_next); } ] { return it; } } Nonempty_Syntax_List _Nonempty_Syntax_List() : { Nonempty_Syntax_List it; Syntax _it; Nonempty_Syntax_List _next; } { { it=new Nonempty_Syntax_List(); } _it=_Syntax() { it.set_it(_it); } [ _next=_Nonempty_Syntax_List() { it.set_next(_next); } ] { return it; } } Nonempty_Part_Commalist _Nonempty_Part_Commalist() : { Nonempty_Part_Commalist it; Part _it; Nonempty_Part_Commalist _next; } { { it=new Nonempty_Part_Commalist(); } _it=_Part() { it.set_it(_it); } [ "," _next=_Nonempty_Part_Commalist() { it.set_next(_next); } ] { return it; } } Nonempty_PlainSyntax_List _Nonempty_PlainSyntax_List() : { Nonempty_PlainSyntax_List it; PlainSyntax _it; Nonempty_PlainSyntax_List _next; } { { it=new Nonempty_PlainSyntax_List(); } _it=_PlainSyntax() { it.set_it(_it); } [ _next=_Nonempty_PlainSyntax_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; int radix; Number num; } { ( ( 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': num = Long.valueOf(s.substring(0, s.length()-1), radix); break; default: num = Integer.valueOf(s, radix); 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)); } } // Lexical specification (largely taken from Java.jack): IGNORE_IN_BNF : {} { " " | "\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" ] > }