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

generating sgml specific editors
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
1

Generating SGML specific editors

from DTDs to Attribute Grammars

José Carlos Ramalho Alda Reis Lopes Pedro Rangel Henriques epl@di.uminho.pt

MT'98 - 19/20 Nov.1998 - Chicago - USA 2

Contents

  • Behind the scene
  • The main goal
  • Attribute grammars: why and what
  • DTD ⇒ AG conversion
  • Future work
slide-2
SLIDE 2 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
2

MT'98 - 19/20 Nov.1998 - Chicago - USA 3

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 4

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>...

slide-3
SLIDE 3 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
3

MT'98 - 19/20 Nov.1998 - Chicago - USA 5

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 6

Programs ⇔ SGML Documents

  • Have a support

language formally defined

  • Processing - compiler

– lexical analysis – syntactic analysis – semantic analysis

  • complex: type checking;

type inference, ...

  • Can be formally

specified: Attribute Grammars

  • Have a support markup

language defined in SGML

  • Processing - parser

– lexical analysis – syntactic analysis – semantic analysis

  • very simple: ID - IDREF

coupling

slide-4
SLIDE 4 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
4

MT'98 - 19/20 Nov.1998 - Chicago - USA 7

INES - Document Programming Environment

Context Rules

Designer DTD “X”

INES

Utilizador A Utilizador B Utilizador C Texto “Y” Texto “X” Texto “Z” Doc X Doc Y Doc Z

Constraints

Style Specification

MT'98 - 19/20 Nov.1998 - Chicago - USA 8

INES: inside

Designer DTD Editor Editor Generator SGEN “X” Editor Utilizador Errors Text Errors Doc X Scheme code Context Editor

Constraints

DSSSL Editor

Style Specification

RTF PostScript DTD DTD

SGML text

working projected

slide-5
SLIDE 5 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
5

MT'98 - 19/20 Nov.1998 - Chicago - USA 9

Why Attribute Grammars?

The Chomsky Hierarchy

Grammar level Algorithm complexity

MT'98 - 19/20 Nov.1998 - Chicago - USA 10

Chomsky Hierarchy

  • 0 - unrestricted
  • 1 - Context-Sensitive
  • 2 - Context-Free
  • 3 - Regular
  • Turing Machine
  • Linear-Bounded

Automaton

  • Push-Down

Automaton

  • Finite-State Automaton

Grammar level Algorithm

A grammar is classified by the highest Chomsky level it fits

slide-6
SLIDE 6 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
6

MT'98 - 19/20 Nov.1998 - Chicago - USA 11

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 12

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

slide-7
SLIDE 7 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
7

MT'98 - 19/20 Nov.1998 - Chicago - USA 13

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 14

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!”)

slide-8
SLIDE 8 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
8

MT'98 - 19/20 Nov.1998 - Chicago - USA 15

AG: example (cont.)

MT'98 - 19/20 Nov.1998 - Chicago - USA 16

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

slide-9
SLIDE 9 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
9

MT'98 - 19/20 Nov.1998 - Chicago - USA 17

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 18

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 LetterAtt → Type Idiom LetterContent → Date NameList Message End S3: Attributes as the AG synthesized attributes Letter → Date NameList Message End Letter.type = ... Letter.idiom = ...

slide-10
SLIDE 10 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
1

MT'98 - 19/20 Nov.1998 - Chicago - USA 19

Connectors

SGML: <!ELEMENT Letter - - (Date,Name+,Message,End)> AG: Letter → Date NameList Message End C1: , SGML: <!ELEMENT Letter - - (Date|Name+|Message|End)> AG: Letter → Date | NameList | ... C2: |

MT'98 - 19/20 Nov.1998 - Chicago - USA 20

Connectors

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, ∃1x Letter → X Letter → X Letter X → Date if( exists( Date.gi, X.ElemTab) ) then error “...” | NameList | Message | End

C3: &

slide-11
SLIDE 11 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
1

MT'98 - 19/20 Nov.1998 - Chicago - USA 21

Occurrence indicators

SGML: <!ELEMENT Letter - - (Date?|...)> AG: Letter → Date ... Date → ε | ... OI1: ? SGML: <!ELEMENT Letter - - (Date|Message|...)*> AG: Letter → ε | LetterContent Letter OI2: * or +

MT'98 - 19/20 Nov.1998 - Chicago - USA 22

AG: an open path to semantics

slide-12
SLIDE 12 J
  • s
é C a r l
  • s
R a m a l h
  • 9
/ 3 / 2 4 S G M L D
  • c
u m e n t s : W h e r e D
  • e
s Q u a l i t y G
  • ?
1 2

MT'98 - 19/20 Nov.1998 - Chicago - USA 23

Questions?

MT'98 - 19/20 Nov.1998 - Chicago - USA 24

New SGML auth. and proc. model

Editor Editor Parser DTD Design Process Authoring Process

OK / errors SGML Doc. Valid SGML Doc.

DTD

DTD2CAM ESIS OK / errors CAMILA

Validation Process 2/2 Validation Process 1/2