Upload
ericupnorth
View
5.497
Download
0
Embed Size (px)
Citation preview
Scaling declarative language specifications
to full-featured languages
and real-world applications1
Ted Kaminksi and Eric Van Wyk
University of Minnesota
SLS 2013, June 25, 2013, Cambridge
1This work is partially supported by NSF Awards No. 0905581 and1047961.
c© Eric Van Wyk 1
Scaling up: languages
c© Eric Van Wyk 2
Scaling up: users
c© Eric Van Wyk 3
Scaling up: languages
One strategy:
I identify a “core” language
I new features translate down to core features
For example:
I for-loop to an initializing assignment and while-loop
I int x,y,z, to int x; int y; int z;,
Difficult question: Which features are part of the core?
c© Eric Van Wyk 4
Implicit and explicit specification of semantics
Specify semanticsI explictly, where desirable/neededI implicitly, via translation, where possible
ArrayList herd = ... ;
for (Goat g: herd) {
g.milk ();
}
language feature-specific
I error messages, analysis
I optimizations
from Java 1.5 translates to code in Java 1.4:
ArrayList herd = ... ;
for (Iterator it = herd.iterator(); it.hasNext();) {
Goat g = (Goat) it.next(); g.milk();
}
for byte code generationc© Eric Van Wyk 5
ForwardingI supports explicit and implicit (via translation)
specification of semantics
I originated in Intentional Programming at MSR Redmond,adapted to attribute grammars at Oxford [CC’02]
I In attribute grammar terminology:I production define some attributesI construct a semantically equivalent syntax tree andI “forward” queries for undefined attributes to that tree
I Similar to prototype or object inheritance, not classinheritance.
c© Eric Van Wyk 6
abstract production enhanced for
f::Stmt ::= ’for’ ’(’ t::Type id::Id ’:’ data::Expr ’)’
body::Stmt
{ f.errors = if isCollection || isArray then [ ]
else [ "Enhanced-for must iterate over " ++
"Collections or arrays." ];
data.env = addEnv( id, t.typerep, f.env ) ;
local attribute isCollection :: Boolean =
match( data.typerep, collectionType( ) ) ;
local attribute isArray :: Boolean =
match( data.typerep, arrayTypeRep( ) ) ;
forwards to if isCollection then forOverCollection
else if isArray then forOverArray
else skip() ;
local attribute forOverCollection :: Stmt =
... syntax tree of for-loop over a collection...local attribute forOverArray :: Stmt =
... syntax tree of for-loop over an array...}c© Eric Van Wyk 7
Various uses
I Name bindingI production unboundVarRef
e::Expr ::= v::VarRef t
forwards to
I production boundVarRef
e::Expr ::= v::VarRef t dcl::Decorated Dcl
I operator overloadingI generic addition
forwards to
I type-specific addition (e.g. integer, matrix, ... )
c© Eric Van Wyk 8
Scaling up: users
c© Eric Van Wyk 9
Extensible Languages (Frameworks)
I @MSR: Intentional Programming
I @Minnesota: ableJ [ECOOP’07], ableP [SPIN’11]
I pluggable domain-specific language extensions
I domain-specific syntax, analysis, and optimization
I composable, developed independently!
I general purpose host language still available
I Extension features translate down to host language
c© Eric Van Wyk 10
class Demo {int demoMethod ( ) {List<List<Integer>> dlist ;
int T ;
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
• SQL queries
• non-null pointeranalysis
• tabular booleanexpressions
c© Eric Van Wyk 11
Extensibility: safe composability
Non-nullpointeranalysis
SQLqueries
c© Eric Van Wyk 12
Extensibility: safe composability
����
���
����
� �����������
�����
�����
��
����������������
SQLqueries
Non-nullpointeranalysis
c© Eric Van Wyk 13
Roles people play ...
1. host language designer
2. language extension designer
3. programmerI language extension user
c© Eric Van Wyk 14
c© Eric Van Wyk 15
Extensible languages require declarative
specifications
I Composable language/extension specifications.
I For composable (no glue code) extensions, forwarding isneeded.
I These make extensible language possible, but don’tesnure that the extensions will, in fact, compose.
I modular analysis are needed.
c© Eric Van Wyk 16
Building a parser from composed specifications.
... CFGH ∪∗ {CFGE1, ...,CFGEn}
∀i ∈ [1, n].isComposable(CFGH ,CFGEi )∧conflictFree(CFGH ∪ CFGEi )
⇒ ⇒ conflictFree(CFGH ∪ {CFGE1, ...,CFGEn})
I Monolithic analysis - not too hard, but not too useful.
I Modular analysis - harder, but required [PLDI’09].
I Non-commutative composition of restricted LALR(1)grammars.
c© Eric Van Wyk 17
Building an attribute grammar evaluator from composedspecifications.
... AGH ∪∗ {AGE1, ...,AGEn}
∀i ∈ [1, n].modComplete(AGH ,AGEi )
⇒ ⇒ complete(AGH ∪ {AGE1 , ...,AGE
n })
I Monolithic analysis - not too hard, but not too useful.
I Modular analysis - harder, but required [SLE’12a].
c© Eric Van Wyk 18
c© Eric Van Wyk 19
Future work
#include <sdtio.h>
int main() {
... bits of SAC ...
... stencil specifications ...
... computational geometry optimizations
robustness transformations ...
}
c© Eric Van Wyk 20
Thanks for your attention.
Questions?
http://melt.cs.umn.edu
c© Eric Van Wyk 21
E. Van Wyk, O. de Moor, K. Backhouse, andP. Kwiatkowski.Forwarding in attribute grammars for modular languagedesign.In 11th Conf. on Compiler Construction (CC), volume2304 of LNCS, pages 128–142. Springer-Verlag, 2002.
Eric Van Wyk, Lijesh Krishnan, August Schwerdfeger, andDerek 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.
c© Eric Van Wyk 21
Yogesh Mali and Eric Van Wyk.Building extensible specifications and implementations ofpromela with AbleP.In Proc. of Intl. SPIN Workshop on Model Checking ofSoftware, 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 andImplementation (PLDI), pages 199–210. ACM, June 2009.
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.
c© Eric Van Wyk 21
Lijesh Krishnan and Eric Van Wyk.Termination analysis for higher-order attribute grammars.In Proceedings of the 5th International Conference onSoftware Language Engineering (SLE 2012), volume 7745of LNCS, pages 44–63. Springer-Verlag, September 2012.
Lijesh Krishnan.Composable Semantics Using Higher-Order AttributeGrammars.PhD thesis, University of Minnesota, Department ofComputer Science and Engineering, Minneapolis,Minnesota, USA, 2012.Available athttp://melt.cs.umn.edu/pubs/krishnan2012PhD/.
c© Eric Van Wyk 21