Helvetia

620 views

Published on

Helvetia. Lukas Renggli, ESUG 2010, Barcelona, Spain

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
620
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Helvetia

  1. 1. Mastering Embedded Languages Lukas Renggli Software Composition Group University of Bern, Switzerland !" #"$%&
  2. 2. Smalltalk is a highly dynamic language PhotobySiasvanSchalkwyk,sxc.hu
  3. 3. Smalltalk syntax is locked down PhotobySimeonEichmann,sxc.hu
  4. 4. Host-language compiler can be patched PhotobyCamillaReenberg,sxc.hu
  5. 5. Patching wrecks your development tools PhotobyArieKok,sxc.hu
  6. 6. Mastering Embedded Languages !" #"$%&
  7. 7. Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006
  8. 8. Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006
  9. 9. Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006
  10. 10. § § § Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006
  11. 11. Requirements
  12. 12. Adopt, Extend, Overload
  13. 13. Adopt, Extend, Overload change semantics
  14. 14. Adopt, Extend, Overload change semantics introduce new syntax
  15. 15. Adopt, Extend, Overload change semantics introduce new syntax change syntax & semantics
  16. 16. Multiple Context Dependent Languages
  17. 17. Homogeneous Data and Code Abstraction
  18. 18. Homogeneous Tool Support § § §
  19. 19. Context Specific Languages with Homogeneous Tool Integration !" #"$%&
  20. 20. Package Name x = 1 y = 1 (2, 1) (2, 2)(1, 2) x = 2 y = 2
  21. 21. aBuilder row grow. aBuilder row fill. aBuilder column grow. aBuilder column fill. aBuilder x: 1 y: 1 add: (LabelShape new text: [ :each | each name ]; borderColor: #black; borderWidth: 1; yourself). aBuilder x: 1 y: 2 w: 2 h: 1 add: (RectangleShape new borderColor: #black; borderWidth: 1; width: 200; height: 100; yourself) Package Name x = 1 y = 1 (2, 1) (2, 2)(1, 2) x = 2 y = 2
  22. 22. row = grow. row = fill. column = grow. column = fill. (1 , 1) = label text: [ :each | each name ]; borderColor: #black; borderWidth: 1. (1 , 2) - (2 , 1) = rectangle borderColor: #black; borderWidth: 1; width: 200; height: 100. Package Name x = 1 y = 1 (2, 1) (2, 2)(1, 2) x = 2 y = 2
  23. 23. A pidgin is a simplified form of the host language. It introduces new vocabulary and semantic meaning.
  24. 24. shape { cols: #grow, #fill; rows: #grow, #fill; } label { position: 1 , 1; text: [ :each | each name ]; borderColor: #black; borderWidth: 1; } rectangle { position: 1 , 2; colspan: 2; borderColor: #black; borderWidth: 1; width: 200; height: 100; } Package Name x = 1 y = 1 (2, 1) (2, 2)(1, 2) x = 2 y = 2
  25. 25. A creole a is a new language formed from the contact of multiple languages.
  26. 26. The He vetia Model!" #"$%&
  27. 27. Traditional Smalltalk Compiler Smalltalk Parser Semantic Analysis Bytecode Generation Executable Code Source Code
  28. 28. Traditional Smalltalk Compiler Smalltalk Parser Semantic Analysis Bytecode Generation Executable Code Source Code <parse> <transform> <attribute> <bytecode> Rules
  29. 29. Traditional Smalltalk Compiler Smalltalk Parser Semantic Analysis Bytecode Generation Executable Code Source Code <parse> <transform> <attribute> <bytecode> Rules <complete> <highlight> ......
  30. 30. Traditional Smalltalk Compiler Smalltalk Parser Semantic Analysis Bytecode Generation Executable Code Source Code <parse> <transform> <attribute> <bytecode> Rules Pidgin path Creole path <complete> <highlight> ......
  31. 31. Homogenous Embedding
  32. 32. Homogeneous Tools
  33. 33. IV + VII = XI ,>++++++[<-­‐-­‐-­‐-­‐-­‐-­‐-­‐-­‐>-­‐],[<+>-­‐]<.
  34. 34. Host Language
  35. 35. Host Language Renggli et al.ECOOP 2010
  36. 36. Language Boxes Modular Language Changes
  37. 37. Editor Compiler Debugger Syntax Language 1 Language 2
  38. 38. Editor Compiler Debugger Syntax Language 1 Language 2
  39. 39. Editor Compiler Debugger Syntax Language 1 Language 2
  40. 40. Editor Compiler Debugger Syntax Language 1 Language 2
  41. 41. Marco Zanoli, cc-by-sa, 2.5, www.wikipedia.de, 2006
  42. 42. /w+@w+.w+/
  43. 43. Language Change Language Concern Language Scope Language Box * * * *
  44. 44. Language Change High-level Description
  45. 45. Language Change Add Regex as an additional choice to Primary .
  46. 46. Language Change /Regex: /^/
  47. 47. Language Change StringPrimary: Number
  48. 48. Regex Language Change StringPrimary: Number
  49. 49. Language Concern Production Action
  50. 50. Language Concern Compiler aToken asRegex lift
  51. 51. Highlighting aToken -> Color orange Language Concern
  52. 52. Other Concerns Language Concern Context Menus Navigation Search Code Expansion Code Completion Error Correction Custom Inspector
  53. 53. Language Scope Active?
  54. 54. ‣ System ‣ Packages ‣ Classes ‣ Methods Language Scope
  55. 55. Multiple Language Extensions
  56. 56. Host Language Grammar
  57. 57. Host Language Grammar Lan B Language Box 1 Language Box 2
  58. 58. Language Box 3 Language Box 1 Language Box 2 Lan B Host Language Grammar
  59. 59. Language Box 3 ge 2 Language Box 4 Host Language Grammar
  60. 60. Host Language Grammar Custom
  61. 61. ‣ Fine-grained language changes ‣ Fine-grained language scoping ‣ Composable and reusable model ‣ Tool integration (Editor, Debugger)
  62. 62. Language Boxes Host Language
  63. 63. Language Boxes Host Language Renggli et al.SLE 2009
  64. 64. Language Boxes Host Language Dynamic Grammars
  65. 65. [Adapted from The New Oxford American Dictionary on Grammar] grammar a set of rules governing what strings are valid or allowable in a [formal] language.
  66. 66. dynamic grammar a high-level grammar that executes at runtime behaviors that other grammars perform during compilation, see dynamic languages. [Adapted from Wikipedia on Dynamic Programming Languages]
  67. 67. Dynamic Grammars Dynamic Languages ‣ Late-bound behavior ‣ First-class representation ‣ On-the-fly transformation ‣ Introspection and reflection
  68. 68. Why would we want that?
  69. 69. Language Change Language Concern Language Scope Language Box * * * *
  70. 70. Language Change = Host Language Grammarδ
  71. 71. Language Change = Grammar Transformation
  72. 72. scanIdentifier self step. ((currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ]) ifTrue: [ [ self recordMatch: #IDENTIFIER. self step. (currentCharacter between: $0 and: $9) or: [ (currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ] ] ] whileTrue. ^ self reportLastMatch ]
  73. 73. scanIdentifier self step. ((currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ]) ifTrue: [ [ self recordMatch: #IDENTIFIER. self step. (currentCharacter between: $0 and: $9) or: [ (currentCharacter between: $A and: $Z) or: [ currentCharacter between: $a and: $z ] ] ] whileTrue. ^ self reportLastMatch ] ✖
  74. 74. #( #[1 0 9 0 25 0 13 0 34 0 17 0 40 0 21 0 41] #[1 0 9 0 25 0 13 0 34 0 93 0 76 0 157 0 112] #[1 2 38 0 21 2 38 0 25 2 38 0 26 0 13 0 34] #[0 1 154 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[0 1 210 0 76 0 81] #[0 1 214 0 76 0 81] #[1 0 173 0 76 0 177 0 81] #[0 1 134 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[1 1 46 0 21 1 46 0 25 1 46 0 26 1 69] #[1 1 54 0 21 1 54 0 25 1 54 0 26 1 54 0 34] #[0 2 102 0 21 0 25 0 26 0 34 0 40 0 41 0 76] #[0 2 50 0 21 0 25 0 26 0 76 0 79] #[1 1 13 0 76 2 85 0 124 1 21 0 125] #[1 2 89 0 17 2 30 0 21 2 30 0 82] #[1 2 93 0 21 2 97 0 82] )
  75. 75. #( #[1 0 9 0 25 0 13 0 34 0 17 0 40 0 21 0 41] #[1 0 9 0 25 0 13 0 34 0 93 0 76 0 157 0 112] #[1 2 38 0 21 2 38 0 25 2 38 0 26 0 13 0 34] #[0 1 154 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[0 1 210 0 76 0 81] #[0 1 214 0 76 0 81] #[1 0 173 0 76 0 177 0 81] #[0 1 134 0 16 0 21 0 25 0 26 0 34 0 40 0 41] #[1 1 46 0 21 1 46 0 25 1 46 0 26 1 69] #[1 1 54 0 21 1 54 0 25 1 54 0 26 1 54 0 34] #[0 2 102 0 21 0 25 0 26 0 34 0 40 0 41 0 76] #[0 2 50 0 21 0 25 0 26 0 76 0 79] #[1 1 13 0 76 2 85 0 124 1 21 0 125] #[1 2 89 0 17 2 30 0 21 2 30 0 82] #[1 2 93 0 21 2 97 0 82] ) ✖
  76. 76. a..z a..z 0..9 ID ::= letter { letter | digit } ;
  77. 77. letter letter digit sequence choice star id := #letter , (#letter / #digit) star
  78. 78. letter letter digit sequence choice star id := #letter asParser , (#letter asParser / #digit asParser) star
  79. 79. letter letter digit sequence choice star ID ::= letter { letter | digit } ; !" #"$%&
  80. 80. Scannerless Parser
  81. 81. Parsing Expression Grammar
  82. 82. Packrat Parser
  83. 83. Parser Combinator
  84. 84. Grammar Transformation
  85. 85. Graph Rewriting
  86. 86. letter letter digit sequence choice star #letter → #letter / $_
  87. 87. letter digit sequence choice starchoice _ letter choice _ #letter → #letter / $_
  88. 88. Optimizations
  89. 89. letter digit sequence choice starchoice _ letter choice _ (`a / `b) / `c → `a / `b / `c
  90. 90. letter digit sequence choice starchoice _ letter _ (`a / `b) / `c → `a / `b / `c
  91. 91. letter digit sequence choice starchoice _ letter _ remove duplicates
  92. 92. letter digit sequence choice starchoice _ remove duplicates
  93. 93. letter digit sequence choice starchoice _ remove duplicates in general a graph
  94. 94. Conflicts?
  95. 95. SELECT * FROM users
  96. 96. SELECT * FROM users | r | r := ^ User fromRow: r .
  97. 97. expr sql|
  98. 98. SELECT * FROM users<SQL: >
  99. 99. expr sql/ ordered
  100. 100. No Conflicts
  101. 101. No Ambiguities
  102. 102. expr sql/ surprise
  103. 103. / exprsql surprise
  104. 104. expr sql| !expr sql / !sql expr
  105. 105. expr sql$ !expr sql / !sql expr / ui
  106. 106. Language Boxes Host Language Dynamic Grammars
  107. 107. Language Boxes Host Language Dynamic Grammars Renggli et al.DYLA 2010
  108. 108. Language Boxes Host Language Dynamic Grammars Embedded Languages
  109. 109. apply hasChanged hasConflict Change object * changes Process 0..1 currentTransaction do: aBlock retry: aBlock checkpoint abort: anObject escapeContext Transaction previousCopy workingCopy ObjectChange applyBlock conflictTestBlock CustomChange * Transactional Memory
  110. 110. Domain-Specific Program Checking
  111. 111. Meta-Programming Facilities ``(`,(aString) asRegex) The LISP stuff, for a cool language
  112. 112. Language Boxes Host Language Dynamic Grammars Language Extensions Renggli et al. CLSS 2009 Renggli et al. IWST 2009 Nierstrasz et al. LNCS 2009 Renggli et al. TOOLS 2010
  113. 113. scg.unibe.ch/research/helvetia

×