SUPREMA CORTE DE JUSTICIA DE LA NACION
VISTOS; Y, RESULTANDO:
Conditional rules can be used to implement matching and instantiation in such a way that the rules closely correspond to the derivation rules in Chapter 3. Therefore, only an excerpt of the implementation will be presented. In Listing 21 is an excerpt of the implementation of instantiate that shows the code for sequential instantiation.
Listing 21 Metacircular Implementation of Sequential Instantiation
1 opdef instantiate:
2 ...
3 do ($sin $bin [:seq $p1 @pr] ) $sout) 4 if $sin $bin $p1 instantiate ) $s1
5 && ($s1 $bin [:seq @pr] instantiate ) $sout). 6 $sin $bin [:seq ] ) $sin.
7 ...
The header of the conditional rule binds p1 to the first element of the pattern sequence and prto the rest of the pattern sequence. The first conditional instantiates the pattern with the initial input and binds s1 to the result. The second conditional calls instantiate on s1, the original bindings and the sequence pattern with the first element removed. By doing so, the rule manipulates the internal program representation and creates a new pattern. The result of instantiating this pattern is the end result of the instantiation. The unconditional rule in line 6 implements the base case of the recursion: in case the sequence pattern is empty the input sequence sin remains unchanged.
Listing 22 shows the implementation of matching an unconditional transformation. Listing 22 Metacircular Implementation of Unconditional Transformations
1 opdef match:
2 ...
3 do ($sin $bin [:utrans $lhs $rhs] ) $res $sout $bout) 4 if ($sin $bin $lhs match ) $res $sout $b1)
5 && ([] $b1 $rhs instantiate ) $res).
6 ...
The header binds lhs to the pattern that makes up the left-hand side of the transfor- mation and rhs to the pattern that makes up the right-hand side. The first conditional matches the left-hand side with the initial input and the second conditional instantiates the right-hand side with an empty sequence and the bindings resulting from the match. The transformation yields the result produced by instantiation and the output sequence and store produced by matching.
5.6 Summary and Conclusions
Concat demonstrates the applicability of the pattern core and its programming related ex- tensions to language engineering. While the previous chapters supported the hypothesis that pattern matching and instantiation provides a formal foundation for LDSE, Con- cat supports the hypothesis that this foundation is also a practical for language-driven programming. Everything in Concat is based on patterns. By applying its language engi- neering tools to its own meta-language, Concat can hide its pattern-based foundation and change itself from within. The degrees of change supported are the following:
• New concrete syntax for literals on the meta-level, e.g., a pattern that uses concrete syntax for rational numbers (1/3|1/2) (views)
• New meta-language syntax. For example, a new syntax for variable bindings such as $x (meta-views)
• New pattern expressions such as <rational> or <seplist> (productions) • Modification of pattern semantics and new features that cannot be implemented by
combining expressions, but require access on a lower level, e.g., memoization or backtracking (metacircular implementation)
The changes supported range from smaller syntactic adjustments to complete replace- ment of the language syntax and semantics. In this sense, Concat is not only an engine for creating languages but also an engine for its own evolution. In other words, Concat can sustain itself [56].
The general philosophy of Concat is to strike a balance between the unambiguity and ease of structural manipulation a uniform framework provides and the freedom and flex- ibility needed for implementing a wide range of languages. This philosophy is embodied in all aspects of the implementation in the form of mutually complementary concepts. Typed sequences define a uniform syntax and views provide means to break out of the re- strictions this entails. Operations enforce functional semantics and macros provide means to circumvent these semantics. Core Concat provides a set of operational concepts and at the same time the means to replace these concepts with new ones.
Concat is a multi-level framework in several regards. Program syntax can be described in five layers with refinement relationships between each. A three-level distinction is made between program, meta-program and meta-meta-program. Views provide a mechanism to implement a programming system in an arbitrary number of layers where each layer
An interesting aspect of Core Concat is the way operations and different types of macros are implemented using the rewriting system. An operation definition associates an operator with a functional semantics. Internally, the operator is appended to the left- hand side of each rule in the body of the operation definition. In effect, the operator defines a context for the rules in the body. Accordingly, the operation definition can be interpreted as a statement that the rules in the body can be applied in the context of the operator symbol. For internalisation macros, a start-tag serves as a left-hand context to the definition to the body. By using start- and end-tags, there is a context to the left and to the right. The underlying principle is that different kinds of computational entities can be defined by separating transformations and context.
XMF: A Pattern-based
(Meta-)Modelling Framework
XMF (XML Modeling Framework)1 is a modelling and meta-modelling tool based on the pattern core introduced in Chapter 3. XMF was initially developed for teaching mod- elling and language-driven engineering and has been successfully used in university teach- ing [143]. Its main goals are to provide flexible means to create and relate modelling languages and to make the modelling process interactive. XMF consists of a browser- based, integrated development environment, a pattern-based transformation language and a JavaScript API that exposes pattern functionality. XMF is based on a three-level meta- architecture in which inter-level relationships are formally defined by pattern instantia- tion and different kinds of relationships between models are defined by a relationship language (Section 6.1). XMF implements this meta-architecture and in addition to that defines a view mechanism for graphical model syntax (Section 6.2). The abstract and concrete syntax of models are based on XML. Models and views are defined using the XML Pattern Language for Transformations (XPLT) that implements matching and in- stantiation on Document Object Model (DOM) trees. Technically, XPLT is a schema lan- guage. However, schemas are defined in such a way that they form the basis for transfor- mation, refinement and querying. Based on XPLT patterns, the view mechanism derives bidirectional transformation between XML model representations and graphical views in XHTML (Section 6.3). XMF contains two built-in modelling languages for class and ob- ject modelling (Section 6.4). These are implemented in XPLT (Section 6.5). A JavaScript API serves as a constraint language for formalising the relationship between models and modelling languages and for defining semantic model constraints. The API functionality is based on referencing and refining patterns and querying with patterns (Section 6.6).
6.1 Meta-Architecture
In recent years, Domain Specific Modelling Languages (DSMLs) have seen growing in- terest in research and practice. DSMLs promise the same advantages for modelling that domain specific programming languages promise for programming: higher expressibility that leads to more readable and maintainable models. The systematic use of specialised languages for modelling different aspects of a system requires the ability to create and relate languages in a flexible manner. For many years, the Unified Modeling Language (UML) [130,131] has been the most prominent modelling language. Although it is a gen- eral purpose object-oriented language, it provides a meta-architecture that describes the relationships between models, languages and meta-languages. In the following, the UML meta-architecture serves as a starting point for developing a uniform meta-architecture that supports a pattern-based approach to creating and relating modelling languages.