GSS-1.1 1. Introduction Domain-Specific Knowledge A task: "Implement a program to store collections of words, that describe animals" Categories of knowledge required to carry out a task: General: knowledge applicable to a wide variety of tasks e.g. English words; program in C Domain-specific:knowledge applicable to all tasks of this type e.g. group word in sets; implement arbitrary numbers of sets of strings in C Task-specific: knowledge about the particular task at hand e.g. sets of words to characterize animals A domain-specific language is used to describe the particular task A domain-specific generator creates a C program that stores the particular set of strings. (c) 2012 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 101 Objectives: Get an idea of domain-specific In the lecture: The categories are explained using the example -------------------------------------------------------------------------------- GSS-1.2 Example for a Domain-Specific Generator Input: collection of words: Output: C header file: int number_of_sets = 3; colors{red blue green} char *name_of_set[] = { bugs{ant spider fly moth bee} "colors", verbs{crawl walk run fly} "bugs", "verbs"}; int size_of_set[] = { 3,5,4}; * simple domain-specific description char *set_of_colors[] = { "red", * errors easier to detect in the domain-specific "blue", description "green"}; char *set_of_bugs[] = { * a number of tasks of the same kind "ant", "spider", "fly", * constraints on representation using general "moth", knowledge require a more complex and detailed "bee"}; description (implementation) char *set_of_verbs[] = { "crawl", "walk", * consistency conditions in the representation "run", "fly"}; using general knowledge are difficult to check char **values_of_set[] = { set_of_colors, set_of_bugs, set_of_verbs}; (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 102 Objectives: Characteristics of a domain-specific generator In the lecture: The example will be explained. -------------------------------------------------------------------------------- GSS-1.3 The Generator Principle Task description Generator Implementation Application generator: the most effective reuse method[Ch. W. Kruger: Software Reuse] narrow, specific application domain completely understood Implementation automatically generated Abstractions on a high level transformed into executable software (using domain knowledge) User understands Generator expert understands abstractions of the application domain implementation methods wide cognitive distance generator makes expert knowledge available Examples: Data base report generator GUI generator Parser generator (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 103 Objectives: Understand generators as a reuse method In the lecture: Topics of the slide will be explained -------------------------------------------------------------------------------- GSS-1.4 Domain-Specific Languages for Generators Task description Generator Implementation Domain-specific languages (DSL) Some GSS Projects Domains outside of informatics Robot control Party organization Stock exchange Soccer teams Control of production lines Tutorial organization Music scores Shopping lists Train tracks layout Software engineering domains LED descriptions to VHDL Data base reports SimpleUML to XMI User interfaces Rule-based XML transformation Test descriptions Representation of data structures (XML) Language implementation as domain Scanner specified by regular expressions Parser specified by a context-free grammar Language implementation specified for Eli Generator: transforms a specification language into an executable program or/and into data, applies domain-specific methods and techniques (c) 2010 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 104 Objectives: Recognize the roles of specification languages In the lecture: The topics of the slide will be explained. -------------------------------------------------------------------------------- GSS-1.5 Reuse of Products Product What is reused? Library of functions Implementation Module, component Code generic module Planned variants of code Software architecture Design Framework Design and code Design pattern Strategy for design and construction Generator Knowledge, how to construct implementations from descriptions Construction process Knowledge, how to use and combine tools to build software Ch. W. Kruger: Software Reuse, ACM Computing Surveys, 24(2), 1992 R. Prieto-Diaz: Status Report: Software reusability, IEEE Software, 10(3), 1993 (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 105 Objectives: Overview on reuse products In the lecture: * Items are explained. * Emphasize the role of generators. Questions: Give concrete examples for reuse products. -------------------------------------------------------------------------------- GSS-1.6 Organisation of Reuse How Products Consequences ad hoc * Code is copied and modified * no a priori costs * adaptation of OO classes * very dangerous for incrementally in sub-classes maintanance planned * oo libraries, frameworks * high a priori costs * Specialization of classes * effective reuse automatic * Generators, * high a priori costs intelligent development environments * very effective reuse * wide cognitive distance (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 106 Objectives: Reuse costs and effectiveness In the lecture: * Items are explained. * Emphasize the role of generators. -------------------------------------------------------------------------------- GSS-1.7 Roles of Provider and Reuser Reusable products are * Constructed and prepared for being reused. Role: provider * Reused for a particular application. Role: reuser Provider and reuser are on the Provider is an expert, same level of experience: reusers are amateurs: * The same person, group of * Reuse bridges a wide cognitive distance persons, profession * Expert knowledge is made available for * Provider assumes non-experts his own level of understanding * Application domain has to be for the reuser completely understood by the expert; * Examples: reuse of code, that knowledge is then encapsulated design patterns * Requires domain-specific notions on a high level * Examples: Generators, frameworks, intelligent development environments (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 107 Objectives: Roles and knowledge in context of reuse In the lecture: * Items are explained. * Emphasize: Expert knowledge provided for non-experts. -------------------------------------------------------------------------------- GSS-1.8 Project: Structure Generator (Lect. Ch. 8, Book Ch. 7) Generator implements described record structures useful tool in software construction Set of record Structur C++ class descriptions generator declarations #include "util.h" Customer ( addr: Address; account: int; ) typedef class Customer_Cl *Customer; typedef class Address_Cl *Address; Address ( name: String; zip: int; class Customer_Cl { city: String; ) private: Address addr_fld; import String from "util.h" int account_fld; public: Customer_Cl (Address addr, int account) { addr_fld=addr; account_fld=account; } ... }; (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 108 Objectives: See a useful generator In the lecture: * The task is explained. * Its effectivity is shown. * Relations to exercises. -------------------------------------------------------------------------------- GSS-1.9 Task Decomposition for the Implementation of Domain-Specific Languages Scanning Lexical analysis Conversion Structuring Parsing Syntactic analysis Tree construction Name analysis Semantic analysis Property analysis Translation Data mapping Transformation Action mapping [W. M. Waite, L. R. Carter: Compiler Construction, Harper Collins College Publisher, 1993] Corresponds to task decomposition for frontends of compilers for programming languages (no machine code generation) source-to-source transformation (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 109 Objectives: ecall general model of compiler tasks In the lecture: * Reminder to compiler lecture * Relate to compiler technique Questions: Find the corresponding slide in the lecture material of Programming Languages and Compilers. -------------------------------------------------------------------------------- GSS-1.9a Design and Specification of a DSL Design the notation of tokens Lexical analysis Specify them by regular expressions Design the structure of descriptions Syntactic analysis Specify it by a context-free grammar Design binding rules for names and Semantic analysis properties of entities. Specify them by an attribute grammar Design the translation into target code. Transformation Specify it by text patterns and their intantiation Customer ( addr: Address; account: int; ) Address ( name: String; zip: int; city: String; ) import String from "util.h" (c) 2013 bei Prof. Dr. Uwe Kastens Translation Structuring -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 109a Objectives: decompose the task of DSL design In the lecture: Explain the sub-tasks for DSL design and specification for the given example -------------------------------------------------------------------------------- GSS-1.10 Task Decomposition for the Structure Generator Recognize the symbols of the description Lexical analysis Store and encode identifiers Recognize the structure of the description Syntactic analysis Represent the structure by a tree Bind names to structures and fields Semantic analysis Store properties and check them Generate class declarations with Transformation constructors and access methods Customer ( addr: Address; account: int; ) Address ( name: String; zip: int; city: String; ) import String from "util.h" (c) 2013 bei Prof. Dr. Uwe Kastens Translation Structuring -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 110 Objectives: get concrete ideas of the sub-tasks In the lecture: Explain the sub-tasks for the given example -------------------------------------------------------------------------------- GSS-1.11 Eli Generates a Structure Generator Generator Implementation Generator Implementation . . . . . . . . . Generator Implementation Set of record Structure C++ class descriptions generator declarations (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 111 Objectives: Generators for sub-tasks provided by Eli In the lecture: Explain the diagram * Examples for generators * Generators generate a generator. -------------------------------------------------------------------------------- GSS-1.12 Task Decomposition Determines the Architecture of the Generator Specialized tools solve specific sub-tasks for creating of the product: Input processing Name analysis Scanning Definition table Symbol coding Parsing Property analysis Text generation Conversion Tree construction Attribute computation in the tree Lexical Syntactic Semantic Transanalysis analysis analysis formation Source text Symbol sequence Structure tree Attr. structure tree Target text Customer (addr: Address; Fields Fields account: int; ) Field Field Field Field isField isField FieldName FieldName FieldName FieldName [1, 1] Ident: 12 TypeName TypeName TypeName TypeName [2, 3] open [2, 4] Ident: 13 class Customer_Cl [2, 8] colon { private: [2,10] Ident: 14 Address addr_fld; int account_fld; } (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 112 Objectives: Understand the architecture of language processors In the lecture: * Phases, tasks, and representations of the intermediate results of the sub-tasks are explained * blue: Generators in Eli * red: Modules in Eli Questions: Compare this architecture with the structure of compilers as presented in the lecture on PLaC -------------------------------------------------------------------------------- GSS-1.13 The Eli System * Framework for language implementation * Suitable for any kind of textual language: domain-specific languages, programming languages * state-of-the-art compiler technique * Based on the (complete) task decomposition (cf. GSS-1.9) * Automatic construction process * Used for many practical projects world wide * Developed, extended, and maintained since1989 by William M. Waite (University of Colorado at Boulder), Uwe Kastens (University of Paderborn), and Antony M. Sloane (Macquarie University, Sydney) * Freely available via Internet from http://eli-project.sourceforge.net (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 113 Objectives: Get introduced to Eli In the lecture: * Explain the topics on the slide * Refer to practical exercises -------------------------------------------------------------------------------- GSS-1.14 Hints for Using Eli 1. Start Eli: /comp/eli/current/bin/eli [-c cacheLocation][-r] Without -c a cache is used/created in directory ~/.ODIN. -r resets the cache 2. Cache: Eli stores all intermediate products in cache, a tree of directories and files. Instead of recomputing a product, Eli reuses it from the cache. The cache contains only derived data; can be recomputed at any time. 3. Eli Documentation: Guide for New Eli Users: Introduction including a little tutorial Products and Parameters and Quick Reference Card: Description of Eli commands Translation Tasks: Conceptual description of central phases of language implementation. Reference Manuals, Tools and Libraries in Eli, Tutorials 4. Eli Commands: A common form: Specification : Product > Target e.g. Wrapper.fw : exe > . from the specification derive the executable and store it in the current directory Wrapper.fw : exe : warning > from ... derive the executable, derive the warnings produced and show them 5. Eli Specifications: A set of files of specific file types. 6. Literate Programming: FunnelWeb files comprise specifications and their documentation (c) 2007 bei Prof. Dr. Uwe Kastens -------------------------------------------------------------------------------- Lecture Generating Software from Specifications WS 2013/14 / Slide 114 Objectives: Get started using Eli In the lecture: * Explain the topics on the slide * Demonstrate using Eli * Show the mentioned documents --------------------------------------------------------------------------------