SlideShare a Scribd company logo
L0080 - 2010-11-02
Redistribution and other use of this material requires written permission from The RCP Company.
ITU - MDD – Textural Languages and Grammars
This presentation describes the use and design of textural domain specific
language - DSL. It has two basic purposes:
Introduce you to some of the more important design criteria in language
design
Introduce you to BNF
This presentation is developed for MDD 2010 course at ITU, Denmark.
Some materials are taken from Artur Boronat, University of Leicester with permissions.
L0080 - 2010-11-02
2
Textual DSLs versus Graphical DSLs
 With both textual and graphical syntax you can
 model any meta model
 verify constraints in real time
 (Eclipse) write ordinary EMF models
 Graphical Editors are good to show structural relationships
 Graphical Editors are sexy and often appeals to management
 Textual Editors are better for „algorithmic“ aspects, or hierarchical models
 Textual Editors integrate better with CVS etc. (diff, merge)
 Textual Editors often provides better support for quick assist and quick fixes
 If you must work with a DSL many hours every day, consider textual DSLs over
graphical DSLs!’
L0080 - 2010-11-02
3
What is needed for a successful DSL
 You must know
 The intended audience
 The expressiveness of the language
 The extendibility of the language
L0080 - 2010-11-02
4
The intended audience
 Who will be using the language
 Temporary help in a call center
 Full-time Clerks
 Accountants
 Engineers – like yourselves
 Any mismatch between the language and the audience is likely to alienate your
audience
 Keywords:
 concise vs. redundant
 intuitive
 simple to write and read
(host “heimdal”
(ipif 192.167.54.55)
(disk:type SSD 500GB))
Define host name = “heimdal”
with IP interface
IPv4 address = 192.167.54.55
end IP address
with disk
type = SSD
size = 500GB
end disk
End host
L0080 - 2010-11-02
5
The expressiveness of the language
 What type of information must be expressed in the language:
 Simple static information
 Complex network of objects
 Algorithms
 Must the DSL be Turing complete?
 What type of constructs must be supported
 Lists
 Tables
 Recursive data structures
 Variables
 Macros
 Conditions and loops
 Functions
 Comments
E = MC2
L0080 - 2010-11-02
6
The extendibility of the language
 Can you be absolute certain that the language will never be extended?
 “The last language…”
 Backward compatibility
 If your grammar is successful, then it will be used – so what should you do
with all the existing “stuff” when you need to extend your grammar with new
functionality
 Open versus closed grammars
 An open grammar can be extended in the future with new constructs or
statements in a natural manner
 A closed grammar can be very difficult to extend while retaining backward
compatibility
heimdal 192.167.54.55 SSD 500
(host “heimdal”
(ipif 192.167.54.55)
(disk type SSD 500GB))
L0080 - 2010-11-02
7
Internal versus External DSLs
 Textual DSLs are normally divided into two distinct groups:
 Internal DSL (or extension language)

Using the syntax and semantics of a host language or system – e.g. Java
or Excel

You can argument that any API is in itself an DSL
 External DSL

A completely new language
L0080 - 2010-11-02
8
Some Examples
Internal DSL
 4GL – attempt in the 1990s to raise the productivity of programmers by adding
more high-level constructs to 3GL languages (such as C, Pascal, etc)
 JSP – current attempt to ease the creation of web pages by adding Java as an
embedded scripting language
 Some languages that have been designed to be a good host language for DSL:
 Tcl
 Python
 Groovy
 Ruby
final IFormCreator detailsSection = myForm.addSection("Details",
table.getBinding().getSingleSelection());
detailsSection.addObjectMessages();
detailsSection.addField("contact.name(w=200)");
detailsSection.addField("logoFileName(w=200)");
detailsSection.addField("loyalty").arg(Constants.ARG_PREFERRED_CONTROL,
RadioGroup.class.getName());
# Assume $remote_server, $my_user_id, $my_password, and $my_command
# were read in earlier in the script.
spawn telnet $remote_server expect "username:"
send "$my_user_idr" expect "password:"
send "$my_passwordr" expect "%"
send "$my_commandr" expect "%"
set results $expect_out(buffer)
send "exitr" expect eof
L0080 - 2010-11-02
9
 Consists of two layers
 a lexical layer
 a grammar layer
 Lexical syntax: the spelling of
words and punctuation
 Grammars: the key formalism for
describing syntax; universal progra
mming language
Example
 if (<expr>) <statement>
 if <expr> then <statement>
 <statement> if <expr>
 (if <expr> <statement>)
Formal Syntax of an DSL
if
expression statement
!=
a
constantvariable
if (a != null) b = a.getArg();
“If” “(“ “a” “!=“ “null” “)” “b” “=“ “a” “.” “getArg” “(“ “)” “;”
assignment
a expression
null
… …
L0080 - 2010-11-02
10
 Tokens/Terminals: units in programming language
 Lexical syntax: correspondence between the written representation (spelling) and
the tokens or terminals in a grammar
 Keywords:
 alphabetic character sequences
 unit in a language - if , while
 Punctuation
 Like ‘(‘, ‘)’, ‘:=‘
 Whitespace
Lexical Syntax
if (a != null) b = a.getArg();
“If” “(“ “a” “!=“ “null” “)” “b” “=“ “a” “.” “getArg” “(“ “)” “;”
L0080 - 2010-11-02
11
 Concrete syntax: describes its written representation, including lexical details
such as the placement of keywords and punctuation marks
 Context-free grammar or grammars: notation for specifying concrete syntax
 Context-free means that the understanding of the next token may not depend on
the current context
 Example from PL/1 of a context dependent grammar:

IF IF THEN THEN ELSE ELSE;

Legal if “IF” is a Boolean variable and “THEN” and “ELSE” are valid
procedures
 Most modern languages have a context-free grammar
 Notable exceptions are C and C++!!!
Context-Free Grammars
L0080 - 2010-11-02
12
 Grammar has four parts
 A set of tokens or terminals

atomic symbols that can not be sub-divided
 A set of nonterminals

Identifiers or variables representing constructs
 A set of rules (called productions)

identify the component of construct

<nonterminal >::= terminal | <nonterminal>
 A starting nonterminal

represents a main construct
Describing Context-Free Grammars
assignment => ID = expression;
expression => expression + term
| expression - term
| term
term => term * factor
| term / factor
| factor
factor => ( expression )
| ID
| NUMBER
L0080 - 2010-11-02
13
 The productions are rules for building strings
 Parse Trees: show how a string can be built
Notation to write grammar
 Backus-Naur Form (BNF)
 Extended BNF (EBNF)
Writing Grammars
L0080 - 2010-11-02
14
Backus-Naur Form (Backus Normal Form)
 Grammar Rules or Productions: define symbols.
 Non-terminal Symbols: anything that is defined on the left-side of some
production.
 Terminal Symbols: things that are not defined by productions. They can be
literals, symbols, and other lexemes of the language defined by lexical rules.
 Identifiers: id::= [A-Za-z_]*
 Delimiters: ;
 Operators: = + - * / %
assignment_stmt ::= id = expression;
The non-terminal symbol being
defined.
The definition (production)
L0080 - 2010-11-02
15
 Different notations (same meaning):
 assignment_stmt ::= id = expression + term
 <assignment-stmt> => <id> = <expr> + <term>
 AssignmentStmt → id = expression + term
::=, =>, → mean "consists of" or "defined as"
 Alternatives ( " | " ):
 Concatenation:
Backus-Naur Form (Backus Normal Form)
expression => expression + term
| expression - term
| term
number => DIGIT number | DIGIT
L0080 - 2010-11-02
16
Backus-Naur Form (Backus Normal Form)
 Another way to write alternatives:
 Null symbol,: ε or @
used to allow a production to match nothing.
 Example: a variable is an identifier followed by an optional subscript
Expression => expression + term
=> expression - term
=> term
variable => identifier subscript
subscript => [ expression ] | e
L0080 - 2010-11-02
17
 Here is a grammar for assignment with arithmetic operations, e.g. y = (2*x +
5)*x - 7;
Arithmetic Grammar
assignment => ID = expression;
expression => expression + term
| expression - term
| term
term => term * factor
| term / factor
| factor
factor => ( expression )
| ID
| NUMBER
L0080 - 2010-11-02
18
Example of a Parse Tree
if
expression statement
!=
a
constantvariable
“If” “(“ “a” “!=“ “null” “)” “b” “=“ “a” “.” “getArg” “(“ “)” “;”
assignment
a expression
null
… …
L0080 - 2010-11-02
19
 Grammar Rules:
expr => expr + expr | expr ∗ expr
| ( expr ) | NUMBER
 Expression: 2 + 3 * 4
 Two possible parse trees:
expr
expr expr
expr
+
*expr
expr
expr
+
*expr
exprexprNUMBER
(2)
NUMBER
(3)
NUMBER
(4)
NUMBER
(2)
NUMBER
(3)
NUMBER
(4)
Ambiguity
L0080 - 2010-11-02
20
 The standard metalanguage: Extended BNF
 Terminal symbols of the language are quoted
 [ and ] include optional symbols
 { and } indicate repetition
 ( and ) are used to group items
 | definition-separator-symbol stands for or. In EBNF we need to quote ( and )
literals as '(' ... ')’
 * repetition symbol
 = defining symbol
 ; terminator symbol
EBNF – Extended BNF
L0080 - 2010-11-02
21
BNF versus EBNF
BNF:
EBNF:
expression ::= expression + term
| expression - term
| term
term ::= term * factor
| term / factor
| factor
factor ::= ( expression )
| id
| number
expression ::= term { (‘+’|’-’) term }
term ::= factor { (‘*’|’/’) factor }
factor ::= '(' expression ')'
| id | number
L0080 - 2010-11-02
22
More Information
 “Model-Driven Software Development” by Thomas Stahl and Markus Völter
 Chapter 8.1 “DSL Construction”

Good high-level introduction to DSLs
 “Domain-Specific Languages: An Annotated Bibliography”
 http://homepages.cwi.nl/~arie/papers/dslbib/

Not very interesting except for the very long annotated bibliography!
 “BNF and EBNF: What are they and how do they work?” by Lars Marius Garshol -
http://www.garshol.priv.no/download/text/bnf.html
 About Backus-Naur Form and parsing
 “Internal Domain-Specific Languages”
 http://fragmental.tw/research-on-dsls/domain-specific-languages-dsls/internal-dsls/

Outlines use of DSL in Java and Ruby
L0080 - 2010-11-02
23
Exercise 1
 Design a textual language (grammar) for a travel package.
 How would you like to specify a travel package in text?
 Do you think, you can teach a travel administrator to use the language?
 Is the grammar open – i.e. can it be extended in the future?
 For the grammar you can use ID, STRING and NUMBER as terminators where
relevant

More Related Content

What's hot

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
C material
C materialC material
C material
tarique472
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
JStalinAsstProfessor
 
Meta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student VersionMeta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student Version
Kelly Bauer
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with C
gpsoft_sk
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_languageSINGH PROJECTS
 
Syntax
SyntaxSyntax
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
Muthuselvam RS
 
C++ programming intro
C++ programming introC++ programming intro
C++ programming intromarklaloo
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
Princess Doll
 
PLUG : Presentation Layer Universal Generator
PLUG : Presentation Layer Universal GeneratorPLUG : Presentation Layer Universal Generator
PLUG : Presentation Layer Universal Generator
Emmanuel Fuchs
 
Lectura 3.5 word normalizationintwitter finitestate_transducers
Lectura 3.5 word normalizationintwitter finitestate_transducersLectura 3.5 word normalizationintwitter finitestate_transducers
Lectura 3.5 word normalizationintwitter finitestate_transducersMatias Menendez
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
Archana Gopinath
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
Apoorv Diwan
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constantsvinay arora
 
C presentation book
C presentation bookC presentation book
C presentation book
krunal1210
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
Muhammed Afsal Villan
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
oggyrao
 

What's hot (19)

POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
C material
C materialC material
C material
 
Introduction of c programming unit-ii ppt
Introduction of  c programming unit-ii pptIntroduction of  c programming unit-ii ppt
Introduction of c programming unit-ii ppt
 
Meta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student VersionMeta Languages Railroad Diagrams Student Version
Meta Languages Railroad Diagrams Student Version
 
C101 – Intro to Programming with C
C101 – Intro to Programming with CC101 – Intro to Programming with C
C101 – Intro to Programming with C
 
Introduction of c_language
Introduction of c_languageIntroduction of c_language
Introduction of c_language
 
Syntax
SyntaxSyntax
Syntax
 
CProgrammingTutorial
CProgrammingTutorialCProgrammingTutorial
CProgrammingTutorial
 
C++ programming intro
C++ programming introC++ programming intro
C++ programming intro
 
Lexical analyzer
Lexical analyzerLexical analyzer
Lexical analyzer
 
PLUG : Presentation Layer Universal Generator
PLUG : Presentation Layer Universal GeneratorPLUG : Presentation Layer Universal Generator
PLUG : Presentation Layer Universal Generator
 
Lectura 3.5 word normalizationintwitter finitestate_transducers
Lectura 3.5 word normalizationintwitter finitestate_transducersLectura 3.5 word normalizationintwitter finitestate_transducers
Lectura 3.5 word normalizationintwitter finitestate_transducers
 
A Role of Lexical Analyzer
A Role of Lexical AnalyzerA Role of Lexical Analyzer
A Role of Lexical Analyzer
 
Compier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.pptCompier Design_Unit I_SRM.ppt
Compier Design_Unit I_SRM.ppt
 
Chapter1 c programming data types, variables and constants
Chapter1 c programming   data types, variables and constantsChapter1 c programming   data types, variables and constants
Chapter1 c programming data types, variables and constants
 
C presentation book
C presentation bookC presentation book
C presentation book
 
Lexical analysis - Compiler Design
Lexical analysis - Compiler DesignLexical analysis - Compiler Design
Lexical analysis - Compiler Design
 
Report on c and c++
Report on c and c++Report on c and c++
Report on c and c++
 
Normalization
NormalizationNormalization
Normalization
 

Similar to ITU - MDD - Textural Languages and Grammars

Convention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsRay Toal
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
Vaclav Pech
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesEelco Visser
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
appasami
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Robert Pickering
 
groovy DSLs from beginner to expert
groovy DSLs from beginner to expertgroovy DSLs from beginner to expert
groovy DSLs from beginner to expert
Paul King
 
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
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
Talentica Software
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
Akshaya Arunan
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash Course
Will Iverson
 
DSL explained _
DSL explained _DSL explained _
DSL explained _
Dmitry Kandalov
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaDmitry Buzdin
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
MashaelQ
 
BUILDING BASIC STRECH SQL COMPILER
BUILDING BASIC STRECH SQL COMPILERBUILDING BASIC STRECH SQL COMPILER
BUILDING BASIC STRECH SQL COMPILER
Ajeet Dubey
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
IndicThreads
 
Internationalisation And Globalisation
Internationalisation And GlobalisationInternationalisation And Globalisation
Internationalisation And Globalisation
Alan Dean
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Bilal Amjad
 

Similar to ITU - MDD - Textural Languages and Grammars (20)

Convention-Based Syntactic Descriptions
Convention-Based Syntactic DescriptionsConvention-Based Syntactic Descriptions
Convention-Based Syntactic Descriptions
 
Concepts of JetBrains MPS
Concepts of JetBrains MPSConcepts of JetBrains MPS
Concepts of JetBrains MPS
 
TI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific LanguagesTI1220 Lecture 14: Domain-Specific Languages
TI1220 Lecture 14: Domain-Specific Languages
 
python and perl
python and perlpython and perl
python and perl
 
Cs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer KeyCs6660 compiler design may june 2016 Answer Key
Cs6660 compiler design may june 2016 Answer Key
 
Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#Combinators, DSLs, HTML and F#
Combinators, DSLs, HTML and F#
 
groovy DSLs from beginner to expert
groovy DSLs from beginner to expertgroovy DSLs from beginner to expert
groovy DSLs from beginner to expert
 
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)
 
PDF Localization
PDF  LocalizationPDF  Localization
PDF Localization
 
Building scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thriftBuilding scalable and language independent java services using apache thrift
Building scalable and language independent java services using apache thrift
 
Compilers Design
Compilers DesignCompilers Design
Compilers Design
 
Software Internationalization Crash Course
Software Internationalization Crash CourseSoftware Internationalization Crash Course
Software Internationalization Crash Course
 
DSL explained _
DSL explained _DSL explained _
DSL explained _
 
AestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in ScalaAestasIT - Internal DSLs in Scala
AestasIT - Internal DSLs in Scala
 
Interm codegen
Interm codegenInterm codegen
Interm codegen
 
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex ToolCompiler Engineering Lab#5 : Symbol Table, Flex Tool
Compiler Engineering Lab#5 : Symbol Table, Flex Tool
 
BUILDING BASIC STRECH SQL COMPILER
BUILDING BASIC STRECH SQL COMPILERBUILDING BASIC STRECH SQL COMPILER
BUILDING BASIC STRECH SQL COMPILER
 
Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...Building scalable and language-independent Java services using Apache Thrift ...
Building scalable and language-independent Java services using Apache Thrift ...
 
Internationalisation And Globalisation
Internationalisation And GlobalisationInternationalisation And Globalisation
Internationalisation And Globalisation
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 4 (Introduction ...
 

More from Tonny Madsen

L0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard ViewsL0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard Views
Tonny Madsen
 
L0037 - Basic Eclipse Configuration
L0037 - Basic Eclipse ConfigurationL0037 - Basic Eclipse Configuration
L0037 - Basic Eclipse Configuration
Tonny Madsen
 
L0036 - Creating Views and Editors
L0036 - Creating Views and EditorsL0036 - Creating Views and Editors
L0036 - Creating Views and Editors
Tonny Madsen
 
L0033 - JFace
L0033 - JFaceL0033 - JFace
L0033 - JFace
Tonny Madsen
 
L0020 - The Basic RCP Application
L0020 - The Basic RCP ApplicationL0020 - The Basic RCP Application
L0020 - The Basic RCP Application
Tonny Madsen
 
L0018 - SWT - The Standard Widget Toolkit
L0018 - SWT - The Standard Widget ToolkitL0018 - SWT - The Standard Widget Toolkit
L0018 - SWT - The Standard Widget Toolkit
Tonny Madsen
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
Tonny Madsen
 
L0001 - The Terminology of the Eclipse Platform
L0001 - The Terminology of the Eclipse PlatformL0001 - The Terminology of the Eclipse Platform
L0001 - The Terminology of the Eclipse Platform
Tonny Madsen
 
EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...
EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...
EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...
Tonny Madsen
 
PROSA - Eclipse Is Just What?
PROSA - Eclipse Is Just What?PROSA - Eclipse Is Just What?
PROSA - Eclipse Is Just What?
Tonny Madsen
 
Eclipse Demo Camp 2010 - Eclipse e4 – The Status and the Future
Eclipse Demo Camp 2010 - Eclipse e4 – The Status and the FutureEclipse Demo Camp 2010 - Eclipse e4 – The Status and the Future
Eclipse Demo Camp 2010 - Eclipse e4 – The Status and the Future
Tonny Madsen
 
Eclipse Demo Camp 2010 - UI Bindings - An Introduction
Eclipse Demo Camp 2010 - UI Bindings - An IntroductionEclipse Demo Camp 2010 - UI Bindings - An Introduction
Eclipse Demo Camp 2010 - UI Bindings - An Introduction
Tonny Madsen
 
ITU - MDD – Model-to-Model Transformations
ITU - MDD – Model-to-Model TransformationsITU - MDD – Model-to-Model Transformations
ITU - MDD – Model-to-Model Transformations
Tonny Madsen
 
IDA - Eclipse Workshop II (In Danish)
IDA - Eclipse Workshop II (In Danish)IDA - Eclipse Workshop II (In Danish)
IDA - Eclipse Workshop II (In Danish)
Tonny Madsen
 
IDA - Eclipse Workshop I (In Danish)
IDA - Eclipse Workshop I (In Danish)IDA - Eclipse Workshop I (In Danish)
IDA - Eclipse Workshop I (In Danish)
Tonny Madsen
 
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...
Tonny Madsen
 
ITU - MDD - EMF
ITU - MDD - EMFITU - MDD - EMF
ITU - MDD - EMF
Tonny Madsen
 
ITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-insITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-ins
Tonny Madsen
 
ITU - MDD - XText
ITU - MDD - XTextITU - MDD - XText
ITU - MDD - XText
Tonny Madsen
 
eclipse.dk - Eclipse RCP Under the Hood
eclipse.dk - Eclipse RCP Under the Hoodeclipse.dk - Eclipse RCP Under the Hood
eclipse.dk - Eclipse RCP Under the Hood
Tonny Madsen
 

More from Tonny Madsen (20)

L0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard ViewsL0043 - Interfacing to Eclipse Standard Views
L0043 - Interfacing to Eclipse Standard Views
 
L0037 - Basic Eclipse Configuration
L0037 - Basic Eclipse ConfigurationL0037 - Basic Eclipse Configuration
L0037 - Basic Eclipse Configuration
 
L0036 - Creating Views and Editors
L0036 - Creating Views and EditorsL0036 - Creating Views and Editors
L0036 - Creating Views and Editors
 
L0033 - JFace
L0033 - JFaceL0033 - JFace
L0033 - JFace
 
L0020 - The Basic RCP Application
L0020 - The Basic RCP ApplicationL0020 - The Basic RCP Application
L0020 - The Basic RCP Application
 
L0018 - SWT - The Standard Widget Toolkit
L0018 - SWT - The Standard Widget ToolkitL0018 - SWT - The Standard Widget Toolkit
L0018 - SWT - The Standard Widget Toolkit
 
L0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-inL0016 - The Structure of an Eclipse Plug-in
L0016 - The Structure of an Eclipse Plug-in
 
L0001 - The Terminology of the Eclipse Platform
L0001 - The Terminology of the Eclipse PlatformL0001 - The Terminology of the Eclipse Platform
L0001 - The Terminology of the Eclipse Platform
 
EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...
EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...
EclipseCon '11 - Using Adapters to Handle Menus and Handlers in Large Scale A...
 
PROSA - Eclipse Is Just What?
PROSA - Eclipse Is Just What?PROSA - Eclipse Is Just What?
PROSA - Eclipse Is Just What?
 
Eclipse Demo Camp 2010 - Eclipse e4 – The Status and the Future
Eclipse Demo Camp 2010 - Eclipse e4 – The Status and the FutureEclipse Demo Camp 2010 - Eclipse e4 – The Status and the Future
Eclipse Demo Camp 2010 - Eclipse e4 – The Status and the Future
 
Eclipse Demo Camp 2010 - UI Bindings - An Introduction
Eclipse Demo Camp 2010 - UI Bindings - An IntroductionEclipse Demo Camp 2010 - UI Bindings - An Introduction
Eclipse Demo Camp 2010 - UI Bindings - An Introduction
 
ITU - MDD – Model-to-Model Transformations
ITU - MDD – Model-to-Model TransformationsITU - MDD – Model-to-Model Transformations
ITU - MDD – Model-to-Model Transformations
 
IDA - Eclipse Workshop II (In Danish)
IDA - Eclipse Workshop II (In Danish)IDA - Eclipse Workshop II (In Danish)
IDA - Eclipse Workshop II (In Danish)
 
IDA - Eclipse Workshop I (In Danish)
IDA - Eclipse Workshop I (In Danish)IDA - Eclipse Workshop I (In Danish)
IDA - Eclipse Workshop I (In Danish)
 
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...
IDA - Fra forretningside til bundlinie: Eclipse følger dig hele vejen (In Dan...
 
ITU - MDD - EMF
ITU - MDD - EMFITU - MDD - EMF
ITU - MDD - EMF
 
ITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-insITU - MDD - Eclipse Plug-ins
ITU - MDD - Eclipse Plug-ins
 
ITU - MDD - XText
ITU - MDD - XTextITU - MDD - XText
ITU - MDD - XText
 
eclipse.dk - Eclipse RCP Under the Hood
eclipse.dk - Eclipse RCP Under the Hoodeclipse.dk - Eclipse RCP Under the Hood
eclipse.dk - Eclipse RCP Under the Hood
 

Recently uploaded

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
bennyroshan06
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
RaedMohamed3
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
kaushalkr1407
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
Fundacja Rozwoju Społeczeństwa Przedsiębiorczego
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
Col Mukteshwar Prasad
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
BhavyaRajput3
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
Delapenabediema
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
Excellence Foundation for South Sudan
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
Anna Sz.
 

Recently uploaded (20)

Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptxMARUTI SUZUKI- A Successful Joint Venture in India.pptx
MARUTI SUZUKI- A Successful Joint Venture in India.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
Palestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptxPalestine last event orientationfvgnh .pptx
Palestine last event orientationfvgnh .pptx
 
The Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdfThe Roman Empire A Historical Colossus.pdf
The Roman Empire A Historical Colossus.pdf
 
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdfESC Beyond Borders _From EU to You_ InfoPack general.pdf
ESC Beyond Borders _From EU to You_ InfoPack general.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
How to Break the cycle of negative Thoughts
How to Break the cycle of negative ThoughtsHow to Break the cycle of negative Thoughts
How to Break the cycle of negative Thoughts
 
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCECLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
CLASS 11 CBSE B.St Project AIDS TO TRADE - INSURANCE
 
The Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official PublicationThe Challenger.pdf DNHS Official Publication
The Challenger.pdf DNHS Official Publication
 
Introduction to Quality Improvement Essentials
Introduction to Quality Improvement EssentialsIntroduction to Quality Improvement Essentials
Introduction to Quality Improvement Essentials
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
Polish students' mobility in the Czech Republic
Polish students' mobility in the Czech RepublicPolish students' mobility in the Czech Republic
Polish students' mobility in the Czech Republic
 

ITU - MDD - Textural Languages and Grammars

  • 1. L0080 - 2010-11-02 Redistribution and other use of this material requires written permission from The RCP Company. ITU - MDD – Textural Languages and Grammars This presentation describes the use and design of textural domain specific language - DSL. It has two basic purposes: Introduce you to some of the more important design criteria in language design Introduce you to BNF This presentation is developed for MDD 2010 course at ITU, Denmark. Some materials are taken from Artur Boronat, University of Leicester with permissions.
  • 2. L0080 - 2010-11-02 2 Textual DSLs versus Graphical DSLs  With both textual and graphical syntax you can  model any meta model  verify constraints in real time  (Eclipse) write ordinary EMF models  Graphical Editors are good to show structural relationships  Graphical Editors are sexy and often appeals to management  Textual Editors are better for „algorithmic“ aspects, or hierarchical models  Textual Editors integrate better with CVS etc. (diff, merge)  Textual Editors often provides better support for quick assist and quick fixes  If you must work with a DSL many hours every day, consider textual DSLs over graphical DSLs!’
  • 3. L0080 - 2010-11-02 3 What is needed for a successful DSL  You must know  The intended audience  The expressiveness of the language  The extendibility of the language
  • 4. L0080 - 2010-11-02 4 The intended audience  Who will be using the language  Temporary help in a call center  Full-time Clerks  Accountants  Engineers – like yourselves  Any mismatch between the language and the audience is likely to alienate your audience  Keywords:  concise vs. redundant  intuitive  simple to write and read (host “heimdal” (ipif 192.167.54.55) (disk:type SSD 500GB)) Define host name = “heimdal” with IP interface IPv4 address = 192.167.54.55 end IP address with disk type = SSD size = 500GB end disk End host
  • 5. L0080 - 2010-11-02 5 The expressiveness of the language  What type of information must be expressed in the language:  Simple static information  Complex network of objects  Algorithms  Must the DSL be Turing complete?  What type of constructs must be supported  Lists  Tables  Recursive data structures  Variables  Macros  Conditions and loops  Functions  Comments E = MC2
  • 6. L0080 - 2010-11-02 6 The extendibility of the language  Can you be absolute certain that the language will never be extended?  “The last language…”  Backward compatibility  If your grammar is successful, then it will be used – so what should you do with all the existing “stuff” when you need to extend your grammar with new functionality  Open versus closed grammars  An open grammar can be extended in the future with new constructs or statements in a natural manner  A closed grammar can be very difficult to extend while retaining backward compatibility heimdal 192.167.54.55 SSD 500 (host “heimdal” (ipif 192.167.54.55) (disk type SSD 500GB))
  • 7. L0080 - 2010-11-02 7 Internal versus External DSLs  Textual DSLs are normally divided into two distinct groups:  Internal DSL (or extension language)  Using the syntax and semantics of a host language or system – e.g. Java or Excel  You can argument that any API is in itself an DSL  External DSL  A completely new language
  • 8. L0080 - 2010-11-02 8 Some Examples Internal DSL  4GL – attempt in the 1990s to raise the productivity of programmers by adding more high-level constructs to 3GL languages (such as C, Pascal, etc)  JSP – current attempt to ease the creation of web pages by adding Java as an embedded scripting language  Some languages that have been designed to be a good host language for DSL:  Tcl  Python  Groovy  Ruby final IFormCreator detailsSection = myForm.addSection("Details", table.getBinding().getSingleSelection()); detailsSection.addObjectMessages(); detailsSection.addField("contact.name(w=200)"); detailsSection.addField("logoFileName(w=200)"); detailsSection.addField("loyalty").arg(Constants.ARG_PREFERRED_CONTROL, RadioGroup.class.getName()); # Assume $remote_server, $my_user_id, $my_password, and $my_command # were read in earlier in the script. spawn telnet $remote_server expect "username:" send "$my_user_idr" expect "password:" send "$my_passwordr" expect "%" send "$my_commandr" expect "%" set results $expect_out(buffer) send "exitr" expect eof
  • 9. L0080 - 2010-11-02 9  Consists of two layers  a lexical layer  a grammar layer  Lexical syntax: the spelling of words and punctuation  Grammars: the key formalism for describing syntax; universal progra mming language Example  if (<expr>) <statement>  if <expr> then <statement>  <statement> if <expr>  (if <expr> <statement>) Formal Syntax of an DSL if expression statement != a constantvariable if (a != null) b = a.getArg(); “If” “(“ “a” “!=“ “null” “)” “b” “=“ “a” “.” “getArg” “(“ “)” “;” assignment a expression null … …
  • 10. L0080 - 2010-11-02 10  Tokens/Terminals: units in programming language  Lexical syntax: correspondence between the written representation (spelling) and the tokens or terminals in a grammar  Keywords:  alphabetic character sequences  unit in a language - if , while  Punctuation  Like ‘(‘, ‘)’, ‘:=‘  Whitespace Lexical Syntax if (a != null) b = a.getArg(); “If” “(“ “a” “!=“ “null” “)” “b” “=“ “a” “.” “getArg” “(“ “)” “;”
  • 11. L0080 - 2010-11-02 11  Concrete syntax: describes its written representation, including lexical details such as the placement of keywords and punctuation marks  Context-free grammar or grammars: notation for specifying concrete syntax  Context-free means that the understanding of the next token may not depend on the current context  Example from PL/1 of a context dependent grammar:  IF IF THEN THEN ELSE ELSE;  Legal if “IF” is a Boolean variable and “THEN” and “ELSE” are valid procedures  Most modern languages have a context-free grammar  Notable exceptions are C and C++!!! Context-Free Grammars
  • 12. L0080 - 2010-11-02 12  Grammar has four parts  A set of tokens or terminals  atomic symbols that can not be sub-divided  A set of nonterminals  Identifiers or variables representing constructs  A set of rules (called productions)  identify the component of construct  <nonterminal >::= terminal | <nonterminal>  A starting nonterminal  represents a main construct Describing Context-Free Grammars assignment => ID = expression; expression => expression + term | expression - term | term term => term * factor | term / factor | factor factor => ( expression ) | ID | NUMBER
  • 13. L0080 - 2010-11-02 13  The productions are rules for building strings  Parse Trees: show how a string can be built Notation to write grammar  Backus-Naur Form (BNF)  Extended BNF (EBNF) Writing Grammars
  • 14. L0080 - 2010-11-02 14 Backus-Naur Form (Backus Normal Form)  Grammar Rules or Productions: define symbols.  Non-terminal Symbols: anything that is defined on the left-side of some production.  Terminal Symbols: things that are not defined by productions. They can be literals, symbols, and other lexemes of the language defined by lexical rules.  Identifiers: id::= [A-Za-z_]*  Delimiters: ;  Operators: = + - * / % assignment_stmt ::= id = expression; The non-terminal symbol being defined. The definition (production)
  • 15. L0080 - 2010-11-02 15  Different notations (same meaning):  assignment_stmt ::= id = expression + term  <assignment-stmt> => <id> = <expr> + <term>  AssignmentStmt → id = expression + term ::=, =>, → mean "consists of" or "defined as"  Alternatives ( " | " ):  Concatenation: Backus-Naur Form (Backus Normal Form) expression => expression + term | expression - term | term number => DIGIT number | DIGIT
  • 16. L0080 - 2010-11-02 16 Backus-Naur Form (Backus Normal Form)  Another way to write alternatives:  Null symbol,: ε or @ used to allow a production to match nothing.  Example: a variable is an identifier followed by an optional subscript Expression => expression + term => expression - term => term variable => identifier subscript subscript => [ expression ] | e
  • 17. L0080 - 2010-11-02 17  Here is a grammar for assignment with arithmetic operations, e.g. y = (2*x + 5)*x - 7; Arithmetic Grammar assignment => ID = expression; expression => expression + term | expression - term | term term => term * factor | term / factor | factor factor => ( expression ) | ID | NUMBER
  • 18. L0080 - 2010-11-02 18 Example of a Parse Tree if expression statement != a constantvariable “If” “(“ “a” “!=“ “null” “)” “b” “=“ “a” “.” “getArg” “(“ “)” “;” assignment a expression null … …
  • 19. L0080 - 2010-11-02 19  Grammar Rules: expr => expr + expr | expr ∗ expr | ( expr ) | NUMBER  Expression: 2 + 3 * 4  Two possible parse trees: expr expr expr expr + *expr expr expr + *expr exprexprNUMBER (2) NUMBER (3) NUMBER (4) NUMBER (2) NUMBER (3) NUMBER (4) Ambiguity
  • 20. L0080 - 2010-11-02 20  The standard metalanguage: Extended BNF  Terminal symbols of the language are quoted  [ and ] include optional symbols  { and } indicate repetition  ( and ) are used to group items  | definition-separator-symbol stands for or. In EBNF we need to quote ( and ) literals as '(' ... ')’  * repetition symbol  = defining symbol  ; terminator symbol EBNF – Extended BNF
  • 21. L0080 - 2010-11-02 21 BNF versus EBNF BNF: EBNF: expression ::= expression + term | expression - term | term term ::= term * factor | term / factor | factor factor ::= ( expression ) | id | number expression ::= term { (‘+’|’-’) term } term ::= factor { (‘*’|’/’) factor } factor ::= '(' expression ')' | id | number
  • 22. L0080 - 2010-11-02 22 More Information  “Model-Driven Software Development” by Thomas Stahl and Markus Völter  Chapter 8.1 “DSL Construction”  Good high-level introduction to DSLs  “Domain-Specific Languages: An Annotated Bibliography”  http://homepages.cwi.nl/~arie/papers/dslbib/  Not very interesting except for the very long annotated bibliography!  “BNF and EBNF: What are they and how do they work?” by Lars Marius Garshol - http://www.garshol.priv.no/download/text/bnf.html  About Backus-Naur Form and parsing  “Internal Domain-Specific Languages”  http://fragmental.tw/research-on-dsls/domain-specific-languages-dsls/internal-dsls/  Outlines use of DSL in Java and Ruby
  • 23. L0080 - 2010-11-02 23 Exercise 1  Design a textual language (grammar) for a travel package.  How would you like to specify a travel package in text?  Do you think, you can teach a travel administrator to use the language?  Is the grammar open – i.e. can it be extended in the future?  For the grammar you can use ID, STRING and NUMBER as terminators where relevant