Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse

1,132 views
1,014 views

Published on

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
1,132
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse

  1. 1. The Spoofax Language Workbench Eelco Visser Lennart Kats Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  2. 2. Spoofax hands-on material: www.strategoxt.org/Spoofax/Devnology
  3. 3. Domain-Specific Languages (DSLs) Domain: • Mobile phone • Web • Financial • Printer design • ... Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology Can offer: • Specialized syntax • Specialized analysis • Specialized optimizations • Platform independence
  4. 4. Example DSL: Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  5. 5. Syntax definition ★ concrete + 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 Problem: building DSLs parser generators meta- programming languages meta- programming libraries template engines Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  6. 6. Problem: building DSLs (ct’d) Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  7. 7. Editor Services syntactic editor services • syntax highlighting • syntax checking • outline view • bracket matching, insertion • automatic indentation • syntax completion • ... semantic editor services • error marking • reference resolving • hover help • mark occurrences • content completion • refactoring • ... Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  8. 8. Syntax definition Static semantics Model-to-model transformation Code generation Syntactic Editor Services Semantic Editor Services }Spoofax how can we make these things cheaply? Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  9. 9. • <spoofax screenshot: lang def and lang use in Eclipse workspace> Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  10. 10. #1 Syntax definition • Basic expression language 1+2+3 Expr “+” Expr -> Expr {cons(“Plus”)} Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  11. 11. #1 Syntax definition • Basic expression language 1+2+3 2 1 3 + + 21 3 + + is that or ? what does the abstract syntax view say?
  12. 12. #1 Syntax definition • Basic expression language 1+2*3 2 1 3 + * 21 3 *is that or ? what does the abstract syntax view say? +
  13. 13. The Spoofax Solution: Declarative Syntax with SDF Declarative, explicit disambigation rules Clean abstract syntax Composable syntax definitions
  14. 14. #2 Transformation Tip. Some other operators: subtS, mulS, divS, gt, lt, eq Transform 1+2 to <addition of> 1 and 2: calc: Add(Int(i), Int(j)) -> Int(<addS> (i, j))
  15. 15. #2 Transformation Transform 1+2 to <addition of> 1 and 2: calc: Add(Int(i), Int(j)) -> Int(<addS> (i, j)) calculate = bottomup(try(calc)) Tip. Some other operators: subtS, mulS, divS, gt, lt, eq
  16. 16. #3 Equations New syntax New semantics x = 2 y = 3 result = 90 * x + 30 * y
  17. 17. #3 Equations x = 2 y = 3 result = 90 * x + 30 * y Assign(“x”, INT(2)) calc: Assign(x, e) -> e where rules(GetValue: x -> e) calc: Var(x) -> <GetValue> x New syntax New semantics
  18. 18. x = 2 y = 3 result = 90 * x + 30 * z #4 Error markers (Var(“z”), “Variable z is not defined”) transform
  19. 19. #4 Error markers analyze = topdown(try(record-var)) record-var: Assign(x, e) -> Assign(x, e) with rules( GetVar :+ x -> e ) constraint-errors = collect-all(constraint-error, conc) constraint-error: Var(x) -> (x, $[Variable [x] is not defined]) where not(<GetVar> x)
  20. 20. #4 Error markers #5 Refinement analyze = topdown(try(record-var)) record-var: Assign(x, e) -> Assign(x, e) with rules( GetVar :+ x -> e ) constraint-errors = collect-all(constraint-error, conc) constraint-error: Var(x) -> (x, $[Variable [x] is not defined]) where not(<GetVar> x)
  21. 21. #4 Error markers #5 Refinement editor-resolve: (Var(x), position, ast, path, project-path) -> target where target := <GetVar> x editor-complete: (Var(x), position, ast, path, project-path) -> proposals where proposals := <all-keys-GetVar> x
  22. 22. Refinement & Free play
  23. 23. Syntax definition Static semantics Model-to-model transformation Code generation Syntactic Editor Services Semantic Editor Services }Spoofax www.spoofax.org

×