// generate.cd -- class dictionary for DemeterJ code generator // $Id: generate.cd,v 1.11 2000/09/19 21:08:21 dougo Exp $ // modified for syntax commands 2004/04/19 // import edu.neu.ccs.demeter.aplib.*; import edu.neu.ccs.demeter.dj.*; import java.util.*; // import java.util.zip.*; import java.io.*; Main = . Input = ClassGraphh SyntaxEnhancement. // Program is the starting nonterminal of the class dictionary grammar, // as well as the root class of the class dictionary class graph. ClassGraphh = DList(Definition). Definition : ClassDef. public ClassDef = ParamClassName *s ClassParts "." . ParamClassName = ClassName ["(" Commalist(ClassName) ")"]. ClassParts : ConstOrAltClass | RepetitionClass. ConstOrAltClass : ConstructionClass | AlternationClass *common* + // The following: // List(ClassElement) // changed to: List(ClassElementWithSyntax) -. // The following: // ClassElement : Part | OptionalPart | Syntax. // changed to: ClassElement : Part | OptionalPart . ClassElementWithSyntax : ClassElement | SandwichedClassElement . SandwichedClassElement = PSandwich(ClassElement). // bug in DemeterJ PSandwich(S) = "{" Sandwich(ClassElement) "}". // the following does not work: // PSandwich(S) = "{" Sandwich(S) "}". Part = *l [ "<" PartName ">" *s ] ClassSpec. OptionalPart = *l "[" Sandwich(Part) "]". ConstructionClass = "=". AlternationClass = ":" + [ Barlist(ClassSpec) ] - "common". RepetitionClass = "~" Sandwich(RepeatedPart). RepeatedPart = [ ClassSpec ] "{" Sandwich(ClassSpec) *s "}". Sandwich(S) = List(Syntax) *s S List(Syntax) . ClassSpec = ClassName ["(" Commalist(ClassSpec) ")" ] . Syntax : SyntaxToken | PrintCommand. SyntaxToken = String. PrintCommand : PrintIndent | PrintUnindent | PrintSkip | PrintSpace. PrintIndent = "+" . PrintUnindent = "-" . PrintSkip = "*l" . PrintSpace = "*s" . // Terminal buffer classes. ClassName = Ident. PartName = Ident. // 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}. ////////////////////// //syntax enhancement// ////////////////////// SyntaxEnhancement = List(Enhancement) EOF. Enhancement = *l Where EnhancementBody. EnhancementBody : ClassBody | PartCoordinate | OptionalPartCoordinate | CollectionCoordinate common ":" SyntaxToken . // also applies outside of optional parts PartCoordinate = "part" SyntaxClassName "." SyntaxPartName. // only for optional parts OptionalPartCoordinate = "inside" "optional" "part" SyntaxClassName "." SyntaxPartName. ClassBody = "class" SyntaxClassName. CollectionCoordinate = "collection" SyntaxClassName CurlyBracket. CurlyBracket : Left | Right. Left = "{". Right = "}". SyntaxClassName = Ident. SyntaxPartName = Ident. Where : Before | After. Before = "before". After = "after". //populates hashtable with classgraph information ClassGraphVisitor = extends Visitor. //provides behavior for different types of syntax commands CommandVisitor = extends Visitor. //three types ClassCommandVisitor = extends Visitor. CollectionCommandVisitor = extends Visitor. PartCommandVisitor = extends Visitor.