Download presentation

Presentation is loading. Please wait.

Published byColt Leadley Modified over 2 years ago

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 our aims: a compositional semantics for attribute grammars expressed as executable functions in Haskell to study both existing and novel combining forms and many more...

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 type safety for attribute values project embed = id

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]) attribution of parentattribution of each child type Rule = Fam Fam

7
Example rule tree 0 ::= tree 1 tree 2 tree 0.locmin = min tree 1.locmin tree 2.locmin tree 2.gmin = tree 0.gmin (tree 0, [tree 1, tree 2 ] ) (embed locmin (min(project locmin tree 1 ) (project locmin tree 1 ) ), [ , embed gmin (project gmin tree 0 )]) synthesised inherited

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 Attributions finite map from names to values Families (parent attribution, [child attribution]) Rules input family (inherited, [synthesised]) to output family (synthesised, [inherited])

10
Semantic aspects type Aspect = ProdName Rule counts :: Int Aspect counts x = chain count [node] define atroot[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 count number of occurrences of x to left of each leaf details in paper

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

12
Semantics of trees inheritedsynthesised type SemTree = Attrs Attrs

13
Semantics of productions type SemProd = [SemTree] SemTree semantics of childrensemantics of parent rules are similar, but we have not connected defining occurrences to uses

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

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 checks abstract interpretation Record calculus gives greater safety but can be too restrictive Further structuring first-class productions

Similar presentations

OK

Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees Recursive definition 1.An empty tree is a binary tree 2.A node.

Comp 122, Spring 2004 Binary Search Trees. btrees - 2 Comp 122, Spring 2004 Binary Trees Recursive definition 1.An empty tree is a binary tree 2.A node.

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google

Ppt on computer graphics algorithms Ppt on sugar industry Ppt on electricity from waste water Ppt on surface water pollution Ppt on water conservation in industries Ppt on boilers operations specialist Ppt on product specification meaning Ppt on autonomous car Ppt on alternative sources of energy Ppt on series and parallel circuits lessons