1 / 18

First-class Attribute Grammars

First-class Attribute Grammars. Oege de Moor joint work with Kevin Backhouse and Doaitse Swierstra. Structuring AGs. flow patterns chains. semantic aspects type checking. remote attribute access copying inherited attributes. and many more. our aims:

genica
Download Presentation

First-class Attribute Grammars

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  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

More Related