// studio.cd -- CD for Apstudio // Authors - Kedar & Binoy // $Id: studio.cd,v 1.4 2000/10/13 19:31:14 dougo Exp $ //***************************************************************************** // package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.*; import java.io.*; import java.util.*; import edu.neu.ccs.demeter.common.tg.*; // Topmost class in class structure is Graph UGraph = "#Class" "#Dictionary" "#Graph" *l [ Package *l] [ SList(Import) *l ] [ JavaCode *l] //deprecated [< vertices >UVertex_List] Hashtable //vert list <-> hash [< edges > UEdge_List] Hashtable //edge list <-> hash Hashtable [UID] *EOF*. /** TODO: 1. Rethink Package handling. Since new demjava 0.5.6 can have more than one package statement! 2. Same for global & local imports. 3. Remove support for preamble */ // Following is description of class Vertex_List and its parts UVertex_List ~ "#Vertex" "#List" *l + UVertex {*l UVertex } *l- . UVertex : UConstOrAltVertex | UTerm | UInterface *common* < vid > UID < vertexname > UVertexName < position > Coordinates [< incoming > IEdge_List] //incoming uids [< outgoing > OEdge_List] //outgoing uids Vector Vector [Decorator] //subgraph tag < persp > Perspective *extends* NetPrimitive . UConstOrAltVertex : UConstVertex | UAltVertex *common* ParseOrNot Vector [ ScopeIdentifier_List]. ParseOrNot : YaParse | NopParse. YaParse = "#parse". NopParse = "#noparse". UTerm : UTermConstVertex | UTermInterface. IEdge_List ~ "#Incoming" UID { "," UID }. //commalist uid {","uid} OEdge_List ~ "#Outgoing" UID { "," UID }. //commalist uid {","uid} UConstVertex = "#ConstVertex" [< beFore > UBefore][< afTer > UAfter]. UBefore = "#Before" String. UAfter = "#After" String. UAltVertex = "#AltVertex" . UInterface = "#Interface" [ InterfaceModifier_List] JavaCode. InterfaceModifier_List ~ InterfaceModifier { InterfaceModifier }. InterfaceModifier : PublicModifier. PublicModifier = "#public". UTermConstVertex = "#TermConstVertex" . UTermInterface = "#TermInterface" . ScopeIdentifier_List ~ ScopeIdentifier { ScopeIdentifier }. ScopeIdentifier : PublicIdentifier | FinalIdentifier . PublicIdentifier = "#public". FinalIdentifier = "#final". // Following is description of class Edge_List and its parts UEdge_List ~ "#Edge" "#List" *l + UEdge {*l UEdge } *l -. UEdge : USuperEdge | UConstEdge *common* < eid >UID < fromVertex > UID < toVertex > UID [Decorator] //subgraph tag [ BendPoint]//_List ] ArcPerspective *extends* NetPrimitive. //BendPoint_List ~ BendPoint{BendPoint}. USuperEdge : UAltEdge | UExtendEdge | UImplEdge . BendPoint = Coordinates. UAltEdge = "#AltEdge". UExtendEdge = "#ExtendEdge". UImplEdge = "#ImplEdge". UConstEdge = "#ConstEdge" [< edgename > UEdgeName] Cardinality [UBefore][UAfter] [ PartModifier_List]. PartModifier_List ~ PartModifier { PartModifier }. PartModifier : FinalMod | StaticMod | ReadOnlyMod | PrivateMod . FinalMod = "#final". StaticMod = "#static". ReadOnlyMod = "#read-only". PrivateMod = "#private". Cardinality = "#Cardinality" < lower > Lower [ < upper > Upper]. Lower = Integer. Upper = "." "." String. // Classes common to Vertex and Edge UID = < id > Integer. UEdgeName = Ident *implements* NameI. UVertexName = Ident *implements* NameI. // Classes common to Vertex , VertexName , Edge and EdgeName Coordinates = "{" X Y "}". X = Integer . Y = Integer . //Decorator to store the attribute(color?) of vertices and edges Decorator = "travstat"Integer Vector.//PList(Attributes) //Attributes = Integer. //IndependantTraversal= "from" List(SUID) Vector // TOCLASS // List(DUID) Vector // ["bypassing" List(UID) ] // Vector. //SUID = UID. //DUID = UID. //TOCLASS : ToV | ToStopV. ///ToV = "to". //ToStopV = "tostop". UniqueIDGenerator= . // generate.cd -- class dictionary for Demeter/Java code generator // Program is the starting nonterminal of the class dictionary grammar, // as well as the root class of the class dictionary class graph. *public* Program = GlobalImports ClassGraph *EOF* . GlobalImports = [ SList(Import) *l ] . Import = "import" PackageName [ ImportAllClasses ] ";". ImportAllClasses = ".*". ClassGraph = Hashtable DList(ClassGraphEntry). ClassGraphEntry : Directive | Definition. Directive : ParseDirective | VisitorDirective | PackageDirective. ParseDirective = ParseKeyword. VisitorDirective = VisitorKeyword. PackageDirective = Package *l LocalImports. Package = "package" PackageName ";". LocalImports = [ SList(Import) *l ] . Definition : ClassDef. *public* ClassDef = List(ClassKeyword) ParamClassName [ *s ParseDirective ] *s ClassParts [ ClassMethods ] [ *s EOFtoken ] "." . ParamClassName = ClassName ["(" Commalist(ClassName) ")"]. ClassParts : ConstOrAltClass | RepetitionClass. ConstOrAltClass : ConstructionClass | AlternationClass *common* + + + List(PartOrSyntax) ClassParents - - -. PartOrSyntax : Part | OptionalPart | Syntax. Part = [ "<" PartName ">" *s ] List(PartKeyword) ClassSpec [ PartInit ]. PartInit = PartInitKeyword *s JavaCode. OptionalPart = "[" [LocalLookahead] Sandwich(Part) "]". ClassParents = [ Superclasses ] [ Interfaces ]. Superclasses = ExtendsKeyword Commalist(Superclass). Superclass = ClassSpec. Interfaces = ImplementsKeyword Commalist(Interface). Interface = ClassSpec. ConstructionClass = "=". AlternationClass = ":" + + + [ *lookahead* (@ _Subclass() @) Barlist(Subclass) ] - - - [ CommonKeyword ]. Subclass = [LocalLookahead] ClassSpec. LocalLookahead = LookaheadKeyword JavaCode. RepetitionClass = "~" Sandwich(RepeatedPart). RepeatedPart = [ ClassSpec ] "{" [LocalLookahead] Sandwich(ClassSpec) *s "}". Sandwich(S) = List(Syntax) *s S List(Syntax) . ClassSpec = ClassName ["(" Commalist(ClassSpec) ")" ] . Syntax : PlainSyntax | PrintCommand. PlainSyntax = String. PrintCommand : PrintIndent | PrintUnindent | PrintSkip | PrintSpace. PrintIndent = "+" . PrintUnindent = "-" . PrintSkip = "*l" . PrintSpace = "*s" . ////////////////////// // Behavior (methods). ////////////////////// // ProgramBehavior is the starting nonterminal of the behavior file grammar. ProgramBehavior = [ DList(Behavior) ] *EOF* . Behavior : StrategyDefinition | ClassBehavior. StrategyDefinition = "strategy" StrategyName "=" StrategyExpression ".". StrategyExpression : StrategyGraph | PathDirective | StrategyVariable | CompoundStrategy common [ "with" *s NameMap ]. StrategyGraph = "{" *l + [ "vec:" *s Vector ] SList(SGEdge) - *l "}" *s [ "source:" ClassGlobSpec ] [ "source-edge:" NList(Integer) ] [ "target:" ClassGlobSpec ] implements StrategyGraphI . SGEdge = ClassGlobSpec *s "->" *s ClassGlobSpec [ NegativeConstraint ]. PathDirective = [ NegativeConstraint ] List(PathSegment) TargetDirective. PathSegment = PositiveConstraint [ NegativeConstraint ]. Constraint : PositiveConstraint | NegativeConstraint *common* *s GlobSpec. PositiveConstraint : Through | Via. // synonyms Through = "through". Via = "via". NegativeConstraint : Bypassing | OnlyThrough. // antonyms Bypassing = "bypassing". OnlyThrough = "only-through". TargetDirective : To | ToStop *common* ClassGlobSpec. To = "to". ToStop = "to-stop". StrategyVariable = "do" StrategyName. CompoundStrategy : Join | Merge | Intersect *common* "(" Commalist(StrategyExpression) ")". Join = "join". Merge = "merge". Intersect = "intersect". NameMap = "{" *s Commalist(NameBinding) *s "}". NameBinding = Name "=" Name. GlobSpec : OneGlob | GlobSet. OneGlob = Glob. GlobSet = "{" *s [ Commalist(Glob) *s ] "}". Glob : ClassGlob | EdgeGlob. EdgeGlob : PartGlob | SubclassGlob | SuperclassGlob. ClassGlob = ClassNameGlob. PartGlob = "->" *s SourceGlob "," *s PartNameGlob "," *s DestGlob. SubclassGlob = "=>" *s SourceGlob "," *s DestGlob. SuperclassGlob = ":>" *s SourceGlob "," *s DestGlob. SourceGlob = ClassNameGlob. DestGlob = ClassNameGlob. ClassNameGlob : ClassNameExact | AnyClass. ClassNameExact = ClassName. AnyClass = "*". PartNameGlob : PartNameExact | AnyPart. PartNameExact = PartName. AnyPart = "*". ClassGlobSpec : OneClassGlob | ClassGlobSet. OneClassGlob = ClassGlob. ClassGlobSet = "{" *s Commalist(ClassGlob) *s "}". ClassBehavior = ClassGlobSpec ClassMethods. ClassMethods = "{" *l + [ SList(Method) ] - *l "}" [ "wrappers:" Hashtable // maps Wrapper-kind -> HostSet ] . HostSet = [ "exact:" Hashtable ] // globs with no stars [ "partnames:" Hashtable ] // -> *,name,* globs [ "globs:" GlobSet] . // other globs Method : TraversalDef | MethodDef | Wrapper | Accessor | Constructor | Start | Finish | ReturnValue | Verbatim. // Class graph traversal definitions. TraversalDef = "traversal" TraversalName TraversalParms *s "{" *l + StrategyExpression ";" - *l "}". TraversalParms = "(" [ Commalist(Visitor) ] ")" . Visitor = ClassName [ VisitorName ]. // Adaptive methods. MethodDef = MethodSignature MethodBody. MethodSignature = List(MethodKeyword) JavaType MethodName "(" [ Commalist(MethodParm) ] ")" Throws. MethodKeyword : PublicMethod | ProtectedMethod | PrivateMethod | StaticMethod | FinalMethod | AbstractMethod. PublicMethod = "public". ProtectedMethod = "protected". PrivateMethod = "private". StaticMethod = "static". FinalMethod = "final". AbstractMethod = "abstract". MethodParm = JavaType ParmName List(ArraySpec). Throws = [ *s "throws" Commalist(ClassName) ]. MethodBody : VerbatimMethodBody | AdaptiveMethodBody | NoMethodBody. VerbatimMethodBody = JavaCode. AdaptiveMethodBody = TraversalExpression VisitorExpression. NoMethodBody = ";". TraversalExpression : TraversalRef | TraversalSpec. TraversalRef = [Equals] TraversalName. Equals = "=". // optional syntax TraversalSpec = StrategyExpression. VisitorExpression : VisitorRef | VisitorSpec. VisitorRef = "(" Commalist(ClassName) ")" ";". VisitorSpec = ClassMethods. // Visit methods. Wrapper = WrapperKind HostSpec JavaCode. WrapperKind : Before | Around | After. Before = "before". Around = "around". After = "after". HostSpec : GlobSpec. // Derived part accessors. Accessor : Getter | Setter *common* PartName JavaCode . Getter = "get" . Setter = "set" . // Constructor method. // Only no-arg constructors supported for now. Constructor = "init" JavaCode. // Methods called at the beginning and ending of a traversal. Start = "start" JavaCode. Finish = "finish" JavaCode. // Code for computing the return value of a visitor when used in an // adaptive method. ReturnValue = "return" [ JavaType ] JavaCode. // Verbatim java code. Verbatim = JavaCode. // Terminal buffer classes. PackageName ~ IdentOrKeyword { *lookahead* (@ 2 @) "." IdentOrKeyword }. public ClassName = Name implements NameI. public PartName = IdentOrKeyword implements NameI. TraversalName = Name. VisitorName = Name. MethodName = Ident. ParmName = Ident. StrategyName = Ident. JavaType = Name List(ArraySpec). ArraySpec = "[" "]". JavaCode = Text. Name ~ Ident { *lookahead* (@ "." _Ident(), { "=:~(".indexOf(getToken(3).image) == -1 } @) // kludge!! "." Ident }. // All the keywords that look like identifiers in the class dictionary // grammar that aren't keywords in Java. IdentOrKeyword : ParseIdent | NoParseIdent | VisitorsIdent | EndVisitorsIdent | VisitorIdent | NotParsedIdent | DerivedIdent | InitIdent | CommonIdent | LookaheadIdent | OtherIdent. ParseIdent = "parse". NoParseIdent = "noparse". VisitorsIdent = "visitors". EndVisitorsIdent = "endvisitors". VisitorIdent = "visitor". NotParsedIdent = "notparsed". DerivedIdent = "derived". InitIdent = "init". CommonIdent = "common". LookaheadIdent = "lookahead". OtherIdent = Ident. // Keywords with optional star forms. ParseKeyword : DoParse | DontParse. DoParse : DoParseWithoutStars | DoParseWithStars. DoParseWithoutStars = "parse". DoParseWithStars = *s "*parse*" *s. DontParse : DontParseWithoutStars | DontParseWithStars. DontParseWithoutStars = "noparse". DontParseWithStars = *s "*noparse*" *s. VisitorKeyword : BeginVisitors | EndVisitors. BeginVisitors : BeginVisitorsWithoutStars | BeginVisitorsWithStars. BeginVisitorsWithoutStars = "visitors". BeginVisitorsWithStars = *s "*visitors*" *s. EndVisitors : EndVisitorsWithoutStars | EndVisitorsWithStars. EndVisitorsWithoutStars = "endvisitors". EndVisitorsWithStars = *s "*endvisitors*" *s. ClassKeyword : PublicClass | FinalClass | InterfaceClass | VisitorClass | NotParsedClass. PublicClass : PublicClassWithoutStars | PublicClassWithStars. PublicClassWithoutStars = "public". PublicClassWithStars = *s "*public*" *s. FinalClass : FinalClassWithoutStars | FinalClassWithStars. FinalClassWithoutStars = "final". FinalClassWithStars = *s "*final*" *s. InterfaceClass : InterfaceClassWithoutStars | InterfaceClassWithStars. InterfaceClassWithoutStars = "interface". InterfaceClassWithStars = *s "*interface*" *s. VisitorClass : VisitorClassWithoutStars | VisitorClassWithStars. VisitorClassWithoutStars = "visitor". VisitorClassWithStars = *s "*visitor*" *s. NotParsedClass : NotParsedClassWithoutStars | NotParsedClassWithStars. NotParsedClassWithoutStars = "notparsed". NotParsedClassWithStars = *s "*notparsed*" *s. PartKeyword : FinalPart | StaticPart | ReadOnlyPart | PrivatePart | DerivedPart. FinalPart : FinalPartWithoutStars | FinalPartWithStars. FinalPartWithoutStars = "final". FinalPartWithStars = *s "*final*" *s. StaticPart : StaticPartWithoutStars | StaticPartWithStars. StaticPartWithoutStars = "static". StaticPartWithStars = *s "*static*" *s. ReadOnlyPart : ReadOnlyPartWithoutStars | ReadOnlyPartWithStars. ReadOnlyPartWithoutStars = "read-only". ReadOnlyPartWithStars = *s "*read-only*" *s. PrivatePart : PrivatePartWithoutStars | PrivatePartWithStars. PrivatePartWithoutStars = "private". PrivatePartWithStars = *s "*private*" *s. DerivedPart : DerivedPartWithoutStars | DerivedPartWithStars. DerivedPartWithoutStars = "derived". DerivedPartWithStars = *s "*derived*" *s. PartInitKeyword : PartInitKeywordWithoutStars | PartInitKeywordWithStars. PartInitKeywordWithoutStars = "init". PartInitKeywordWithStars = *s "*init*" *s. ExtendsKeyword : ExtendsKeywordWithoutStars | ExtendsKeywordWithStars. ExtendsKeywordWithoutStars = "extends". ExtendsKeywordWithStars = *s "*extends*" *s. ImplementsKeyword : ImplementsKeywordWithoutStars | ImplementsKeywordWithStars. ImplementsKeywordWithoutStars = "implements". ImplementsKeywordWithStars = *s "*implements*" *s. CommonKeyword : CommonWithoutStars | CommonWithStars. CommonWithoutStars = *l + "common" -. CommonWithStars = *l + *s "*common*" *s -. LookaheadKeyword : LookaheadKeywordWithoutStars | LookaheadKeywordWithStars. LookaheadKeywordWithoutStars = "lookahead". LookaheadKeywordWithStars = *s "*lookahead*" *s. EOFtoken : EOFtokenWithoutStars | EOFtokenWithStars. EOFtokenWithoutStars = "EOF". EOFtokenWithStars = *s "*EOF*" *s. // Parameterized class definitions. List(S) ~ {*s S}. NList(S) ~ S {*s S}. SList(S) ~ S { *l S } . DList(S) ~ S { *l *l S } *l . Commalist(S) ~ S {"," *s S}. Barlist(S) ~ S { *l "|" *s S}. *noparse* // Utility classes. TraversalMethodName = MethodName. UniversalTraversalGraph = extends TraversalGraph. ClassType = boolean boolean boolean boolean boolean boolean boolean boolean. PartType = boolean boolean boolean boolean boolean . Parts ~ { Part }. ///********** //visitors (text-uml ones) //turn off parsing for the visitors noparse //visitors PlacementVisitor = UGraph . EdgeDistinctionVisitor = String. ClassNameRetVisitor = ClassName. ClassNameTranspVisitor = ParamClassName. EdgeVisitor = EdgeDistinctionVisitor ClassNameTranspVisitor UGraph. //************ // Visitors for UML - to - TEXT traversals VertexReadingVisitor = UGraph String Integer Integer . EdgeReadingVisitor = UGraph String String Integer String Integer Integer . // Visitors and Main class (the GUI ones) ReadVertexVisitor= VertexContainer . VertexContainer = < construction > Vector < alternation > Vector < termination > Vector. ReadEdgeVisitor = < elements > EdgeContainer . EdgeContainer = < construction > Vector < alternation > Vector . Main = . CountingVisitor = Integer . //TraversalVisitor = UGraph IndependantTraversal . visitor superInitVisitor: InitVisitor | HashCreateVisitor | TGCreateVisitor | TGUpdateVisitor. InitVisitor = . HashCreateVisitor =. ListVectorVisitor = VectorVectorVector. DecoCollectVisitor =UID Vector. tostopVisitor = . RepClassSpecVisitor = Name Name. PlaceVertexVisitor = Coordinates Hashtable Hashtable. SomeClassSpecVisitor = UConstEdge. //Visitors for cd2gcd : for Modifiers IntModVisitor = InterfaceModifier_List . ClassModVisitor = ScopeIdentifier_List . PartModVisitor = PartModifier_List . //visitors for cdstring.beh cdStringVisitor : ConstVisitor | AltVisitor | IntVisitor *common* String. ConstVisitor = Hashtable Hashtable . AltVisitor = Hashtable Hashtable . IntVisitor = Hashtable Hashtable . //visitors for CTGstrategy.beh and CTGglob.beh visitors ClassGlobVisitor : . ClassNameAccessor : . GlobVisitor : ClassGlobCollector | SGEdgeMatcher . ClassGlobCollector = ClassGlobSet. SGEdgeMatcher = NameI int Vector. EdgeGlobMaker = ClassName ClassName ClassName PartName Glob extends EdgePartsVisitor. //visitors for CTGsubgraph.beh TGCreateVisitor = Hashtable. TGUpdateVisitor = Hashtable TraversalGraph. endvisitors //visitor for gcdsave.beh & extracting propagation graph SaveGraphVisitor = < graphString > String . SelectMarkedVisitor = boolean boolean boolean String String. // Visitors for strategy graph extraction SGraphCollector = Vector Vector. VecVisitor = Vector. StringVisitor = String. DummyVisitor=.