The connection between Context free grammars and XML
The connection between Context -free grammars and XML Guðmundur Freyr Jónasson 11/29/2020 Algorithms, Logic and Complexity 1
Context-Free Grammars Variables: A, B Terminals: 0, 1, # Nr of rules: 3 Derivation of the string 000#111: 11/29/2020 Algorithms, Logic and Complexity 2
Document Type Definition (DTD) • DTD defines the legal building blocks of an XML document with a list of legal elements and attributes. • XML validity requires that a document follows the constraints expressed in its document type definition, which provides a rough equivalence to a context-free grammar for a document type. • DTD is specified using “Extended Context-Free Grammar”. 11/29/2020 Algorithms, Logic and Complexity 3
Extended Context-Free Grammar • Allows regular expressions over terminals and non-terminals on the right hand side of productions. • The regular expression operators are ∪, * and concatenation. • We could write grammar G as follows: Or Where S is the start symbol in both cases. 11/29/2020 Algorithms, Logic and Complexity 4
DTD Syntax • < !ELEMENT name (model) > – ELEMENT is a keyword – name is the element name being declared – model is the elements content model • The content model is specified using a regular expression over element names. • We now have sequences of element names rather then sequences of symbols (strings) like in CFG. 11/29/2020 Algorithms, Logic and Complexity 5
Regular Expressions vs. DTD Syntax 11/29/2020 Algorithms, Logic and Complexity 6
CFG and DTD example 11/29/2020 Algorithms, Logic and Complexity 7
Conclusion • Both DTD for XML and CFG describe languages with certain rules and restrictions, and thereby declare what’s legal and what’s not in a given language. • An XML document is considered valid if it’s well formed and has been validated against a DTD. • A string is a valid string in a given Context-free language if the Context-free grammar for that language can generate it. 11/29/2020 Algorithms, Logic and Complexity 8
References • Introduction to the Theory of Computation, 2 nd edition, M. Sipser, Course Technology, 2005. • W 3 Schools – Learn DTD: http: //w 3 schools. com/dtd/default. asp • Extensible Markup Language (XML) Fourth Edition: http: //www. w 3. org/TR/REC-xml/ • Languages, Grammars and DTDs: http: //www. dcs. bbk. ac. uk/~ptw/teaching/dtd-new/notes. html 11/29/2020 Algorithms, Logic and Complexity 9
- Slides: 9