2. What is needed to implement a DSL?
define lexer and parser using some parser generator
transform parse tree get the model
resolve references
build validation
implement a type system
interpret or compile the model
build simple editor for the language
ident = letter {letter}
IfStmt = ”if” ”(” BoolExpr ”)” {Stmt}
class IfStmt extends Stmt {
int x=1; int y=x+5;
bool x; if (x>5) {
weight x = 15 mm;
load x; load y; add;
abstract syntax tree
3. Code generation
interpretation instructions executed directly
compilation generate code in another language
transpilation source-to-source compiler
no need to compile to machine language
slow
machine language
Java C#
4. IDE integration
DSL
should be shipped with DSLpowerful IDE adoption & success of DSL
reading code validating code executing code
IDE syntax-aware editor not the case for internal DSLs
immediate feedback report errors as they appear
incremental syntax checking validate code as it is being typed
suggesting corrections quickfixes
auto-completion
5.
6. Syntax highlighting
program colored formatted
commentskeywords stringsnot just cosmetic
immediate feedback on syntactic correctness of what is written
7. Background validation
program write save switch to command line run compiler
rewriteerrors
errors found too late
programming
environment
continuously check code
while programmer is writing
even if the current file is not saved
highlight errors
in the background
directly in the editor
9. Hyperlinking and hovering
navigate between references especially useful if declaration is in a different file
hovering:
display a pop-up
window with
documentation
about an element