generating sgml specific editors
play

Generating SGML specific editors from DTDs to Attribute Grammars - PDF document

J R o o h l a m a s o l r a C s 2 4 0 9 / 0 3 / Generating SGML specific editors from DTDs to Attribute Grammars Jos Carlos Ramalho Alda Reis Lopes Pedro Rangel Henriques epl@di.uminho.pt Contents Behind the


  1. J R o o h l a m a s o l r a C é s 2 4 0 9 / 0 3 / Generating SGML specific editors from DTDs to Attribute Grammars José Carlos Ramalho Alda Reis Lopes Pedro Rangel Henriques epl@di.uminho.pt Contents • Behind the scene • The main goal • Attribute grammars: why and what • DTD ⇒ AG conversion • Future work MT'98 - 19/20 Nov.1998 - Chicago - USA 2 t c G o ? e m u D o y L M G S t n D : W h e r e o i e s Q u a l s 1

  2. J R o h l a m a s o l r a C é s o 2 4 0 3 / / 9 0 Behind the scene • Last year conference (Washington) – Semantic Validation: the possibility to add constraints and context conditions • Markup Languages Journal – Processing constraints • type inference • value normalization MT'98 - 19/20 Nov.1998 - Chicago - USA 3 Type inference Problem: how to process ... ? Constraint: latitude > 39 and latitude < 42.5 Document: ...<latitude>41.32</latitude>... Answer: ...<latitude type=“float”>41.32</latitude>... MT'98 - 19/20 Nov.1998 - Chicago - USA 4 W c s t n e m u D o ? L M G S : o h e r e D o e s Q G u a l i t y 2

  3. J R o o h l a m a s o l r a C é s 2 4 0 9 / 0 3 / Value normalization Problem: How can I identify ...? ... King <name>Affonso</name> proclaimed several ... ... And his soldiers battled against <name>Afonso</name>. ...and that church was built in the <date>XVIII century</date>. ...it all happened on <date> the fifth October</date>... Answer ...King <name value=“Afonso”>Affonso</name>... ...it all happened on <date value=“xxxx.10.05”>the fifth... MT'98 - 19/20 Nov.1998 - Chicago - USA 5 Programs ⇔ SGML Documents • Have a support • Have a support markup language formally language defined in defined SGML • Processing - compiler • Processing - parser – lexical analysis – lexical analysis – syntactic analysis – syntactic analysis – semantic analysis – semantic analysis • complex: type checking; • very simple: ID - IDREF type inference, ... coupling • Can be formally specified: Attribute Grammars MT'98 - 19/20 Nov.1998 - Chicago - USA 6 L m S : s t n e u G M c o D i h W u y G o ? l a Q t s o D e r e e 3

  4. J R o o h l a m a s o l r a C é s 2 4 0 3 / 0 9 / INES - Document Programming Environment Doc X DTD “X” INES Designer Doc Y Constraints Context Rules Style Specification Doc Z Texto “Y” Texto “X” Texto “Z” Utilizador Utilizador Utilizador A B C MT'98 - 19/20 Nov.1998 - Chicago - USA 7 INES: inside Errors Designer SGML text Scheme code RTF DTD Editor DTD SGEN Editor Generator DTD PostScript Context Constraints Editor “X” Editor Doc X Style Specification DSSSL Errors Editor Text Utilizador working projected MT'98 - 19/20 Nov.1998 - Chicago - USA 8 : s t n e m u t h c o D L M G S W r e u o G y i l a Q ? s e o D e 4

  5. J R o o h l a m a s o l r a C é s / 4 0 2 0 3 / 9 Why Attribute Grammars? The Chomsky Hierarchy Grammar level Algorithm complexity MT'98 - 19/20 Nov.1998 - Chicago - USA 9 Chomsky Hierarchy Grammar level Algorithm • 0 - unrestricted • Turing Machine • 1 - Context-Sensitive • Linear-Bounded Automaton • 2 - Context-Free • Push-Down Automaton • Finite-State Automaton • 3 - Regular A grammar is classified by the highest Chomsky level it fits MT'98 - 19/20 Nov.1998 - Chicago - USA 10 D m : s t n e u W c o D L M G S h o i e s Q u a l t r y G o ? e e 5

  6. J o h l a m a R o s l r a C é s o 2 4 0 0 / 3 / 9 Attribute Grammars To have a level 2 grammar with level 1 expressive power! Interesting languages have context! • Is this element already defined? • Are open brackets paired with closing ones? • Does this variable have the correct type? MT'98 - 19/20 Nov.1998 - Chicago - USA 11 Attribute Grammars • Semantics – Context conditions and constraints as attribute equations • New concepts in compiling – incremental parsing: being able to produce an instance of the AST at any time – incremental evaluation: recompiling only what is really necessary MT'98 - 19/20 Nov.1998 - Chicago - USA 12 : s t n e m u e h c o D L M G S W r Q e D o e s u ? a l i t y G o 6

  7. J R o o h l a m a s o l r a C é s 2 4 0 9 / 0 3 / AG: formal definition AG = <G, A, R, C> G is a context free grammar (level 2): G = <T, N, S, P> T - set of terminal symbols (alphabet) N - set of nonterminal symbols S - start symbol or axiom (S belongs to N) P - set of derivation rules A is the set of all attributes: intrinsic, inherited and synthesized R is the set of attribute evaluation rules C is the set of all contextual conditions MT'98 - 19/20 Nov.1998 - Chicago - USA 13 AG: example DTD → Decls Decls.ElemTab = ( ) Decls → Dec Decls Dec.ElemTab = Decls.ElemTab Decls$2.ElemTab = Dec.ElemNewTab | ε Dec → ElemDec ElemDec.ElemTab = Dec.ElemTab Dec.ElemNewTab = ElemDec.ElemNewTab | AttDec ... ElemDec → gi min min Content if( not exist( gi, ElemDec.ElemTab )) ElemDec.ElemNewTab = insert( ElemDec.ElemTab, gi ) else error(“Element already defined!”) MT'98 - 19/20 Nov.1998 - Chicago - USA 14 Q m : s t n e u W c o D L M G S h u o a l i t y G ? e s e o D e r 7

  8. J R o o h l a m a s o l r a C é s 2 4 0 9 / 0 3 / AG: example (cont.) MT'98 - 19/20 Nov.1998 - Chicago - USA 15 AG implementation tool: SGen • It allows attribute definitions • It allows attribute equations definitions • It provides an evaluator for those equations • Sgen – based in a formal language: the interface, attribute equations, ... – multiple views of the internal representation MT'98 - 19/20 Nov.1998 - Chicago - USA 16 G o ? m u c n t o D L M G S y i t e : W h e r e D l o e s Q u a s 8

  9. J R o o h l a m a s o l r a C é s / 0 2 4 0 3 / 9 DTD2AG conversion • Elements and Attributes • Content models – connectors – occurrence indicators • SGML “specials” The AG internal representation is very similar to a grove. Disjoint things in SGML will have to merge. MT'98 - 19/20 Nov.1998 - Chicago - USA 17 Elements and Attributes SGML: <!ELEMENT Letter - - (Date,Name+,Message,End)> <!ATTLIST Letter Type (work|family|friend) work Idiom (en|pt|fr|sp) en> S1: Attributes as part of the content model Letter → Type Idiom Date NameList Message End S2: Attributes apart from content model Letter → LetterAtt LetterContent S3: Attributes as the AG synthesized attributes LetterAtt → Type Idiom Letter → Date NameList Message End LetterContent → Date NameList Message End Letter.type = ... Letter.idiom = ... MT'98 - 19/20 Nov.1998 - Chicago - USA 18 s m : s t n e u W c o D L M G S h Q u a l i t y G e o ? e o D r e 9

  10. J R o h l a m a s o l r a C é s o 2 4 0 3 / / 9 0 Connectors C1: , SGML: <!ELEMENT Letter - - (Date,Name+,Message,End)> AG: Letter → Date NameList Message End C2: | SGML: <!ELEMENT Letter - - (Date|Name+|Message|End)> AG: Letter → Date | NameList | ... MT'98 - 19/20 Nov.1998 - Chicago - USA 19 Connectors C3: & SGML: <!ELEMENT Letter - - (Date&Name+&Message&End)+> AG1: all possible combinations Letter → Date NameList ... | NameList Date ... ... AG2: transform SGML and add constraint <!ELEMENT Letter - - (Date|Name+|Message|End)> CC: � x in Content, ∃ 1 x Letter → X Letter → X Letter X → Date if( exists( Date.gi, X.ElemTab) ) then error “...” | NameList | Message | End MT'98 - 19/20 Nov.1998 - Chicago - USA 20 c o D L M G S m u e W u h e r e D : e s Q a n l i t y G o ? s t o 1 0

  11. J R o h l a m a s o l r a C é s o 2 4 0 3 / / 9 0 Occurrence indicators OI1: ? SGML: <!ELEMENT Letter - - (Date?|...)> AG: Letter → Date ... Date → ε | ... OI2: * or + SGML: <!ELEMENT Letter - - (Date|Message|...)*> AG: Letter → ε | LetterContent Letter MT'98 - 19/20 Nov.1998 - Chicago - USA 21 AG: an open path to semantics MT'98 - 19/20 Nov.1998 - Chicago - USA 22 W c s t n e m u D o ? L M G S : o h e r e D o e s Q G u a l i t y 1

  12. J o h l a m a R o s o l r a C é s 4 0 2 / 0 3 / 9 Questions? MT'98 - 19/20 Nov.1998 - Chicago - USA 23 New SGML auth. and proc. model Validation Validation ESIS Process 2/2 Process 1/2 CAMILA Parser SGML Doc. DTD2CAM OK / errors OK / errors DTD DTD Valid SGML Doc. Editor Editor Authoring Design Process Process MT'98 - 19/20 Nov.1998 - Chicago - USA 24 D o e u L M G S c e n e t s : W h e r m D o s Q u a l i t y G o ? 2 1

Recommend


More recommend