97
TI1220 2012-2013 Concepts of Programming Languages Eelco Visser / TU Delft Lecture 14: Domain-Specific Languages

TI1220 Lecture 14: Domain-Specific Languages

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: TI1220 Lecture 14: Domain-Specific Languages

TI1220 2012-2013Concepts of Programming Languages

Eelco Visser / TU Delft

Lecture 14: Domain-Specific Languages

Page 3: TI1220 Lecture 14: Domain-Specific Languages

Linguistic Abstraction

Formalizing Design Patterns

Page 4: TI1220 Lecture 14: Domain-Specific Languages

ProblemDomain

SolutionDomain

implement

validate

Software Engineering

Page 5: TI1220 Lecture 14: Domain-Specific Languages

Software Reuse: Don’t Repeat Yourself

software reuse patterns

• copy and paste

• libraries

• frameworks

• service APIs

• design patterns

Page 6: TI1220 Lecture 14: Domain-Specific Languages

Linguistic Abstraction

identify pattern

use new abstraction

language A language Bdesign abstraction

Page 7: TI1220 Lecture 14: Domain-Specific Languages

From Instructions to Expressions

mov &a, &cadd &b, &cmov &a, &t1sub &b, &t1and &t1,&c

Source: http://sites.google.com/site/arch1utep/home/course_outline/translating-complex-expressions-into-assembly-language-using-expression-trees

c = ac += bt1 = at1 -= bc &= t1

c = (a + b) & (a - b)

Page 8: TI1220 Lecture 14: Domain-Specific Languages

From Calling Conventions to Procedures

calc: push eBP ; save old frame pointer mov eBP,eSP ; get new frame pointer sub eSP,localsize ; reserve place for locals . . ; perform calculations, leave result in AX . mov eSP,eBP ; free space for locals pop eBP ; restore old frame pointer ret paramsize ; free parameter space and return

f(e1,e2,...,en)

push eAX ; pass some register resultpush byte[eBP+20] ; pass some memory variable (FASM/TASM syntax)push 3 ; pass some constantcall calc ; the returned result is now in eAX

f(x) { ... }

http://en.wikipedia.org/wiki/Calling_convention

Page 9: TI1220 Lecture 14: Domain-Specific Languages

A structure is a collection of one or more variables, possibly of different types, grouped together under a single name for convenient handling. (Structures are called ``records'' in some languages, notably Pascal.)

struct point { int x; int y;};

member

structure tag

Structures in C: Abstract from Memory Layout

Page 10: TI1220 Lecture 14: Domain-Specific Languages

Malloc/Free to Automatic Memory Management

/* Allocate space for an array with ten elements of type int. */

int *ptr = (int*)malloc(10 * sizeof (int));if (ptr == NULL) { /* Memory could not be allocated, the program should handle the error here as appropriate. */} else { /* Allocation succeeded. Do something. */ free(ptr); /* We are done with the int objects, and free the associated pointer. */ ptr = NULL; /* The pointer must not be used again, unless re-assigned to using malloc again. */}

http://en.wikipedia.org/wiki/Malloc

int [] = new int[10];/* use it; gc will clean up (hopefully) */

Page 11: TI1220 Lecture 14: Domain-Specific Languages

typedef struct Base { void* (**vtable)(); int x;} Base;

void (*Base_Vtable[])() = { &Base_print };

Base* newBase(int v) { Base* obj = (Base*)malloc(sizeof(Base)); obj->vtable = Base_Vtable; obj->x = v; return obj;}

void print(Base* obj) { obj->vtable[0](obj);}

class Base { Integer x; public Base(Integer v) { x = v; } public void print() { System.out.println("Base: " + x); }}class Child extends Base { Integer y; public Child(Integer v1, Integer v2) { super(v1); y = v2; } public void print() { System.out.println("Child: (" + x + "," + y + ")"); }}

Dynamic Dispatch

Page 12: TI1220 Lecture 14: Domain-Specific Languages

Polymorphic Higher-Order Functions

def map[A,B](f: A => B, xs: List[A]): List[B] = { xs match{ case Nil() => Nil() case Cons(y, ys) => Cons(f(y), map(f, ys)) } }

def incList(xs: IntList): IntList = xs match { case Nil() => Nil() case Cons(y, ys) => Cons(y + 1, incList(ys)) }

Page 13: TI1220 Lecture 14: Domain-Specific Languages

Abstractions in Programming Languages

❖ Structured control-flow

★ if-then-else, while

❖ Procedural abstraction

★ procedures, first-class functions (closures)

❖ Memory management

★ garbage collection

❖ Data abstraction

★ abstract data types, objects

❖ Modules

★ inheritance, traits, mixins

Page 14: TI1220 Lecture 14: Domain-Specific Languages

“A programming language is low level when its programs require attention to the irrelevant”

Alan J. Perlis. Epigrams on Programming. SIGPLAN Notices, 17(9):7-13, 1982.

Page 15: TI1220 Lecture 14: Domain-Specific Languages

Do HLLs eliminate all irrelevant details?

What about

❖ data persistence

❖ data services

❖ concurrency

❖ distribution

❖ access control

❖ data invariants

❖ workflow

❖ ...

Page 16: TI1220 Lecture 14: Domain-Specific Languages

Do HLLs eliminate all irrelevant details?

What about

❖ data persistence

❖ data services

❖ concurrency

❖ distribution

❖ access control

❖ data invariants

❖ workflow

❖ ...

many of these concerns require

programmatic encodings

Page 17: TI1220 Lecture 14: Domain-Specific Languages

What is the Next Level of Abstraction?

ProblemDomain HLL Machine

Page 18: TI1220 Lecture 14: Domain-Specific Languages

Domain-Specific Languages

ProblemDomain HLL MachineDSL

Page 19: TI1220 Lecture 14: Domain-Specific Languages

Example: Encoding Units

compiler

computerinput

input distance : Float;input duration : Float;output speed : Float := duration / distance;

output

Page 20: TI1220 Lecture 14: Domain-Specific Languages

Example: Encoding Units

compiler

computerinput

input distance : Float;input duration : Float;output speed : Float := duration / distance;

error

wrong output

Page 21: TI1220 Lecture 14: Domain-Specific Languages

Impact of Software Errors

compiler

computer

error

Mars Climate OrbiterUnit mismatch: Orbiter variables in Newtons, Ground control software in Pound-force.

Damage: ~350 M$

input distance : Float;input duration : Float;output speed : Float := duration / distance;

wrong output

Page 22: TI1220 Lecture 14: Domain-Specific Languages

Example: Explicit Representation of Units

computer

input distance : Meter;input duration : Second;output speed : Meter/Second := duration / distance;

compiler

formalize knowledge of application area (domain) in language

error

Page 23: TI1220 Lecture 14: Domain-Specific Languages

DSLs Provide Domain-Specific ...

Abstractions

★ directly represent domain concepts

Concrete syntax

★ natural notation

Optimization

★ based on domain assumptions

Error checking

★ report errors in terms of domain concepts

Tool support

★ interpreter, compiler, code generator, IDE

Page 24: TI1220 Lecture 14: Domain-Specific Languages

Internal DSL

Library in HLL

★ Haskell, Scala, Ruby, ...

★ API is language

★ language features for ‘linguistic abstraction’

Advantages

★ host language = implementation language

Disadvantages

★ host language = implementation language (encoding)

★ no portability

★ no domain-specific errors, analysis, optimization

Page 25: TI1220 Lecture 14: Domain-Specific Languages

External DSL

Dedicated language

★ independent of host/target language (portable)

★ implementation with interpreter or compiler

Advantages

★ language tuned to domain

★ domain-specific errors, analysis, optimizations

Disadvantages

★ cost of learning new language

★ cost of maintaining language

Page 26: TI1220 Lecture 14: Domain-Specific Languages

Example DSLs (1)

Spreadsheet

★ formulas, macros

Querying

★ SQL, XQuery, XPath

Graph layout

★ GraphViz

Web

★ HTML, CSS, RSS, XML, XSLT

★ Ruby/Rails, JSP, ASP, JSF, WebDSL

Page 27: TI1220 Lecture 14: Domain-Specific Languages

Example DSLs (2)

Games

★ Lua, UnrealScript

Modeling

★ UML, OCL, QVT

Language engineering

★ YACC, LEX, RegExp, ANTLR, SDF

★ TXL, ASF+SDF, Stratego

Page 28: TI1220 Lecture 14: Domain-Specific Languages

Example: Linguistic Integration in

WebDSL

Page 29: TI1220 Lecture 14: Domain-Specific Languages

browser server database

web app

Web Programming

Page 30: TI1220 Lecture 14: Domain-Specific Languages

browser server database

Java SQLHTML, JS, CSS

Web Programming = Distributed Programming

Page 31: TI1220 Lecture 14: Domain-Specific Languages

Concerns in Web Programming

Data Persistence

Access Control

Injection Attacks

Search

XSS

Data Validation

Data Binding

Routing

... ...

Page 33: TI1220 Lecture 14: Domain-Specific Languages

Complexity in Web Programming:

Multiple Languages x Multiple Concerns

Consistency not statically checked

Page 35: TI1220 Lecture 14: Domain-Specific Languages
Page 36: TI1220 Lecture 14: Domain-Specific Languages

Formalizing Navigation Logic

Page 38: TI1220 Lecture 14: Domain-Specific Languages

page blog(b: Blog, index: Int) { main(b){ for(p: Post in b.recentPosts(index,5)) { section{ header{ navigate post(p) { output(p.title) } } par{ output(p.content) } par{ output(p.created.format("MMMM d, yyyy")) } } }}page post(p: Post) { ... }

Statically checked navigation

Page 39: TI1220 Lecture 14: Domain-Specific Languages

entity Blog { key :: String (id) title :: String (name) posts -> Set<Post> (inverse=Post.blog) function recentPosts(index: Int, n: Int): List<Post> { var i := max(1,index) - 1; return [p | p: Post in posts order by p.created desc limit n offset i*n].list(); }}entity Post { key :: String (id) title :: String (name, searchable) content :: WikiText (searchable) blog -> Blog }

Persistent Data Models

Generation of queries: no injection attacks

Page 40: TI1220 Lecture 14: Domain-Specific Languages

entity Assignment { key :: String (id) title :: String (name, searchable) shortTitle :: String description :: WikiText (searchable) course -> CourseEdition (searchable) weight :: Float (default=1.0) deadline :: DateTime (default=null) // ...} page assignment(assign: Assignment, tab: String) { main{ progress(assign, tab) pageHeader{ output(assign.title) breadcrumbs(assign) } // ... } }

Persistent variables in WebDSL

http://department.st.ewi.tudelft.nl/weblab/assignment/752

objects are automatically persisted in database

1

2

3

Page 41: TI1220 Lecture 14: Domain-Specific Languages

page post(p: Post) { ... }page editpost(p: Post) { action save() { return blog(p); } main(p.blog){ form{ formEntry("Title"){ input(p.title) } formEntry("Content") { input(p.content) } formEntry("Posted") { input(p.created) } submit save() { "Save" } } }}

Forms & Data Binding

No separate controller!

Page 42: TI1220 Lecture 14: Domain-Specific Languages

access control rules

principal is User with credentials username, password rule page blog(b: Blog, index: Int) { true } rule page post(p: Post) { p.public || p.author == principal } rule page editpost(p: Post) { principal == p.author }

extend entity User { password :: Secret}

extend entity Blog { owner -> User}

extend entity Post { public :: Bool}

Declarative Access Control Rules

Page 43: TI1220 Lecture 14: Domain-Specific Languages

Linguistically Integrated

Persistent data model

Logic

Templates (UI, Email, Service)

Data binding

Access control

Data validation

Faceted search

Collaborative filtering

Page 44: TI1220 Lecture 14: Domain-Specific Languages

DSL Summary

software reuse through linguistic abstraction

• capture understanding of design patterns in language concepts

• abstract from accidental complexity

• program in terms of domain concepts

• automatically generate implementation

Page 45: TI1220 Lecture 14: Domain-Specific Languages

When to Use/Create DSLs?

Hierarchy of abstractions

• first understand how to program it

• make variations by copy, paste, adapt

• (avoid over-engineering)

• make library of frequently used patterns

• find existing (internal) DSLs for the domain

Time for a DSL?

• large class of applications using same design patterns

• design patterns cannot be captured in PL

• lack of checking / optimization for DSL abstractions

Page 46: TI1220 Lecture 14: Domain-Specific Languages

Language Engineering

Page 47: TI1220 Lecture 14: Domain-Specific Languages

object ExpParser extends JavaTokenParsers with PackratParsers { lazy val exp: PackratParser[Exp] = (exp <~ "+") ~ exp1 ^^ { case lhs~rhs => Add(lhs, rhs) } | exp1

lazy val exp1: PackratParser[Exp] = (exp1 ~ exp0) ^^ { case lhs~rhs => App(lhs, rhs) } | exp0 lazy val exp0: PackratParser[Exp] = number | identifier | function | letBinding | "(" ~> exp <~ ")" // ... def parse(text: String) = parseAll(exp, text)}

syntax through parsers

Page 48: TI1220 Lecture 14: Domain-Specific Languages

sealed abstract class Valuecase class numV(n: Int) extends Valuecase class closureV(param: Symbol, body: Exp, env: Env) extends Value

def eval(exp: Exp, env: Env): Value = exp match { case Num(v) => numV(v) case Add(l, r) => plus(eval(l, env), eval(r, env)) case Id(name) => lookup(name, env) case Let(name, e1, e2) => eval(e2, bind(name, eval(e1, env), env))

case Fun(name, body) => closureV(name, body, env)

case App(fun, arg) => eval(fun, env) match { case closureV(name, body, env2) => eval(body, bind(name, eval(arg, env), env2)) case _ => sys.error("Closure expected") }

} semantics through interpreter

Page 49: TI1220 Lecture 14: Domain-Specific Languages

Traditional Compilers

Page 50: TI1220 Lecture 14: Domain-Specific Languages

Traditional Compilers

ls

Course.java

Page 51: TI1220 Lecture 14: Domain-Specific Languages

Traditional Compilers

ls

Course.java

javac -verbose Course.java

[parsing started Course.java][parsing completed 8ms][loading java/lang/Object.class(java/lang:Object.class)][checking university.Course][wrote Course.class][total 411ms]

Page 52: TI1220 Lecture 14: Domain-Specific Languages

Traditional Compilers

ls

Course.java

javac -verbose Course.java

[parsing started Course.java][parsing completed 8ms][loading java/lang/Object.class(java/lang:Object.class)][checking university.Course][wrote Course.class][total 411ms]

ls

Course.class Course.java

Page 53: TI1220 Lecture 14: Domain-Specific Languages

Language Processors

syntax analysis

• parsing

• AST construction

static analysis

• name analysis

• type analysis

semantics

• generation

• interpretation

Page 54: TI1220 Lecture 14: Domain-Specific Languages

Integrated Development Environments (IDE)

Page 55: TI1220 Lecture 14: Domain-Specific Languages

Modern Compilers in IDEs

syntactic editor services

• syntax checking

• syntax highlighting

• outline view

• code folding

• bracket matching

semantic editor services

• error checking

• reference resolving

• hover help

• content completion

• refactoring

Page 56: TI1220 Lecture 14: Domain-Specific Languages

Eclipse Platform

runtime platform

• composition

• integration

development platform

• complex APIs

• abstractions for Eclipse IDEs

• concepts: editors, views, label provider, label provider factory, …

• tedious, boring, frustrating

Page 57: TI1220 Lecture 14: Domain-Specific Languages

Spoofax Language Workbench

declarative meta-languages

• syntax definition

• editor services

• term rewriting

implementation

• generic integration into Eclipse and IMP

• compilation & interpretation of language definitions

agile

• Spoofax & IDE under development in same Eclipse instance

• support for test-driven development

Page 58: TI1220 Lecture 14: Domain-Specific Languages

A Taste of Language Engineeringwith Spoofax

• abstract syntax trees

• declarative syntax definition

• name binding and scope

• transformation by term rewriting

Page 59: TI1220 Lecture 14: Domain-Specific Languages

EnFun: Entities with Functions

module blog entity String { function plus(that:String): String } entity Bool { } entity Set<T> { function add(x: T) function remove(x: T) function member(x: T): Bool } entity Blog { posts : Set<Post> function newPost(): Post { var p : Post := Post.new(); posts.add(p); } } entity Post { title : String }

Page 60: TI1220 Lecture 14: Domain-Specific Languages

Structure: Abstract Syntax

Page 61: TI1220 Lecture 14: Domain-Specific Languages

Signature & Terms

constructors Module : ID * List(Definition) -> Module Imports : ID -> Definition

Module( "application", [Imports("library"), Imports("users"), Imports("frontend")])

Page 62: TI1220 Lecture 14: Domain-Specific Languages

Entities & Properties

constructors Entity : ID * List(Property) -> Definition Type : ID -> Type New : Type -> Exp

constructors Property : ID * Type -> Property This : Exp PropAccess : Exp * ID -> Exp

Module("users", [ Imports("library") , Entity("User" , [ Property("email", Type("String")) , Property("password", Type("String")) , Property("isAdmin", Type("Bool"))])])

Page 63: TI1220 Lecture 14: Domain-Specific Languages

Parsing: From Text to Structure

Page 64: TI1220 Lecture 14: Domain-Specific Languages

Declarative Syntax Definition

Entity("User", [ Property("first", Type("String")), Property("last", Type("String"))])

signature constructors Entity : ID * List(Property) -> Definition Type : ID -> Type Property : ID * Type -> Property

Page 65: TI1220 Lecture 14: Domain-Specific Languages

Declarative Syntax Definition

entity User { first : String last : String}

Entity("User", [ Property("first", Type("String")), Property("last", Type("String"))])

signature constructors Entity : ID * List(Property) -> Definition Type : ID -> Type Property : ID * Type -> Property

Page 66: TI1220 Lecture 14: Domain-Specific Languages

Declarative Syntax Definition

entity User { first : String last : String}

Entity("User", [ Property("first", Type("String")), Property("last", Type("String"))])

signature constructors Entity : ID * List(Property) -> Definition Type : ID -> Type Property : ID * Type -> Property

context-free syntax "entity" ID "{" Property* "}" -> Definition {"Entity"} ID -> Type {"Type"} ID ":" Type -> Property {"Property"}

Page 67: TI1220 Lecture 14: Domain-Specific Languages

Prototyping Syntax Definition

Page 68: TI1220 Lecture 14: Domain-Specific Languages

Context-free Syntax

constructors True : Exp False : Exp Not : Exp -> Exp And : Exp * Exp -> Exp Or : Exp * Exp -> Exp

context-free syntax "true" -> Exp {"True"} "false" -> Exp {"False"} "!" Exp -> Exp {"Not"} Exp "&&" Exp -> Exp {"And"} Exp "||" Exp -> Exp {"Or"}

Page 69: TI1220 Lecture 14: Domain-Specific Languages

Lexical Syntax

constructors True : Exp False : Exp Not : Exp -> Exp And : Exp * Exp -> Exp Or : Exp * Exp -> Exp

context-free syntax "true" -> Exp {"True"} "false" -> Exp {"False"} "!" Exp -> Exp {"Not"} Exp "&&" Exp -> Exp {"And"} Exp "||" Exp -> Exp {"Or"}

lexical syntax [a-zA-Z][a-zA-Z0-9]* -> ID "-"? [0-9]+ -> INT [\ \t\n\r] -> LAYOUT

constructors : String -> ID : String -> INT

scannerless generalized (LR) parsing

form of tokens (words, lexemes)

Page 70: TI1220 Lecture 14: Domain-Specific Languages

Ambiguity

constructors True : Exp False : Exp Not : Exp -> Exp And : Exp * Exp -> Exp Or : Exp * Exp -> Exp

context-free syntax "true" -> Exp {"True"} "false" -> Exp {"False"} "!" Exp -> Exp {"Not"} Exp "&&" Exp -> Exp {"And"} Exp "||" Exp -> Exp {"Or"}

isPublic || isDraft && (author == principal())

Page 71: TI1220 Lecture 14: Domain-Specific Languages

Ambiguity

constructors True : Exp False : Exp Not : Exp -> Exp And : Exp * Exp -> Exp Or : Exp * Exp -> Exp

context-free syntax "true" -> Exp {"True"} "false" -> Exp {"False"} "!" Exp -> Exp {"Not"} Exp "&&" Exp -> Exp {"And"} Exp "||" Exp -> Exp {"Or"}

isPublic || isDraft && (author == principal())

amb([ And(Or(Var("isPublic"), Var("isDraft")), Eq(Var("author"), ThisCall("principal", []))), Or(Var("isPublic"), And(Var("isDraft"), Eq(Var("author"), ThisCall("principal", []))))])

Page 72: TI1220 Lecture 14: Domain-Specific Languages

Disambiguation by Encoding Precedence

constructors True : Exp False : Exp Not : Exp -> Exp And : Exp * Exp -> Exp Or : Exp * Exp -> Exp

context-free syntax "true" -> Exp {"True"} "false" -> Exp {"False"} "!" Exp -> Exp {"Not"} Exp "&&" Exp -> Exp {"And"} Exp "||" Exp -> Exp {"Or"}

context-free syntax "(" Exp ")" -> Exp0 {bracket} "true" -> Exp0 {"True"} "false" -> Exp0 {"False"} Exp0 -> Exp1 "!" Exp0 -> Exp1 {"Not"} Exp1 -> Exp2 Exp1 "&&" Exp2 -> Exp2 {"And"} Exp2 -> Exp3 Exp2 "||" Exp3 -> Exp3 {"Or"}

Page 73: TI1220 Lecture 14: Domain-Specific Languages

Declarative Disambiguation

context-free syntax "true" -> Exp {"True"} "false" -> Exp {"False"} "!" Exp -> Exp {"Not"} Exp "&&" Exp -> Exp {"And", left} Exp "||" Exp -> Exp {"Or", left} "(" Exp ")" -> Exp {bracket}context-free priorities {left: Exp.Not} > {left: Exp.Mul} > {left: Exp.Plus Exp.Minus} > {left: Exp.And} > {non-assoc: Exp.Eq Exp.Lt Exp.Gt Exp.Leq Exp.Geq}

isPublic || isDraft && (author == principal())

Or(Var("isPublic"), And(Var("isDraft"), Eq(Var("author"), ThisCall("principal", []))))

Page 74: TI1220 Lecture 14: Domain-Specific Languages

Analysis: Name Resolution

+

Page 75: TI1220 Lecture 14: Domain-Specific Languages

Definitions and References

module test

entity String { }

entity User { first : String last : String }

definition

reference

Page 76: TI1220 Lecture 14: Domain-Specific Languages

Name Binding in IDE

Page 77: TI1220 Lecture 14: Domain-Specific Languages

From Tree to Graph

Module( "test", [ Entity("String", []) , Entity( "User" , [ Property("first", ) , Property("last", ) ] ) ])

Page 78: TI1220 Lecture 14: Domain-Specific Languages

NaBL: Name Binding Language

module names

imports include/Cam namespaces Type Property Function Variable rules

Entity(name, None(), None(), _): defines Type name of type Type(name, []) scopes Type, Function, Property, Variable

Type(name, _): refers to Type name

Page 79: TI1220 Lecture 14: Domain-Specific Languages

Transformation

Page 80: TI1220 Lecture 14: Domain-Specific Languages

Transformation by Strategic Rewriting

rules desugar: Plus(e1, e2) -> MethCall(e1, "plus", [e2]) desugar: Or(e1, e2) -> MethCall(e1, "or", [e2])

desugar : VarDeclInit(x, t, e) -> Seq([VarDecl(x, t), Assign(Var(x), e)])

strategies desugar-all = topdown(repeat(desugar))

Page 81: TI1220 Lecture 14: Domain-Specific Languages

Return-Lifting Applied

function fact(n: Int): Int { var res: Int; if(n == 0) { res := 1; } else { res := this * fact(n - 1); } return res;}

function fact(n: Int): Int {

if(n == 0) { return 1; } else { return this * fact(n - 1); }

}

Page 82: TI1220 Lecture 14: Domain-Specific Languages

Return-Lifting Rules

rules lift-return-all = alltd(lift-return; normalize-all) lift-return : FunDef(x, arg*, Some(t), stat1*) -> FunDef(x, arg*, Some(t), Seq([ VarDecl(y, t), Seq(stat2*), Return(Var(y)) ])) where y := <new>; stat2* := <alltd(replace-return(|y))> stat1* replace-return(|y) : Return(e) -> Assign(y, e)

Page 83: TI1220 Lecture 14: Domain-Specific Languages

Language Engineering Summary

apply linguistic abstraction to language engineering

• declarative languages for language definition

• automatic derivation of efficient compilers

• automatic derivation of IDEs

Page 84: TI1220 Lecture 14: Domain-Specific Languages

Research Agenda

Page 85: TI1220 Lecture 14: Domain-Specific Languages

Example: Explicit Representation of Units

computer

input distance : Meter;input duration : Second;output speed : Meter/Second := duration / distance;

compiler

formalize knowledge of application area (domain) in language

error

Page 86: TI1220 Lecture 14: Domain-Specific Languages

error

Problem: Correctness of Language Definitions

computer

compilerCan we trust the compiler?

wrong outputinput

program

type soundness: well-typed programs don’t go wrong

Page 87: TI1220 Lecture 14: Domain-Specific Languages

compiler

error

Challenge: Automatic Verification of Correctness

computer

compiler

wrong output

program

type soundness: well-typed programs don’t go wrong

typechecker

codegenerator

input

Page 88: TI1220 Lecture 14: Domain-Specific Languages

CorrectnessProof

Language Workbench

State-of-the-Art: Language Engineering

SyntaxChecker

NameResolver

TypeChecker

CodeGenerator

focus on implementation; not suitable for verification

CompilerEditor(IDE) Tests

Page 89: TI1220 Lecture 14: Domain-Specific Languages

Formal Language Specification

State-of-the-Art: Semantics Engineering

AbstractSyntax

TypeSystem

DynamicSemantics Transforms

focus on (only semi-automatic) verification; not suitable for implementation

CorrectnessProof TestsCompiler

Editor(IDE)

Page 90: TI1220 Lecture 14: Domain-Specific Languages

Declarative Language Definition

My Approach: Multi-Purpose Language Definitions

SyntaxDefinition

NameBinding

TypeSystem

DynamicSemantics Transforms

CompilerEditor(IDE)

CorrectnessProof Tests

bridging the gap between language engineering and semantics engineering

Page 91: TI1220 Lecture 14: Domain-Specific Languages

Software Development on the Web

revisiting the architecture of the IDE

Page 92: TI1220 Lecture 14: Domain-Specific Languages

Exam

Page 94: TI1220 Lecture 14: Domain-Specific Languages

Material for exam

Slides from lectures

Tutorial exercises

Graded assignments

Sebesta: Chapters 1-13, 15

Programming in Scala: Chapters 1, 4-16, 19, 32-33

K&R C: Chapters 1-6

JavaScript Good Parts: Chapters 1-4

Page 95: TI1220 Lecture 14: Domain-Specific Languages

Content of exam

10% multiple choice questions about concepts

50% Scala programming (functional programming)

20% C programming (structures and pointers)

20% JavaScript programming (objects and prototypes)

Page 96: TI1220 Lecture 14: Domain-Specific Languages

Registration for Exam is Required

http://department.st.ewi.tudelft.nl/weblab/assignment/761 -> your submission

Page 97: TI1220 Lecture 14: Domain-Specific Languages

Good Luck!