Presentation is loading. Please wait.

Presentation is loading. Please wait.

Attribute Grammars and XML Workshop on Attribute Grammars, XML, and RDF Institute for Media and Communications Management University of St. Gallen 20/21.

Similar presentations


Presentation on theme: "Attribute Grammars and XML Workshop on Attribute Grammars, XML, and RDF Institute for Media and Communications Management University of St. Gallen 20/21."— Presentation transcript:

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

2 1 “What Are” and “How Relate” Attribute 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 2 Attribute Grammar Example: Cartesian Move Sequences Cartesian 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 3 Grammar with Attributes on Nonterminals Grammar: path   path  step path step  n step  e step  s step  w Attributes: path.  Exx-coordinate of end position path.  Eyy-coordinate of end position step.  Dxincremental change of x-coordinate step.  Dyincremental change of y-coordinate We will only consider synthesized attributes, often prefixed by a “  ”, not inherited attributes

5 4 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 path 1.  Ex := step.  Dx + path 2.  Ex  path 1.  Ey := step.  Dy + path 2.  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 5 Decorated Parse Tree for Sequence e,e,n path step path step path step  e n e Ex = 0 Ey = 0 Ex = 0 Ey = 1 Ex = 1 Ey = 1 Ex = 2 Ey = 1 Dx = 0 Dy = 1 Dx = 1 Dy = 0

7 6 “e,e,n”-Parse Tree as XML Element e e n path step path step path step  e n e Ex = 0 Ey = 0 Ex = 0 Ey = 1 Ex = 1 Ey = 1 Ex = 2 Ey = 1 Dx = 0 Dy = 1 Dx = 1 Dy = 0 Attributed XML element tree = Decorated parse tree Attribute grammar parse results and intermediate states can thus be represented as XML elements

8 7 DTD Approximation for Attribute Grammar (AG) ‘Canonical empty elements’ instead of terminals CDATA instead of integers Semantic Rules of full AGs can be added (via XML stylesheets, Java, Prolog,...)

9 8 “e,e,n”-XML Element According to DTD e e n Terminal e becomes empty element Terminal n becomes empty element

10 9 path[0,0]([]). path[Nx,Ny]([Head|Tail]) :- step[Dx,Dy](Head), path[Ex,Ey](Tail), Nx.= +(Dx,Ex), Ny.= +(Dy,Ey). step[0,1](n). step[1,0](e). step[0,-1](s). step[-1,0](w). Prolog-like Form of AG with Semantic Rules Attribute values represented as “[...]”-parameters. Call path[X,Y]([e,e,n]) computes X = 2, Y = 1, e.g. using Relfun interpreterRelfun interpreter path.  Ex := 0  path.  Ey := 0 path 1.  Ex := step.  Dx + path 2.  Ex  path 1.  Ey := step.  Dy + path 2.  Ey path   path  step path 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

11 10 Parameter-XML Form of AG via RFML-like Generic Markup path 0 path[0,0]([]). path nx ny head tail path[Nx,Ny] ([Head|Tail]) :- step dx dy head path ex ey tail nx + dx ex ny + dy ey step[Dx,Dy](Head), path[Ex,Ey](Tail), Nx.= +(Dx,Ex), Ny.= +(Dy,Ey). step 0 1 n step 1 0 e step 0 s step 0 w step[0,1](n). step[1,0](e). step[0,-1](s). step[-1,0](w). Generic: User-defined nonterminals (e.g. path ) don’t appear as tags, only between tags

12 11 Attribute-XML Form of AG via RFML/MathML-like Non-Generic Markup <path ex="0" ey="0"/> path [Ex=0, Ey=0] ([]). <step dx="?" dy="?"/> head Step [Dx=?, Dy=?] (Head), <path ex="?" ey="?"/> tail Path [Ex=?, Ey=?] (Tail), nx dx ex Nx.= +(Dx,Ex), ny dy ey Ny.= +(Dy,Ey). <path nx="?" ny="?"/> head tail path [Nx=?, Ny=?] ([Head|Tail]) :- Output attributes made explicit via “?”-values

13 12 Conclusions Attribute Grammars and XML use the same parse and element trees There are various possible XML markups for AG’s 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


Download ppt "Attribute Grammars and XML Workshop on Attribute Grammars, XML, and RDF Institute for Media and Communications Management University of St. Gallen 20/21."

Similar presentations


Ads by Google