Model-Driven Software Development - Language Workbenches & Syntax Definition

3,358 views

Published on

Language Workbenches & Syntax Definition

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
3,358
On SlideShare
0
From Embeds
0
Number of Embeds
885
Actions
Shares
0
Downloads
72
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Model-Driven Software Development - Language Workbenches & Syntax Definition

  1. 1. Language Workbenches & Syntax Definition Lecture 6 Course IN4308 Eelco Visser Master Computer Science http://eelcovisser.org Delft University of Technology
  2. 2. Part II Modeling Languages
  3. 3. Language Workbenches Lecture 6
  4. 4. Language Modeling Lectures 6-7
  5. 5. Transformation, Generation, Analysis Lectures 8-10
  6. 6. Customization Model generate customize Code Lecture 10
  7. 7. Advanced Topics Economics ★ costs and benefits of developing (with) DSLs Evolution ★ maintenance of models and languages Portability ★ supporting multiple platforms Internal DSLs ★ library as a language Language composition ★ combining multiple DSLs Lectures 12-14
  8. 8. Language Workbenches
  9. 9. parse check Model AST Errors desugar Traditional Compiler core Architecture generate Code
  10. 10. Compiler Ingredients Syntax definition ★ concrete syntax ★ abstract syntax Static semantics ★ error checking ★ name resolution ★ type analysis Model-to-model transformation ★ express constructs in core language Code generation ★ translate core language models to implementation
  11. 11. Integrated Development Environments extended requirements for language definition
  12. 12. Editor Services for Modern IDEs Syntactic Editor Services ★ syntax checking ★ bracket matching ★ syntax highlighting ★ code folding ★ outline view Semantic Editor Services ★ error checking ★ reference resolving ★ hover help ★ code completion ★ refactoring
  13. 13. Demonstration: NWL in Spoofax
  14. 14. parse Editor AST feedback core Integrated Development Environment Code
  15. 15. Architectural Requirements for IDEs Editor services are based on AST ★ services analyze structure, not text of source Error recovery ★ continue services in presence of syntactic errors Incremental processing ★ effort of applying analysis, transformation, generation should be proportional to change in source Separate compilation (analysis, transformation) ★ keep track of dependencies
  16. 16. Holy Grail of Software Language Definition Automatically derive efficient, scalable, incremental compiler + usable IDE from high-level, declarative language definition
  17. 17. Language Definition Tools Parser generators ★ automatically generate parsers from grammars ★ LEX/YAC, Bison, ANTLR, ... Meta-programming tools ★ DSLs for programming with programs as data ★ TXL, ASF+SDF, Stratego, JastAdd, RascalMPL, ... IDE generators/frameworks ★ tools for construction of IDE plugins ★ IMP, TMF ★ Synthesizer Generator, Centaur, Lrc
  18. 18. Language Workbenches Integrated development environment for ★ language definition ★ application of language Textual languages ★ ASF+SDF MetaEnvironment, XText, MontiCore, EMFText, Spoofax Structure editors ★ MPS Visual languages ★ MetaEdit+, DSL Tools, ...
  19. 19. Spoofax/IMP
  20. 20. The Spoofax/IMP Language Workbench Syntax definition: SDF ★ declarative, modular syntax definition Transformation, analysis, generation: Stratego ★ rewrite rules, strategies, dynamic rules Editor services ★ domain-specific languages for configuration Based on IMP framework by IBM Research
  21. 21. Syntax Definition
  22. 22. Syntax Definition Pretty-Print Parse Table Signature Table Parse Transform Pretty-Print @Entity entity User { class User { name :: String String _user; pw :: Secret public User } getUser() { def output(u : syntax definition is basis of language definition return _user; User) { }
  23. 23. Lexical & Context-Free Syntax
  24. 24. Structure of Sentences composed from
  25. 25. Context-Free Grammar sort regular expression symbol Definition grammar production Property* {Stat “;”}* “entity”
  26. 26. Lexical Syntax regular expression character class characters in lexical syntax not separated by layout
  27. 27. Syntax of Data Models
  28. 28. Recognizing Well-Formed Sentences
  29. 29. Lexical Syntax: Identifiers & Literals follow restriction: symbol may not reserved words be followed by character from this class: BlogEntry is one ID
  30. 30. Lexical Syntax: Strings escape complement escape escape
  31. 31. Lexical Syntax: Whitespace LAYOUT? is inserted between symbols in CF productions normalize
  32. 32. Lexical Syntax: Comment
  33. 33. Modular Syntax Definition
  34. 34. Meta-Grammar
  35. 35. Parsing & Abstract Syntax building structured representation of sentence
  36. 36. Constructor Annotations
  37. 37. Terms to Represent Abstract Syntax Entity(“Blog”, [Property(“name”,SimpleType(“String”)), Property(“author”, SimpleType(“User”))] )
  38. 38. Parsing
  39. 39. Parsing
  40. 40. Parsing
  41. 41. Parsing
  42. 42. Parsing
  43. 43. Parsing in Spoofax
  44. 44. Signatures defining the structure of abstract syntax terms
  45. 45. Syntax Definition Pretty-Print Parse Table Signature Table Parse Transform Pretty-Print @Entity entity User { class User { name :: String String _user; pw :: Secret public User } getUser() { def output(u : syntax definition is basis of language definition return _user; User) { }
  46. 46. Signatures declare arguments and types of constructors signature is generated from grammar
  47. 47. Disambiguation
  48. 48. Arithmetic Expressions note: this style produces good abstract syntax Plus(Times(Var(“x”),Int(2)),Var(“z”))
  49. 49. Associativity
  50. 50. Priority
  51. 51. Parsing after Disambiguation
  52. 52. Brackets
  53. 53. Syntax Definition Pretty-Print Parse Table Signature Table Parse Transform Pretty-Print @Entity entity User { class User { name :: String String _user; pw :: Secret public User } getUser() { def output(u : syntax definition is basis of language definition return _user; User) { }
  54. 54. Schedule Lab this week ★ Design 1: deadline is April 1 ★ Design 2: what DSL will you design? Cases ★ Case 2: web abstractions ★ Deadline Case 2: April 8 Next ★ Lecture 7: editor services & basic code generation

×