SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
The Spoofax
Language Workbench
Eelco Visser
Lennart Kats
Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
Spoofax
hands-on material:
www.strategoxt.org/Spoofax/Devnology
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
Example DSL:
Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
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
Problem: building DSLs (ct’d)
Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
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
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
• <spoofax screenshot: lang def and lang use
in Eclipse workspace>
Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
#1 Syntax definition
• Basic expression language
1+2+3
Expr “+” Expr -> Expr {cons(“Plus”)}
Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
#1 Syntax definition
• Basic expression language
1+2+3
2
1
3
+
+
21
3
+
+
is that or ?
what does the abstract syntax view say?
#1 Syntax definition
• Basic expression language
1+2*3
2
1
3
+
*
21
3
*is that or ?
what does the abstract syntax view say?
+
The Spoofax Solution:
Declarative Syntax with SDF
Declarative, explicit disambigation rules
Clean abstract syntax
Composable syntax definitions
#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))
#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
#3 Equations
New syntax
New semantics
x = 2
y = 3
result = 90 * x + 30 * y
#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
x = 2
y = 3
result = 90 * x + 30 * z
#4 Error markers
(Var(“z”), “Variable z is not defined”)
transform
#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)
#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)
#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
Refinement &
Free play
Syntax definition
Static semantics
Model-to-model transformation
Code generation
Syntactic Editor Services
Semantic Editor Services
}Spoofax
www.spoofax.org

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (8)

T3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmerT3chFest 2016 - The polyglot programmer
T3chFest 2016 - The polyglot programmer
 
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
Scala-Gopher: CSP-style programming techniques with idiomatic Scala.
 
scala-gopher: async implementation of CSP for scala
scala-gopher:  async implementation of CSP  for  scalascala-gopher:  async implementation of CSP  for  scala
scala-gopher: async implementation of CSP for scala
 
Code quailty metrics demystified
Code quailty metrics demystifiedCode quailty metrics demystified
Code quailty metrics demystified
 
The best language in the world
The best language in the worldThe best language in the world
The best language in the world
 
GUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programmingGUL UC3M - Introduction to functional programming
GUL UC3M - Introduction to functional programming
 
201801 CSE240 Lecture 14
201801 CSE240 Lecture 14201801 CSE240 Lecture 14
201801 CSE240 Lecture 14
 
Csp scala wixmeetup2016
Csp scala wixmeetup2016Csp scala wixmeetup2016
Csp scala wixmeetup2016
 

Andere mochten auch (6)

anheuser-busch 2006AR_LetterToShareholders
anheuser-busch 2006AR_LetterToShareholdersanheuser-busch 2006AR_LetterToShareholders
anheuser-busch 2006AR_LetterToShareholders
 
Presentation ASB
Presentation ASBPresentation ASB
Presentation ASB
 
New creative economy pwp
New creative economy pwpNew creative economy pwp
New creative economy pwp
 
DME
DMEDME
DME
 
Irlande Johanne Mathilde
Irlande Johanne MathildeIrlande Johanne Mathilde
Irlande Johanne Mathilde
 
What's New in Search Engine Market (2009 review)
What's New in Search Engine Market (2009 review)What's New in Search Engine Market (2009 review)
What's New in Search Engine Market (2009 review)
 

Ähnlich wie Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse

Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
Vitaly Baum
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
Baidu, Inc.
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
Robert Pickering
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
Dmitry Buzdin
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 Enhancements
Robert MacLean
 
Cadence GenusTutorial------------ .pdf.pdf
Cadence GenusTutorial------------ .pdf.pdfCadence GenusTutorial------------ .pdf.pdf
Cadence GenusTutorial------------ .pdf.pdf
SamHoney6
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
google
 

Ähnlich wie Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse (20)

Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)Building DSLs On CLR and DLR (Microsoft.NET)
Building DSLs On CLR and DLR (Microsoft.NET)
 
The Art Of Readable Code
The Art Of Readable CodeThe Art Of Readable Code
The Art Of Readable Code
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
Introducing BinarySortedMultiMap - A new Flink state primitive to boost your ...
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
 
Measuring Your Code
Measuring Your CodeMeasuring Your Code
Measuring Your Code
 
Measuring Your Code 2.0
Measuring Your Code 2.0Measuring Your Code 2.0
Measuring Your Code 2.0
 
Software Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & SpoofaxSoftware Language Design & Engineering: Mobl & Spoofax
Software Language Design & Engineering: Mobl & Spoofax
 
Hands on Mahout!
Hands on Mahout!Hands on Mahout!
Hands on Mahout!
 
CoCoViLa @ devclub.eu
CoCoViLa @ devclub.euCoCoViLa @ devclub.eu
CoCoViLa @ devclub.eu
 
Core .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 EnhancementsCore .NET Framework 4.0 Enhancements
Core .NET Framework 4.0 Enhancements
 
Scam 08
Scam 08Scam 08
Scam 08
 
(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net(1) c sharp introduction_basics_dot_net
(1) c sharp introduction_basics_dot_net
 
C sharp 8.0 new features
C sharp 8.0 new featuresC sharp 8.0 new features
C sharp 8.0 new features
 
More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...More Data, More Problems: Evolving big data machine learning pipelines with S...
More Data, More Problems: Evolving big data machine learning pipelines with S...
 
Cadence GenusTutorial------------ .pdf.pdf
Cadence GenusTutorial------------ .pdf.pdfCadence GenusTutorial------------ .pdf.pdf
Cadence GenusTutorial------------ .pdf.pdf
 
Python basics
Python basicsPython basics
Python basics
 
Linq 1224887336792847 9
Linq 1224887336792847 9Linq 1224887336792847 9
Linq 1224887336792847 9
 
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali ZaidiNatural Language Processing with CNTK and Apache Spark with Ali Zaidi
Natural Language Processing with CNTK and Apache Spark with Ali Zaidi
 
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
Michael Hall [InfluxData] | Become an InfluxDB Pro in 20 Minutes | InfluxDays...
 

Mehr von Devnology

Slides Felienne Hermans Symposium EWI
Slides Felienne Hermans Symposium EWISlides Felienne Hermans Symposium EWI
Slides Felienne Hermans Symposium EWI
Devnology
 
Devnology auteursrecht en open source 20130205
Devnology auteursrecht en open source 20130205Devnology auteursrecht en open source 20130205
Devnology auteursrecht en open source 20130205
Devnology
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
Devnology
 
Devnology Back to School IV - Agility en Architectuur
Devnology Back to School IV - Agility en ArchitectuurDevnology Back to School IV - Agility en Architectuur
Devnology Back to School IV - Agility en Architectuur
Devnology
 
Introduction to Software Evolution: The Software Volcano
Introduction to Software Evolution: The Software VolcanoIntroduction to Software Evolution: The Software Volcano
Introduction to Software Evolution: The Software Volcano
Devnology
 
Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011
Devnology
 
Devnology Coding Dojo 05-01-2011
Devnology Coding Dojo 05-01-2011Devnology Coding Dojo 05-01-2011
Devnology Coding Dojo 05-01-2011
Devnology
 
Experimenting with Augmented Reality
Experimenting with Augmented RealityExperimenting with Augmented Reality
Experimenting with Augmented Reality
Devnology
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in Silverlight
Devnology
 
mobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkelingmobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkeling
Devnology
 

Mehr von Devnology (20)

What do we really know about the differences between static and dynamic types?
What do we really know about the differences between static and dynamic types?What do we really know about the differences between static and dynamic types?
What do we really know about the differences between static and dynamic types?
 
Meetup at SIG: Meten is weten
Meetup at SIG: Meten is wetenMeetup at SIG: Meten is weten
Meetup at SIG: Meten is weten
 
Software Operation Knowledge
Software Operation KnowledgeSoftware Operation Knowledge
Software Operation Knowledge
 
Slides Felienne Hermans Symposium EWI
Slides Felienne Hermans Symposium EWISlides Felienne Hermans Symposium EWI
Slides Felienne Hermans Symposium EWI
 
Devnology auteursrecht en open source 20130205
Devnology auteursrecht en open source 20130205Devnology auteursrecht en open source 20130205
Devnology auteursrecht en open source 20130205
 
The top 10 security issues in web applications
The top 10 security issues in web applicationsThe top 10 security issues in web applications
The top 10 security issues in web applications
 
Hacking Smartcards & RFID
Hacking Smartcards & RFIDHacking Smartcards & RFID
Hacking Smartcards & RFID
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
Learn a language : LISP
Learn a language : LISPLearn a language : LISP
Learn a language : LISP
 
Devnology Back to School: Empirical Evidence on Modeling in Software Development
Devnology Back to School: Empirical Evidence on Modeling in Software DevelopmentDevnology Back to School: Empirical Evidence on Modeling in Software Development
Devnology Back to School: Empirical Evidence on Modeling in Software Development
 
Devnology Back to School IV - Agility en Architectuur
Devnology Back to School IV - Agility en ArchitectuurDevnology Back to School IV - Agility en Architectuur
Devnology Back to School IV - Agility en Architectuur
 
Devnology Back to School III : Software impact
Devnology Back to School III : Software impactDevnology Back to School III : Software impact
Devnology Back to School III : Software impact
 
Devnology back toschool software reengineering
Devnology back toschool software reengineeringDevnology back toschool software reengineering
Devnology back toschool software reengineering
 
Introduction to Software Evolution: The Software Volcano
Introduction to Software Evolution: The Software VolcanoIntroduction to Software Evolution: The Software Volcano
Introduction to Software Evolution: The Software Volcano
 
Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011Devnology Workshop Genpro 2 feb 2011
Devnology Workshop Genpro 2 feb 2011
 
Devnology Coding Dojo 05-01-2011
Devnology Coding Dojo 05-01-2011Devnology Coding Dojo 05-01-2011
Devnology Coding Dojo 05-01-2011
 
Experimenting with Augmented Reality
Experimenting with Augmented RealityExperimenting with Augmented Reality
Experimenting with Augmented Reality
 
Unit testing and MVVM in Silverlight
Unit testing and MVVM in SilverlightUnit testing and MVVM in Silverlight
Unit testing and MVVM in Silverlight
 
mobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkelingmobl: Een DSL voor mobiele applicatieontwikkeling
mobl: Een DSL voor mobiele applicatieontwikkeling
 
Devnology Fitnesse workshop
Devnology Fitnesse workshopDevnology Fitnesse workshop
Devnology Fitnesse workshop
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 

Kürzlich hochgeladen (20)

Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 

Spoofax: ontwikkeling van domeinspecifieke talen in Eclipse

  • 1. The Spoofax Language Workbench Eelco Visser Lennart Kats Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  • 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. Example DSL: Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  • 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. Problem: building DSLs (ct’d) Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  • 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. 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. • <spoofax screenshot: lang def and lang use in Eclipse workspace> Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology
  • 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. #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. #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. The Spoofax Solution: Declarative Syntax with SDF Declarative, explicit disambigation rules Clean abstract syntax Composable syntax definitions
  • 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. #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. #3 Equations New syntax New semantics x = 2 y = 3 result = 90 * x + 30 * y
  • 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. x = 2 y = 3 result = 90 * x + 30 * z #4 Error markers (Var(“z”), “Variable z is not defined”) transform
  • 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. #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. #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
  • 23. Syntax definition Static semantics Model-to-model transformation Code generation Syntactic Editor Services Semantic Editor Services }Spoofax www.spoofax.org