spoofax: ontwikkeling van domeinspecifieke talen in eclipse

23
The Spoofax Language Workbench Eelco Visser Lennart Kats Spoofax tutorial hands-on material: www.strategoxt.org/Spoofax/Devnology

Upload: devnology

Post on 20-Aug-2015

904 views

Category:

Technology


2 download

TRANSCRIPT

The SpoofaxLanguage Workbench

Eelco VisserLennart 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

templateengines

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

21

3

++

213

++

is that or ?

what does the abstract syntax view say?

#1 Syntax definition

• Basic expression language

1+2*3

21

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