Attribute Grammars and XML - PowerPoint PPT Presentation

1 / 13
About This Presentation
Title:

Attribute Grammars and XML

Description:

Decorated parse trees as attributed element trees. XML markups for semantic rules. 2 ... Attribute Grammars and XML use the same parse and element trees ... – PowerPoint PPT presentation

Number of Views:96
Avg rating:3.0/5.0
Slides: 14
Provided by: ISG77
Category:

less

Transcript and Presenter's Notes

Title: Attribute Grammars and XML


1
Attribute Grammars and XML
Harold Boley, DFKI Kaiserslautern
  • Workshop on Attribute Grammars, XML, and RDF
  • Institute for Media and Communications Management
  • University of St. Gallen
  • 20/21 Sept. 2000

2
What Are and How RelateAttribute Grammars
and XML?
  • Both are extensions of context-free grammars
  • Attribute grammars via semantic (evaluation)
    rules over attributes
  • XML via (document-markup) tags, attribute DTDs,
    stylesheets, etc.
  • Will be compared on two exemplary levels
  • Decorated parse trees as attributed element trees
  • XML markups for semantic rules

3
Attribute Grammar ExampleCartesian Move
Sequences
  • In the Cartesian plane move stepwise in the
    directions north, east, south, west
  • Starting from the coordinates X 0, Y 0
    compute the end position after a finite sequence
    of moves
  • Sample computations
  • Sequence e,e,n shall compute X 2, Y 1
  • Sequence s,w,s,e shall compute X 0, Y -2

4
Grammar with Attributes on Nonterminals
Grammar path ? ? path ? step path step ?
n step ? e step ? s step ? w Attributes
path.?Ex x-coordinate of end position path.?Ey
y-coordinate of end position step
.?Dx incremental change of x-coordinate step
.?Dy incremental change of y-coordinate
We will only consider synthesized
attributes, often prefixed by a ?, not
inherited attributes
5
Attribute Grammar with Semantic Rules
Grammar path ? ? path ? step path step ?
n step ? e step ? s step ? w
Semantic Rules path.?Ex 0 ? path.?Ey
0 path1.?Ex step .?Dx path2.?Ex
? path1.?Ey step .?Dy path2.?Ey step .?Dx
0 ? step .?Dy 1 step .?Dx 1 ? step .?Dy
0 step .?Dx 0 ? step .?Dy -1 step .?Dx
-1 ? step .?Dy 0
6
Decorated Parse Treefor Sequence e,e,n
path
Ex 2 Ey 1
Ex 1 Ey 1
Dx 1 Dy 0
e
Ex 0 Ey 1
Dx 1 Dy 0
e
Ex 0 Ey 0
Dx 0 Dy 1
?
n
7
e,e,n-Parse Tree as XML Element
ltpath Ex"2" Ey"1"gt ltstep Dx "1" Dy"0"gt e
lt/stepgt ltpath Ex"1" Ey"1"gt ltstep Dx
"1" Dy"0"gt e lt/stepgt ltpath Ex"0"
Ey"1"gt ltstep Dx "0" Dy"1"gt n lt/stepgt
ltpath Ex"0" Ey"0"gt lt/pathgt
lt/pathgt lt/pathgt lt/pathgt
Attribute grammar parse results and intermediate
states can thus be represented as XML elements
8
DTD Approximation forAttribute Grammar (AG)
lt!ELEMENT path (EMPTY (step, path))
gt lt!ELEMENT step (n e s w) gt lt!ELEMENT
n EMPTY gt lt!ELEMENT e EMPTY gt lt!ELEMENT s EMPTY
gt lt!ELEMENT w EMPTY gt lt!ATTLIST path Ex
CDATA REQUIRED gt lt!ATTLIST path Ey CDATA
REQUIRED gt lt!ATTLIST step Dx CDATA
REQUIRED gt lt!ATTLIST step Dy CDATA
REQUIRED gt
Canonical empty elements instead of terminals
CDATA instead of integers
Semantic Rules of full AGs can be added (via XML
stylesheets, Java, Prolog, ...)
9
e,e,n-XML ElementAccording to DTD
ltpath Ex"2" Ey"1"gt ltstep Dx "1" Dy"0"gt e
lt/stepgt ltpath Ex"1" Ey"1"gt ltstep Dx
"1" Dy"0"gt e lt/stepgt ltpath Ex"0"
Ey"1"gt ltstep Dx "0" Dy"1"gt n lt/stepgt
ltpath Ex"0" Ey"0"gt lt/pathgt
lt/pathgt lt/pathgt lt/pathgt
ltpath Ex"2" Ey"1"gt ltstep Dx "1" Dy"0"gt
lte/gt lt/stepgt ltpath Ex"1" Ey"1"gt ltstep
Dx "1" Dy"0"gt lte/gt lt/stepgt ltpath Ex"0"
Ey"1"gt ltstep Dx "0" Dy"1"gt ltn/gt
lt/stepgt ltpath Ex"0" Ey"0"gt lt/pathgt
lt/pathgt lt/pathgt lt/pathgt
Terminal e becomes empty element lte/gt Terminal n
becomes empty element ltn/gt
10
Prolog-like Form of AGwith Semantic Rules
path.?Ex 0 ? path.?Ey 0 path1.?Ex
step .?Dx path2.?Ex ? path1.?Ey step .?Dy
path2.?Ey
path ? ? path ? step path
path0,0(). pathNx,Ny(HeadTail) -
stepDx,Dy(Head), pathEx,Ey(Tail),
Nx .
(Dx,Ex), Ny . (Dy,Ey). step0,1(n). step
1,0(e). step0,-1(s). step-1,0(w).
step ? n step ? e step ? s step ? w
step .?Dx 0 ? step .?Dy 1 step .?Dx 1 ?
step .?Dy 0 step .?Dx 0 ? step .?Dy
-1 step .?Dx -1 ? step .?Dy 0
Attribute values represented as
...-parameters. Call pathX,Y(e,e,n)
computes X 2, Y 1, e.g. using Relfun
interpreter
11
Parameter-XML Form of AG via RFML-like Generic
Markup
Generic User-defined nonterminals (e.g.
path) dont appear as tags, only between tags
12
Attribute-XML Form of AG via RFML/MathML-likeNon-
Generic Markup
13
Conclusions
  • Attribute Grammars and XML use the same parse and
    element trees
  • There are various possible XML markups for AGs
    semantic rules (cf. RFML/MathML)
  • In future work an AG-markup language could be
    developed and applied for grammar sharing
  • Further levels of the XML/AG relationships should
    be studied, e.g. attribute dependencies,
    rule-evaluation methods, and DOM-level rules
Write a Comment
User Comments (0)
About PowerShow.com