SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
Domain-specific language features1
Ted Kaminksi and Eric Van Wyk
University of Minnesota
Global DSL 2013, July 2, 2013, Montpellier
1
This work is partially supported by NSF Awards No. 0905581 and
1047961.
c Eric Van Wyk 1
DSLs are bad, or at least have some challenges...
External
“No recourse to the law.”
domain-specific syntax, analysis, and optimization
Internal/Embedded
“just libraries”, caveat: staging, Delite
composable
general purpose host language available
Maybe there are alternatives ...
c Eric Van Wyk 2
Extensible Languages (Frameworks)
pluggable domain-specific language extensions
domain-specific syntax, analysis, and optimization
composable
general purpose host language available
extension features translate down to host language
c Eric Van Wyk 3
class Demo {
int demoMethod ( ) {
List<List<Integer>> dlist ;
Regex ws = regex/nt / ;
int SELECT ;
connection c "jdbc:derby:/home/derby/db/testdb"
with table person [ person id INTEGER,
first name VARCHAR,
last name VARCHAR ] ,
table details [ person id INTEGER,
age INTEGER ] ;
Integer limit = 18 ;
ResultSet rs = using c query {
SELECT age, gender, last name
FROM person , details
WHERE person.person id = details.person id
AND details.age > limit } ;
Integer = rs.getInteger("age");
String gender = rs.getString("gender");
boolean b ;
b = table ( age > 40 : T * ,
gender == "M" : T F ) ;
}
}
• natural syntax
• semantic analysis
• composable extensions
• Regexs, different whitespace
• SQL queries
• non-null pointer
analysis
• tabular boolean
expressions
c Eric Van Wyk 4
#include <sdtio.h>
int main() {
... bits of SAC ...
... stencil specifications ...
... computational geometry optimizations
robustness transformations ...
}
c Eric Van Wyk 5
Roles people play ...
1. host language designer
2. language extension designer
3. programmer
language extension user
has no language design and implementation knowledge
c Eric Van Wyk 6
c Eric Van Wyk 7
An analog
We can write type safe programs in assembly, Python,
Ruby, Scheme, etc.
We are guaranteed to write type safe program in Haskell,
ML, etc.
Some of use (happily) trade some expressibility for this
safety.
Can we build extensible languages and composable
language extensions?
Are there any guarantees of composability of language
extensions?
c Eric Van Wyk 8
c Eric Van Wyk 9
Developing language extensions
Two primary challenges:
1. composable syntax — enables building a parser
context-aware scanning [GPCE’07]
modular determinism analysis [PLDI’09]
Copper
2. composable semantics — analysis and translations
attribute grammars with forwarding, collections and
higher-order attributes
set union of specification components
sets of productions, non-terminals, attributes
sets of attribute defining equations, on a production
sets of equations contributing values to a single attribute
modular well-definedness analysis [SLE’12a]
modular termination analysis [SLE’12b, KrishnanPhD]
Silver
c Eric Van Wyk 10
Challenges in scanning
Keywords in embedded languages may be identifiers in
host language:
int SELECT ;
...
rs = using c query { SELECT last name
FROM person WHERE ...
Different extensions use same keyword
connection c "jdbc:derby:./derby/db/testdb"
with table person [ person id INTEGER,
first name VARCHAR ];
...
b = table ( c1 : T F ,
c2 : F * ) ;
c Eric Van Wyk 11
Challenges in scanning
Operators with different precedence specifications:
x = 3 + y * z ;
...
str = /[a-z][a-z0-9]*.java/
Terminals that are prefixes of others
List<List<Integer>> dlist ;
...
x = y >> 4 ;
or
aspect ... before ... call( o.get*() )
...
x = get*3 ;
[from Bravenboer, Tanter & Visser’s OOPSLA 06 paper on parsing AspectJ]
c Eric Van Wyk 12
Need for context
Problem: the scanner cannot match strings (lexemes) to
proper terminal symbols in the grammar.
“SELECT” – Select kwd or Identifier
“table” – SQL table kwd or DNF table kwd
“>>” – RightBitShift op or GT op, GT op
Neither terminal has global precedence over the other.
maximal munch gives “>>” precedence over “>”
thus grammars are written to accommodate this
c Eric Van Wyk 13
Need for context
Traditionally, parser and scanner are disjoint.
Scanner → Parser → Semantic Analysis
In context aware scanning, they communicate
Scanner Parser → Semantic Analysis
c Eric Van Wyk 14
Context aware scanning
Scanner recognizes only tokens valid for current “context”
keeps embedded sub-languages, in a sense, separate
Consider:
chan in, out;
for i in a { a[i] = i*i ; }
Two terminal symbols that match “in”.
terminal IN ’in’ ;
terminal ID /[a-zA-Z ][a-zA-Z 0-9]*/
submits to {promela kwd };
terminal FOR ’for’ lexer classes {promela kwd
};
example is part of AbleP [SPIN’11]
c Eric Van Wyk 15
Allows parsing of embedded C code in host
Promela
c_decl {
typedef struct Coord {
int x, y; } Coord; }
c_state "Coord pt" "Global" /* goes in state vector */
int z = 3; /* standard global decl */
active proctype example()
{ c_code { now.pt.x = now.pt.y = 0; };
do :: c_expr { now.pt.x == now.pt.y }
-> c_code { now.pt.y++; }
:: else -> break
od;
c_code { printf("values %d: %d, %d,%dn",c Eric Van Wyk 16
Context aware scanning
We use a slightly modified LR parser and a context-aware
scanner.
Context is based on the LR-parser state.
Parser passes a set of valid look-ahead terminals to
scanner.
This is the set of terminals with shift, reduce, or accept
entries in parse table for current parse state.
Scanner only returns tokens from the valid look-ahead set.
Scanner uses this set to disambiguate terminals.
e.g. SQL table kwd and DNF table kwd
e.g. Select kwd and Identifier
c Eric Van Wyk 17
Context aware scanning
This scanning algorithm subordinates the
disambiguation principle of maximal munch
to the principle of
disambiguation by context.
It will return a shorter valid match before a longer invalid
match.
In List<List<Integer>> before “>”,
“>” in valid lookahead but “>>” is not.
A context aware scanner is essentially an implicitly-moded
scanner.
There is no explicit specification of valid look ahead.
It is generated from standard grammars and terminal
regexs.
c Eric Van Wyk 18
With a smarter scanner, LALR(1) is not so brittle.
We can build syntactically composable language
extensions.
Context aware scanning makes composable syntax “more
likely”
But it does not give a guarantee of composability.
c Eric Van Wyk 19
Building a parser from composed specifications.
... CFGH
∪∗
{CFGE1
, ..., CFGEn
}
∀i ∈ [1, n].isComposable(CFGH
, CFGEi
)∧
conflictFree(CFGH
∪ CFGEi
)
⇒ ⇒ conflictFree(CFGH
∪ {CFGE1
, ..., CFGEn
})
Monolithic analysis - not too hard, but not too useful.
Modular analysis - harder, but required [PLDI’09].
Non-commutative composition of restricted LALR(1)
grammars.
c Eric Van Wyk 20
Building an attribute grammar evaluator from composed
specifications.
... AGH
∪∗
{AGE1
, ..., AGEn
}
∀i ∈ [1, n].modComplete(AGH
, AGEi
)
⇒ ⇒ complete(AGH
∪ {AGE
1 , ..., AGE
n })
Monolithic analysis - not too hard, but not too useful.
Modular analysis - harder, but required [SLE’12a].
c Eric Van Wyk 21
c Eric Van Wyk 22
Modular
determinism analysis — scanning, parsing
well-definedness — attribute grammars
termination — attribute grammars
are language independent analyses.
Next: language specific analyses.
Sebastian Erweg at ICFP’13 - modular type soundness
c Eric Van Wyk 23
Expressiveness versus safe composition
Compare to
other parser generators
libraries
The modular compositionality analysis does not require
context aware scanning.
But, context aware scanning makes it practical.
c Eric Van Wyk 24
Tool Support
Copper – context-aware parser and scanner generator
implements context-aware scanning for a LALR(1) parser
lexical precedence
parser attributes and disambiguation functions when
disambiguation by context and lexical precedence is not
enough
currently integrated into Silver [SCP’10], an extensible
attribute grammar system.
c Eric Van Wyk 25
Thanks for your attention.
Questions?
http://melt.cs.umn.edu
evw@cs.umn.edu
c Eric Van Wyk 26
Ted Kaminski and Eric Van Wyk.
Modular well-definedness analysis for attribute grammars.
In Proc. of Intl. Conf. on Software Language Engineering
(SLE), volume 7745 of LNCS, pages 352–371.
Springer-Verlag, September 2012.
Lijesh Krishnan and Eric Van Wyk.
Termination analysis for higher-order attribute grammars.
In Proceedings of the 5th International Conference on
Software Language Engineering (SLE 2012), volume 7745
of LNCS, pages 44–63. Springer-Verlag, September 2012.
Lijesh Krishnan.
Composable Semantics Using Higher-Order Attribute
Grammars.
PhD thesis, University of Minnesota, Minnesota, USA,
2012.
http://melt.cs.umn.edu/pubs/krishnan2012PhD/.
c Eric Van Wyk 26
Yogesh Mali and Eric Van Wyk.
Building extensible specifications and implementations of
promela with AbleP.
In Proc. of Intl. SPIN Workshop on Model Checking of
Software, volume 6823 of LNCS, pages 108–125.
Springer-Verlag, July 2011.
August Schwerdfeger and Eric Van Wyk.
Verifiable composition of deterministic grammars.
In Proc. of Conf. on Programming Language Design and
Implementation (PLDI), pages 199–210. ACM, June 2009.
A. Schwerdfeger and E. Van Wyk.
Verifiable parse table composition for deterministic
parsing.
In 2nd International Conference on Software Language
Engineering, volume 5969 of LNCS, pages 184–203.
Springer-Verlag, 2010.
c Eric Van Wyk 26
E. Van Wyk, O. de Moor, K. Backhouse, and
P. Kwiatkowski.
Forwarding in attribute grammars for modular language
design.
In 11th Conf. on Compiler Construction (CC), volume
2304 of LNCS, pages 128–142. Springer-Verlag, 2002.
Eric Van Wyk, Lijesh Krishnan, August Schwerdfeger, and
Derek Bodin.
Attribute grammar-based language extensions for Java.
In Proc. of European Conf. on Object Oriented Prog.
(ECOOP), volume 4609 of LNCS, pages 575–599.
Springer-Verlag, 2007.
E. Van Wyk and A. Schwerdfeger.
Context-aware scanning for parsing extensible languages.
In Intl. Conf. on Generative Programming and Component
Engineering, (GPCE). ACM Press, October 2007.
c Eric Van Wyk 26
Eric Van Wyk, Derek Bodin, Jimin Gao, and Lijesh
Krishnan.
Silver: an extensible attribute grammar system.
Science of Computer Programming, 75(1–2):39–54,
January 2010.
c Eric Van Wyk 26

Más contenido relacionado

La actualidad más candente

Domain Specific Language Design
Domain Specific Language DesignDomain Specific Language Design
Domain Specific Language Design
Markus Voelter
 
Guidance, Please! Towards a Framework for RDF-based Constraint Languages.
Guidance, Please! Towards a Framework for RDF-based Constraint Languages.Guidance, Please! Towards a Framework for RDF-based Constraint Languages.
Guidance, Please! Towards a Framework for RDF-based Constraint Languages.
Kai Eckert
 
Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-
Krishna Sai
 

La actualidad más candente (19)

Introduction to programming using c
Introduction to programming using cIntroduction to programming using c
Introduction to programming using c
 
Introduction to c_sharp
Introduction to c_sharpIntroduction to c_sharp
Introduction to c_sharp
 
thrift-20070401
thrift-20070401thrift-20070401
thrift-20070401
 
Introduction to VHDL
Introduction to VHDLIntroduction to VHDL
Introduction to VHDL
 
C Language
C LanguageC Language
C Language
 
Vb.net
Vb.netVb.net
Vb.net
 
Lecture2 vhdl refresher
Lecture2 vhdl refresherLecture2 vhdl refresher
Lecture2 vhdl refresher
 
C Course Material0209
C Course Material0209C Course Material0209
C Course Material0209
 
New c sharp4_features_part_iv
New c sharp4_features_part_ivNew c sharp4_features_part_iv
New c sharp4_features_part_iv
 
Expressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In JavaExpressive And Modular Predicate Dispatch In Java
Expressive And Modular Predicate Dispatch In Java
 
Microsoft .NET Platform
Microsoft .NET PlatformMicrosoft .NET Platform
Microsoft .NET Platform
 
Inside.Net
Inside.NetInside.Net
Inside.Net
 
Domain Specific Language Design
Domain Specific Language DesignDomain Specific Language Design
Domain Specific Language Design
 
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGESOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
SOFTWARE TOOL FOR TRANSLATING PSEUDOCODE TO A PROGRAMMING LANGUAGE
 
Guidance, Please! Towards a Framework for RDF-based Constraint Languages.
Guidance, Please! Towards a Framework for RDF-based Constraint Languages.Guidance, Please! Towards a Framework for RDF-based Constraint Languages.
Guidance, Please! Towards a Framework for RDF-based Constraint Languages.
 
Advanced Java Topics
Advanced Java TopicsAdvanced Java Topics
Advanced Java Topics
 
Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-Principles of-programming-languages-lecture-notes-
Principles of-programming-languages-lecture-notes-
 
Programming Languages
Programming LanguagesProgramming Languages
Programming Languages
 
Programing paradigm &amp; implementation
Programing paradigm &amp; implementationPrograming paradigm &amp; implementation
Programing paradigm &amp; implementation
 

Destacado

Sea Level Rise
Sea Level RiseSea Level Rise
Sea Level Rise
tudorgeog
 
06_CI4_SOLID SURFACE_Nora Lardiés
06_CI4_SOLID SURFACE_Nora Lardiés06_CI4_SOLID SURFACE_Nora Lardiés
06_CI4_SOLID SURFACE_Nora Lardiés
Redit
 
Automatic Generation of Peephole Superoptimizers
Automatic Generation of Peephole SuperoptimizersAutomatic Generation of Peephole Superoptimizers
Automatic Generation of Peephole Superoptimizers
keanumit
 
6. global warming
6. global warming6. global warming
6. global warming
giri reddy
 

Destacado (17)

Ind eng-428-ppt
Ind eng-428-pptInd eng-428-ppt
Ind eng-428-ppt
 
Us Nero Giardini
Us Nero GiardiniUs Nero Giardini
Us Nero Giardini
 
Mi biografía
Mi biografía Mi biografía
Mi biografía
 
Sea Level Rise
Sea Level RiseSea Level Rise
Sea Level Rise
 
TW-01 WPC floor
TW-01 WPC floorTW-01 WPC floor
TW-01 WPC floor
 
Chiesa viva 457 f
Chiesa viva 457 fChiesa viva 457 f
Chiesa viva 457 f
 
Olumide pidan c
Olumide pidan cOlumide pidan c
Olumide pidan c
 
Ary inter madit
Ary inter maditAry inter madit
Ary inter madit
 
06_CI4_SOLID SURFACE_Nora Lardiés
06_CI4_SOLID SURFACE_Nora Lardiés06_CI4_SOLID SURFACE_Nora Lardiés
06_CI4_SOLID SURFACE_Nora Lardiés
 
Amrapali Group
Amrapali GroupAmrapali Group
Amrapali Group
 
Parsing example
Parsing exampleParsing example
Parsing example
 
Automatic Generation of Peephole Superoptimizers
Automatic Generation of Peephole SuperoptimizersAutomatic Generation of Peephole Superoptimizers
Automatic Generation of Peephole Superoptimizers
 
COOWIN WALL CLADDING
COOWIN WALL CLADDING COOWIN WALL CLADDING
COOWIN WALL CLADDING
 
FINGERPRINTS IMAGE COMPRESSION BY WAVE ATOMS
FINGERPRINTS IMAGE COMPRESSION BY WAVE ATOMSFINGERPRINTS IMAGE COMPRESSION BY WAVE ATOMS
FINGERPRINTS IMAGE COMPRESSION BY WAVE ATOMS
 
W.A.H.C 2014 The Future of Water Testing is Digital
W.A.H.C 2014 The Future of Water Testing is DigitalW.A.H.C 2014 The Future of Water Testing is Digital
W.A.H.C 2014 The Future of Water Testing is Digital
 
6. global warming
6. global warming6. global warming
6. global warming
 
m blocks self assembling robots
m blocks self assembling robotsm blocks self assembling robots
m blocks self assembling robots
 

Similar a Global DSL workshop slides

Scaling Language Specifications
Scaling Language SpecificationsScaling Language Specifications
Scaling Language Specifications
ericupnorth
 
2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf
cifoxo
 
Minko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSLMinko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSL
Minko3D
 

Similar a Global DSL workshop slides (20)

Scaling Language Specifications
Scaling Language SpecificationsScaling Language Specifications
Scaling Language Specifications
 
Lecture 1 introduction to language processors
Lecture 1  introduction to language processorsLecture 1  introduction to language processors
Lecture 1 introduction to language processors
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
Domain specific languages and Scala
Domain specific languages and ScalaDomain specific languages and Scala
Domain specific languages and Scala
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Crystal internals (part 1)
Crystal internals (part 1)Crystal internals (part 1)
Crystal internals (part 1)
 
Re-implementing Thrift using MDE
Re-implementing Thrift using MDERe-implementing Thrift using MDE
Re-implementing Thrift using MDE
 
7068458.ppt
7068458.ppt7068458.ppt
7068458.ppt
 
Compiler presentaion
Compiler presentaionCompiler presentaion
Compiler presentaion
 
1 cc
1 cc1 cc
1 cc
 
(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
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009
 
Compiler_Lecture1.pdf
Compiler_Lecture1.pdfCompiler_Lecture1.pdf
Compiler_Lecture1.pdf
 
2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf2023-02-22_Tiberti_CyberX.pdf
2023-02-22_Tiberti_CyberX.pdf
 
All experiment of java
All experiment of javaAll experiment of java
All experiment of java
 
Preparing for Scala 3
Preparing for Scala 3Preparing for Scala 3
Preparing for Scala 3
 
Minko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSLMinko - Targeting Flash/Stage3D with C++ and GLSL
Minko - Targeting Flash/Stage3D with C++ and GLSL
 
Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?Compiler Construction | Lecture 1 | What is a compiler?
Compiler Construction | Lecture 1 | What is a compiler?
 
Reverse-Engineering Reusable Language Modules from Legacy DSLs
Reverse-Engineering Reusable Language Modules from Legacy DSLsReverse-Engineering Reusable Language Modules from Legacy DSLs
Reverse-Engineering Reusable Language Modules from Legacy DSLs
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 

Global DSL workshop slides

  • 1. Domain-specific language features1 Ted Kaminksi and Eric Van Wyk University of Minnesota Global DSL 2013, July 2, 2013, Montpellier 1 This work is partially supported by NSF Awards No. 0905581 and 1047961. c Eric Van Wyk 1
  • 2. DSLs are bad, or at least have some challenges... External “No recourse to the law.” domain-specific syntax, analysis, and optimization Internal/Embedded “just libraries”, caveat: staging, Delite composable general purpose host language available Maybe there are alternatives ... c Eric Van Wyk 2
  • 3. Extensible Languages (Frameworks) pluggable domain-specific language extensions domain-specific syntax, analysis, and optimization composable general purpose host language available extension features translate down to host language c Eric Van Wyk 3
  • 4. class Demo { int demoMethod ( ) { List<List<Integer>> dlist ; Regex ws = regex/nt / ; int SELECT ; connection c "jdbc:derby:/home/derby/db/testdb" with table person [ person id INTEGER, first name VARCHAR, last name VARCHAR ] , table details [ person id INTEGER, age INTEGER ] ; Integer limit = 18 ; ResultSet rs = using c query { SELECT age, gender, last name FROM person , details WHERE person.person id = details.person id AND details.age > limit } ; Integer = rs.getInteger("age"); String gender = rs.getString("gender"); boolean b ; b = table ( age > 40 : T * , gender == "M" : T F ) ; } } • natural syntax • semantic analysis • composable extensions • Regexs, different whitespace • SQL queries • non-null pointer analysis • tabular boolean expressions c Eric Van Wyk 4
  • 5. #include <sdtio.h> int main() { ... bits of SAC ... ... stencil specifications ... ... computational geometry optimizations robustness transformations ... } c Eric Van Wyk 5
  • 6. Roles people play ... 1. host language designer 2. language extension designer 3. programmer language extension user has no language design and implementation knowledge c Eric Van Wyk 6
  • 7. c Eric Van Wyk 7
  • 8. An analog We can write type safe programs in assembly, Python, Ruby, Scheme, etc. We are guaranteed to write type safe program in Haskell, ML, etc. Some of use (happily) trade some expressibility for this safety. Can we build extensible languages and composable language extensions? Are there any guarantees of composability of language extensions? c Eric Van Wyk 8
  • 9. c Eric Van Wyk 9
  • 10. Developing language extensions Two primary challenges: 1. composable syntax — enables building a parser context-aware scanning [GPCE’07] modular determinism analysis [PLDI’09] Copper 2. composable semantics — analysis and translations attribute grammars with forwarding, collections and higher-order attributes set union of specification components sets of productions, non-terminals, attributes sets of attribute defining equations, on a production sets of equations contributing values to a single attribute modular well-definedness analysis [SLE’12a] modular termination analysis [SLE’12b, KrishnanPhD] Silver c Eric Van Wyk 10
  • 11. Challenges in scanning Keywords in embedded languages may be identifiers in host language: int SELECT ; ... rs = using c query { SELECT last name FROM person WHERE ... Different extensions use same keyword connection c "jdbc:derby:./derby/db/testdb" with table person [ person id INTEGER, first name VARCHAR ]; ... b = table ( c1 : T F , c2 : F * ) ; c Eric Van Wyk 11
  • 12. Challenges in scanning Operators with different precedence specifications: x = 3 + y * z ; ... str = /[a-z][a-z0-9]*.java/ Terminals that are prefixes of others List<List<Integer>> dlist ; ... x = y >> 4 ; or aspect ... before ... call( o.get*() ) ... x = get*3 ; [from Bravenboer, Tanter & Visser’s OOPSLA 06 paper on parsing AspectJ] c Eric Van Wyk 12
  • 13. Need for context Problem: the scanner cannot match strings (lexemes) to proper terminal symbols in the grammar. “SELECT” – Select kwd or Identifier “table” – SQL table kwd or DNF table kwd “>>” – RightBitShift op or GT op, GT op Neither terminal has global precedence over the other. maximal munch gives “>>” precedence over “>” thus grammars are written to accommodate this c Eric Van Wyk 13
  • 14. Need for context Traditionally, parser and scanner are disjoint. Scanner → Parser → Semantic Analysis In context aware scanning, they communicate Scanner Parser → Semantic Analysis c Eric Van Wyk 14
  • 15. Context aware scanning Scanner recognizes only tokens valid for current “context” keeps embedded sub-languages, in a sense, separate Consider: chan in, out; for i in a { a[i] = i*i ; } Two terminal symbols that match “in”. terminal IN ’in’ ; terminal ID /[a-zA-Z ][a-zA-Z 0-9]*/ submits to {promela kwd }; terminal FOR ’for’ lexer classes {promela kwd }; example is part of AbleP [SPIN’11] c Eric Van Wyk 15
  • 16. Allows parsing of embedded C code in host Promela c_decl { typedef struct Coord { int x, y; } Coord; } c_state "Coord pt" "Global" /* goes in state vector */ int z = 3; /* standard global decl */ active proctype example() { c_code { now.pt.x = now.pt.y = 0; }; do :: c_expr { now.pt.x == now.pt.y } -> c_code { now.pt.y++; } :: else -> break od; c_code { printf("values %d: %d, %d,%dn",c Eric Van Wyk 16
  • 17. Context aware scanning We use a slightly modified LR parser and a context-aware scanner. Context is based on the LR-parser state. Parser passes a set of valid look-ahead terminals to scanner. This is the set of terminals with shift, reduce, or accept entries in parse table for current parse state. Scanner only returns tokens from the valid look-ahead set. Scanner uses this set to disambiguate terminals. e.g. SQL table kwd and DNF table kwd e.g. Select kwd and Identifier c Eric Van Wyk 17
  • 18. Context aware scanning This scanning algorithm subordinates the disambiguation principle of maximal munch to the principle of disambiguation by context. It will return a shorter valid match before a longer invalid match. In List<List<Integer>> before “>”, “>” in valid lookahead but “>>” is not. A context aware scanner is essentially an implicitly-moded scanner. There is no explicit specification of valid look ahead. It is generated from standard grammars and terminal regexs. c Eric Van Wyk 18
  • 19. With a smarter scanner, LALR(1) is not so brittle. We can build syntactically composable language extensions. Context aware scanning makes composable syntax “more likely” But it does not give a guarantee of composability. c Eric Van Wyk 19
  • 20. Building a parser from composed specifications. ... CFGH ∪∗ {CFGE1 , ..., CFGEn } ∀i ∈ [1, n].isComposable(CFGH , CFGEi )∧ conflictFree(CFGH ∪ CFGEi ) ⇒ ⇒ conflictFree(CFGH ∪ {CFGE1 , ..., CFGEn }) Monolithic analysis - not too hard, but not too useful. Modular analysis - harder, but required [PLDI’09]. Non-commutative composition of restricted LALR(1) grammars. c Eric Van Wyk 20
  • 21. Building an attribute grammar evaluator from composed specifications. ... AGH ∪∗ {AGE1 , ..., AGEn } ∀i ∈ [1, n].modComplete(AGH , AGEi ) ⇒ ⇒ complete(AGH ∪ {AGE 1 , ..., AGE n }) Monolithic analysis - not too hard, but not too useful. Modular analysis - harder, but required [SLE’12a]. c Eric Van Wyk 21
  • 22. c Eric Van Wyk 22
  • 23. Modular determinism analysis — scanning, parsing well-definedness — attribute grammars termination — attribute grammars are language independent analyses. Next: language specific analyses. Sebastian Erweg at ICFP’13 - modular type soundness c Eric Van Wyk 23
  • 24. Expressiveness versus safe composition Compare to other parser generators libraries The modular compositionality analysis does not require context aware scanning. But, context aware scanning makes it practical. c Eric Van Wyk 24
  • 25. Tool Support Copper – context-aware parser and scanner generator implements context-aware scanning for a LALR(1) parser lexical precedence parser attributes and disambiguation functions when disambiguation by context and lexical precedence is not enough currently integrated into Silver [SCP’10], an extensible attribute grammar system. c Eric Van Wyk 25
  • 26. Thanks for your attention. Questions? http://melt.cs.umn.edu evw@cs.umn.edu c Eric Van Wyk 26
  • 27. Ted Kaminski and Eric Van Wyk. Modular well-definedness analysis for attribute grammars. In Proc. of Intl. Conf. on Software Language Engineering (SLE), volume 7745 of LNCS, pages 352–371. Springer-Verlag, September 2012. Lijesh Krishnan and Eric Van Wyk. Termination analysis for higher-order attribute grammars. In Proceedings of the 5th International Conference on Software Language Engineering (SLE 2012), volume 7745 of LNCS, pages 44–63. Springer-Verlag, September 2012. Lijesh Krishnan. Composable Semantics Using Higher-Order Attribute Grammars. PhD thesis, University of Minnesota, Minnesota, USA, 2012. http://melt.cs.umn.edu/pubs/krishnan2012PhD/. c Eric Van Wyk 26
  • 28. Yogesh Mali and Eric Van Wyk. Building extensible specifications and implementations of promela with AbleP. In Proc. of Intl. SPIN Workshop on Model Checking of Software, volume 6823 of LNCS, pages 108–125. Springer-Verlag, July 2011. August Schwerdfeger and Eric Van Wyk. Verifiable composition of deterministic grammars. In Proc. of Conf. on Programming Language Design and Implementation (PLDI), pages 199–210. ACM, June 2009. A. Schwerdfeger and E. Van Wyk. Verifiable parse table composition for deterministic parsing. In 2nd International Conference on Software Language Engineering, volume 5969 of LNCS, pages 184–203. Springer-Verlag, 2010. c Eric Van Wyk 26
  • 29. E. Van Wyk, O. de Moor, K. Backhouse, and P. Kwiatkowski. Forwarding in attribute grammars for modular language design. In 11th Conf. on Compiler Construction (CC), volume 2304 of LNCS, pages 128–142. Springer-Verlag, 2002. Eric Van Wyk, Lijesh Krishnan, August Schwerdfeger, and Derek Bodin. Attribute grammar-based language extensions for Java. In Proc. of European Conf. on Object Oriented Prog. (ECOOP), volume 4609 of LNCS, pages 575–599. Springer-Verlag, 2007. E. Van Wyk and A. Schwerdfeger. Context-aware scanning for parsing extensible languages. In Intl. Conf. on Generative Programming and Component Engineering, (GPCE). ACM Press, October 2007. c Eric Van Wyk 26
  • 30. Eric Van Wyk, Derek Bodin, Jimin Gao, and Lijesh Krishnan. Silver: an extensible attribute grammar system. Science of Computer Programming, 75(1–2):39–54, January 2010. c Eric Van Wyk 26