[ 1 ] Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009 ETAPS/LDTA, York Banana Algebra: Jacob Andersen [ [email protected] ] Aarhus University Claus Brabrand [ [email protected] ] IT University of Copenhagen Syntactic Language Extension via an Algebra of Languages and Transformations
44
Embed
[ 1 ] Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009 ETAPS/LDTA, York Banana Algebra: Jacob Andersen [ [email protected] ] Aarhus University Claus Brabrand.
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
[ 1 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Syntactic Language Extension via an Algebra of Languages and Transformations
[ 2 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
AbstractAbstract
We propose an algebra of languages and transformations as a means for extending languages syntactically. The algebra provides a layer of high-level abstractions built on top of languages (captured by CFGs) and transformations (captured by constructive catamorphisms).
The algebra is self-contained in that any term of the algebra specifying a transformation can be reduced to a constant catamorphism, before the transformation is run. Thus, the algebra comes "for free" without sacrificing the strong safety and efficiency properties of constructive catamorphisms.
The entire algebra as presented in the paper is implemented as the Banana Algebra Tool which may be used to syntactically extend languages in an incremental and modular fashion via algebraic composition of previously defined languages and transformations. We demonstrate and evaluate the tool via several kinds of extensions.
[ 3 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Introduction: "What is a Banana?"
Bananas for Language Transformation
Language Extension Pattern
Banana Algebra
Examples
Implementation
Related Work
Conclusion
OutlineOutline
[ 4 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
What is a 'Banana' ?What is a 'Banana' ?
Datatype; "list":
Banana ("sum-of-list"):
Separation of recursion and evaluation
Implicit recursion on input structure
bottom-up re-combination of intermediate results
list = Num N | Cons N * list
[Num n] = n[Cons n l] = n + [l]
list N
(aka. "Catamorphism" )
(| n.n , (n,l ).n+l |)
[ 5 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Language TransformationLanguage Transformation
Bananas (statically typed):
Source language: 'LS'
Target language: 'LT'
Nonterminal-typing: ' '
Reconstructors: 'c '
list = Num N | Cons N * list
tree = Nil | Leaf N | Node N * tree * tree
[Num n] = Leaf n[Cons n l] = Node n (Nil) [l]
[list -> tree]
(| LS -> LT [] c |)
Type-check'able!
LS -> LT
[ 6 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Banana properties:Simple (corresponds to: “simple recursion”)Safe (syntactically safe + always terminate)Efficient (linear time in size of input + output)(Expressive) (…enough for interesting extensions)
[ 20 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
"FUN" Usage Statistics"FUN" Usage Statistics
Usage statistics (245x operators) in "FUN":58x { …cfg… } Constant languages51x "file.l" Language inclusions28x L + L Language additions23x v Language variables17x (|L L [] c|) Constant transformations17x X + X Transformation additions14x "file.x" Transformation inclusions10x let-in Local definitions 9x idx(L) Identity transformations 8x X X Compositions 4x L \ L Language restriction 4x w Transformation variables 2x src(X) Source extractions
[ 21 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Uses (underlying technologies): 'dk.brics.grammar': for parsing, unparsing, and ambiguity analysis ! 'XSugar': for transformation: "concrete syntax abstract XML syntax" 'XSLT': for transformation: "XML XML"
[ 23 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Introduction: "What is a Banana?"
Bananas for Language Transformation
Language Extension Pattern
Banana Algebra
Examples
Implementation
Related Work
Conclusion
OutlineOutline
[ 24 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York
Related Work (I/III)Related Work (I/III)
Macro Systems:
"The metafront System: Safe and Extensible Parsing and Transformation" [ Claus Brabrand | Michael Schwartzbach ] ( LDTA 2003 , SCP J. 2007 )
"Growing Languages with Metamorphic Syntax Macros" [ Claus Brabrand | Michael Schwartzbach ] ( PEPM 2002 )
[ 25 ]Claus Brabrand, ITU BANANA ALGEBRA March 28, 2009ETAPS/LDTA, York