Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Embedding Attribute Grammars

61f8010a7249d7ec93e197e96999fe6c?s=47 Tony Sloane
November 08, 2016

Embedding Attribute Grammars

Slides for talk given at Lund University, Sweden.

61f8010a7249d7ec93e197e96999fe6c?s=128

Tony Sloane

November 08, 2016
Tweet

Transcript

  1. EMBEDDING ATTRIBUTE GRAMMARS Anthony Sloane Programming Languages and Verification Group

    Macquarie University, Sydney, Australia
  2. ELI

  3. ELI

  4. KIAMA

  5. Anthony Sloane, Matthew Roberts, Dominic Verity Scott Buckley KIAMA High-level

    language processing in a familiar programming setting Enables experimentation with combinations of processing mechanisms A shallow embedding of Domain-Specific Languages in Scala strategic term rewriting dynamically-scheduled attribute grammars abstract state machines pretty-printing combinators A. M. Sloane. Lightweight language processing in Kiama. In Generative and Transformational Techniques in Software Engineering III, volume 6491 of Lecture Notes in Computer Science, Springer, 2011. https://bitbucket.org/inkytonik/kiama
  6. Photo: Rémi Bigonneau (https://www.flickr.com/photos/35434071@N02/20040081905/) Franck Cassez, Anthony Sloane, Matthew Roberts

    Pablo González de Aledo, Matthew Pigram, Pongsak Suvanpong SKINK
  7. scalallvm lib control flow graph error trace trace effect (assert

    (and (= %0@1 %r@1 ) %cmp@1 (= %cmp@1 (> %0@1 0)))) (check-sat) C compiler no more traces program correct sat (get-value (r)) ((r 42)) unsat unsat, trace infeasible remove trace from graph SMT solver SMT lib sat, trace feasible program incorrect automata lib
  8. CONTEXT-FREE GRAMMAR AND TREE A B B C D E?

    F* E F F
  9. ALGEBRAIC DATA TYPES AND VALUE A B B C D

    E? F* E F F
  10. ATTRIBUTE FUNCTION B a

  11. EQUATION SELECTION PATTERN MATCHING CASES

  12. RULE-BASED EQUATIONS B a C a B a D a

    * 2
  13. BINDINGS AND EXPRESSIONS IN CASES B a C a B

    a D a * 2
  14. CACHING AND CYCLE CHECK Wrap equations node identity is crucial

  15. COMPLETENESS

  16. CONTEXT-FREE GRAMMAR TREE ATTRIBUTE EQUATION SELECTION EQUATION NOTATION CACHING CYCLE

    CHECK COMPLETENESS CHECK SUMMARY (1) ALGEBRAIC DATA TYPE ADT VALUE FUNCTION PATTERN-MATCHING CASES BINDING AND EXPRESSIONS IN ATTR WRAPPER DYNAMIC IN ATTR WRAPPER PATTERN EXHAUSTIVENESS CHECK
  17. SYMBOL-BASED EQUATIONS B a ? a

  18. TREE RELATIONS: CHILD-PARENT A B B C D E? F*

    E F F parent child A. M. Sloane, M. Roberts, and L. G. C. Hamey. Respect your parents: How attribution and rewriting can get along. In Proceedings of the International Conference on Software Language Engineering, volume 8706 of Lecture Notes in Computer Science, 2014.
  19. TREE RELATIONS: FIRST CHILD, NEXT A B B C D

    E? F* E F F first child next
  20. TREE RELATIONS AND SHARING A B B A B C

    D D
  21. GENERIC TREE ACCESS B a ? a

  22. TREE RELATIONS AS PATTERNS Bind c to the first child

    of the matched node, or fail if there are no children Bind pn to the next node at the same level as the parent of the matched node, or fail if there is no parent or next node after parent Succeed if and only if there is a parent and it is an A
  23. INHERITED ATTRIBUTES A C c 10 B C c 20

  24. MATCHING ON PARENT A C c 10 B C c

    20
  25. MIXED MODE ATTRIBUTES A C c ? C c G

    c 10
  26. CONTEXT-FREE GRAMMAR TREE ATTRIBUTE EQUATION SELECTION EQUATION NOTATION CACHING CYCLE

    CHECK COMPLETENESS CHECK INHERITED EQUATIONS CONTEXT-DEPENDENT EQUATIONS SUMMARY (2) ALGEBRAIC DATA TYPE ADT VALUE FUNCTION PATTERN-MATCHING CASES BINDING AND EXPRESSIONS IN ATTR WRAPPER DYNAMIC IN ATTR WRAPPER PATTERN EXHAUSTIVENESS CHECK MATCHING ON PARENT TREE RELATIONS AS PATTERNS
  27. HIGHER-ORDER ATTRIBUTES A B d D x y

  28. HIGHER-ORDER ATTRIBUTES A B d D x y

  29. REFERENCE ATTRIBUTES

  30. FORWARDING * 1 + 2 3 + * 3 1

    2 ast
  31. CIRCULAR ATTRIBUTES E. Magnusson, G. Hedin. Circular reference attributed grammars

    — their evaluation and applications. Science of Computer Programming 68 (2007) 21–37.
  32. ATTRIBUTION PATTERNS

  33. DOWN DECORATOR

  34. MODULARITY L1 L2 L3 L4 Syntax analyser Oberon-0 printer Name

    analyser Type analyser Desugarer Lifter Code generator C printer A extends B A B A B mixin: A ... with B A. M. Sloane and M. Roberts. Oberon-0 in Kiama. Science of Computer Programming, Dec. 2015
  35. CONTEXT-FREE GRAMMAR TREE ATTRIBUTE EQUATION SELECTION EQUATION NOTATION CACHING CYCLE

    CHECK COMPLETENESS CHECK INHERITED EQUATIONS CONTEXT-DEPENDENT EQUATIONS HIGHER-ORDER/REFERENCE ATTRS FORWARDING CIRCULAR ATTRIBUTES ATTRIBUTION PATTERNS MODULARITY SUMMARY (3) ALGEBRAIC DATA TYPE ADT VALUE FUNCTION PATTERN-MATCHING CASES BINDING AND EXPRESSIONS IN ATTR WRAPPER DYNAMIC IN ATTR WRAPPER PATTERN EXHAUSTIVENESS CHECK MATCHING ON PARENT TREE RELATIONS AS PATTERNS FUNCTIONS AND TREE RELATIONS IMPLICIT CONVERSION AS IN JASTADD DECORATORS MIXINS, INHERITANCE
  36. SOFTWARE LANGUAGE ENGINEERING AT MACQUARIE UNIVERSITY https://bitbucket.org/inkytonik/kiama Anthony.Sloane@mq.edu.au @inkytonik on

    Twitter High-level language processing in a familiar programming setting strategic term rewriting dynamically-scheduled attribute grammars abstract state machines pretty-printing combinators https://bitbucket.org/inkytonik/sbt-rats Scala parser generator plugin PEG-based packrat parsing tree construction pretty-printing