/** * name: DTDParser.jj * modified: Apr 2, 2001 * author: John Gebbie * email: j_gebbie@yahoo.com */ options { DEBUG_PARSER = false; } PARSER_BEGIN(DTDParser) import java.io.InputStream; import java.io.FileInputStream; import java.io.FileNotFoundException; public class DTDParser { public static void parse(InputStream aInSt) throws ParseException { // create a parser (this object) DTDParser parser = new DTDParser(aInSt); // parse! parser.dtd(); } public static void main(String[] args) throws ParseException, FileNotFoundException { parse(new FileInputStream(args[0])); } } PARSER_END(DTDParser) TOKEN : { | | | | "." | "-" | "_" | ":" ) > | | | | | | | | | | | | | | | | | "_" | ":" ) ( )* > | } SKIP : { < ( " " | "\t" | "\n" | "\r" )+ > // comment decl updated by Gagandeep Bhatia [mailto:gagan@ebprovider.com] | < "" > | < ""])* ">" > } void dtd() : { } { ( elementDecl() | attListDecl() )* } void elementDecl() : { } { " contentSpec() ">" } void contentSpec() : { } { | | LOOKAHEAD(2) mixed() | children() } void mixed() : { } { "(" ( ( "|" )* ")*" | ")" ) } void children() : { } { seqchoice() [ modifier() ] } void seqchoice() : { } { "(" cp() ( choice() | seq() ) ")" } void choice() : { } { ( "|" cp() )+ } void seq() : { } { ( "," cp() )* } void cp() : { } { ( | seqchoice() ) [ modifier() ] } void modifier() : { } { "*" | "+" | "?" } void attListDecl() : { } { " ( attribDef() )* ">" } void attribDef() : { } { attribType() defaultDecl() } void attribType() : { } { stringType() | tokenizedType() | enumeratedType() } void stringType() : { } { } void tokenizedType() : { } { | | | | | | } void enumeratedType() : { } { ( notationType() | enumeration() ) } void notationType() : { } { "(" ( "|" )* ")" } void enumeration() : { } { "(" ( "|" )* ")" } void defaultDecl() : { } { | | ( [ ] attribValue() ) } void attribValue() : { } { }