SlideServe
Menu
Préférences
© SlideServe · v2026

Structuring Attribute Grammars: Executable Semantics and Type Safety in Haskell

genica avatar
18 diapositives · 349 Views · Sep 22, 2014

This work explores a comprehensive framework for attribute grammars (AGs) focusing on compositional semantics expressed as executable functions in Haskell. It addresses semantic aspects such as type checking, remote attribute access, and copying inherited attributes. The study involves both existing and novel retrieval forms of attributes, along with rules for defining and structuring attributes with type safety. We provide examples of rule trees and chains that demonstrate the application of these concepts in the semantics of AGs, ultimately aiming to enhance safety and flexibility in grammar design.

Structuring Attribute Grammars: Executable Semantics and Type Safety in Haskell - slide 1
01 / 18Structuring Attribute Grammars: Executable Semantics and Type Safety in Haskell
1 / 17

Télécharger la présentation

Structuring Attribute Grammars: Executable Semantics and Type Safety in Haskell
Une image / un lien ci-dessous est fourni (tel quel) pour télécharger la présentation

Politique de téléchargement : le contenu du site vous est fourni TEL QUEL pour votre information et votre usage personnel ; il ne peut être vendu, concédé sous licence ni partagé sur d’autres sites sans l’accord de son auteur.Le contenu vous est fourni TEL QUEL, pour votre information et votre usage personnel uniquement. Téléchargez la présentation en cliquant sur ce lien. Lors du téléchargement, si vous ne parvenez pas à télécharger une présentation, l’éditeur a peut-être supprimé le fichier de son serveur.Pendant le téléchargement, si vous ne parvenez pas à obtenir une présentation, le fichier a peut-être été supprimé par l’éditeur.

F I N

Plus de contenu associé

Transcription de la présentation
  1. First-class Attribute Grammars Oege de Moor joint work with Kevin Backhouse and Doaitse Swierstra

  2. Structuring AGs flow patterns chains semantic aspects type checking remote attribute access copying inherited attributes and many more... • our aims: • a compositional semantics for attribute grammars • expressed as executable functions in Haskell • to study both existing and novel combining forms

  3. Attributions type Attrs = Name  Value Value : disjoint sum of all attribute types joining attributions () :: Attrs  Attrs  Attrs a record type would be safer, but also more cumbersome

  4. Attributes type At  = (  Attrs, Attrs  ) embed (e,p) = e project (e,p) = p project  embed = id type safety for attribute values

  5. Rules An attribute definition rule at production P maps the input attributes of P to some of P’s output attributes (inherited of parent, synthesised of children) (synthesised of parent, inherited of children) allow multiple output attributes so rules can be joined

  6. Rules An attribute definition rule is a function (inherited of parent, synthesised of children) (synthesised of parent, inherited of children) what is the type of these things? type Fam = (Attrs, [Attrs]) type Rule = Fam  Fam attribution of parent attribution of each child

  7. Example rule tree0 ::= tree1 tree2 tree0.locmin = min tree1.locmin tree2.locmintree2.gmin = tree0.gmin synthesised inherited  (tree0, [tree1 , tree2 ] )  (embed locmin (min (project locmin tree1) (project locmin tree1) ), [, embed gmin (project gmin tree0)])

  8. Example rule chainRule :: At   Rule chainRule (e,p) (inhp, syncs) = (last outs, init outs) where outs = map (e  p) ins ins = inhp : syncs

  9. Recap • Attributionsfinite map from names to values • Families(parent attribution, [child attribution]) • Rulesinput family (inherited, [synthesised]) to output family (synthesised, [inherited])

  10. Semantic aspects type Aspect = ProdName  Rule count number of occurrences of x to left of each leaf counts :: Int  Aspect counts x = chain count [node] define at root[tree] : 0 leaf[tree] : if val.value == x then tree.count + 1 else tree.count root: start  tree node: tree  tree tree leaf: tree  val details in paper

  11. Aims semantics of building blocks: Attributions Families Rules Aspects How assemble them into semantics of translators?

  12. Semantics of trees type SemTree = Attrs  Attrs inherited synthesised

  13. Semantics of productions type SemProd = [SemTree]  SemTree semantics of children semantics of parent rules are similar, but we have notconnected defining occurrences to uses

  14. From rules to productions inherited attributes of children synthesised attributes of parent knit :: Rule  SemProd knit r fs inhp = synp where (synp, inhcs) = r (inhp,syncs) syncs = applyList fs inhcs rule inherited attributes of parent synthesised attributes of children semantics of children applyList [] xs = [] applyList (f:fs) (x:xs) = f x : applyList fs xs

  15. Semantics of AGs type AG = ProdName  SemProd knitAspect :: Aspect  AG knitAspect as = knit  as

  16. Translation data Tree = Fork ProdName [Tree] | Val Attrs attribution from scanner/parser trans :: AG  Tree  SemTree trans ag (Fork l ts) inh = ag l (map (trans ag) ts) inh trans ag (Val a) inh = a

  17. Summary Attrs = Name  Value Fam = (Attrs,[Attrs]) Rule = Fam  Fam Aspect = ProdName  Rule SemTree = Attrs  Attrs SemProd = [SemTree]  SemTree AG = ProdName  SemProd trans :: AG  Tree  SemTree

  18. Discussion • Executable denotational semantics • Prototype lacks static checksabstract interpretation • Record calculus gives greater safetybut can be too restrictive • Further structuringfirst-class productions