Textual Modeling Languages



Similar documents
Model-Driven Development - From Frontend to Code

VICCI. The Eclipse Modeling Framework (EMF) A Practical Introduction and Technology Overview. Dipl.-Inf. Christoph Seidl

Implementation and Integration of a Domain Specific Language with oaw and Xtext

Organization of DSLE part. Overview of DSLE. Model driven software engineering. Engineering. Tooling. Topics:

Compiler Construction

Xtext Documentation. September 26, 2014

How to Improve Database Connectivity With the Data Tools Platform. John Graham (Sybase Data Tooling) Brian Payton (IBM Information Management)

Syntax Check of Embedded SQL in C++ with Proto

Eindhoven University of Technology

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

JastEMF: Reference Attribute Grammars for EMF-based DSLs

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Architectural Design Patterns for Language Parsers

A DSL Toolkit for Deferring Architectural Decisions in DSL-Based Software Design

Efficient Editor Generation for Compositional DSLs in Eclipse

CSCI 3136 Principles of Programming Languages

Modeling Cloud Messaging with a Domain-Specific Modeling Language

Programmers rejoice: QML makes business people understand. Qt Developer Days 2014 Hinrich Specht 2. September 2014 Folie 1

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

YouTrack MPS case study

A Web Specific Language for Content Management Systems

Integrating Content Assist into Textual Modelling Editors

Implementing reusable software components for SNOMED CT diagram and expression concept representations

UML PROFILING AND DSL

Development of Tool Extensions with MOFLON

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Programming Project 1: Lexical Analyzer (Scanner)

Programming Languages CIS 443

Jos Warmer, Independent

Programming Assignment II Due Date: See online CISC 672 schedule Individual Assignment

Lecture 9. Semantic Analysis Scoping and Symbol Table

On General-purpose Textual Modeling Languages. On General-purpose Textual Modeling Languages

COCOVILA Compiler-Compiler for Visual Languages

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Towards More Security in Data Exchange

mbeddr: an Extensible MPS-based Programming Language and IDE for Embedded Systems

A Model-Driven Approach for the Development of an IDE for Spacecraft On-Board Software

03 - Lexical Analysis

sql-schema-comparer: Support of Multi-Language Refactoring with Relational Databases

Context free grammars and predictive parsing

Foundations of Model-Driven Software Engineering

DSL Design. Model Transformations. Model Transformations. Language g Implementation Strategies

OpenEmbeDD basic demo

clooca : Web based tool for Domain Specific Modeling

Compiler Construction

Dynamic website development using the Grails Platform. Joshua Davis Senior Architect Cognizant Technology Solutions

Compiler I: Syntax Analysis Human Thought

Implementing a Bidirectional Model Transformation Language as an Internal DSL in Scala

Building industrial sensors with MDSD

Cedalion A Language Oriented Programming Language (Extended Abstract)

Polyglot Multi-Paradigm. Modeling. MDA in the Real World. Stefan Tilkov

Teaching Pragmatic Model-Driven Software Development

An Eclipse Plug-In for Visualizing Java Code Dependencies on Relational Databases

UPROM Tool: A Unified Business Process Modeling Tool for Generating Software Life Cycle Artifacts

CommentTemplate: A Lightweight Code Generator for Java built with Eclipse Modeling Technology

Embedded Software Development with MPS

Programming Languages

Proceedings of the 6th Educators Symposium: Software Modeling in Education at MODELS 2010 (EduSymp 2010)

X-ABNF: Name-Bindings of ABNF specifications for custom code generation

Automatic Generation of Consistency-Preserving Edit Operations for MDE Tools

estatistik.core: COLLECTING RAW DATA FROM ERP SYSTEMS

today 1,700 special programming languages used to communicate in over 700 application areas.

Transforming PICTURE to BPMN 2.0 as Part of the Model-driven Development of Electronic Government Systems

Semester Review. CSC 301, Fall 2015

COS 333: Advanced Programming Techniques

Modern PL/SQL Code Checking and Dependency Analysis

Simplified Game Specific Description Language for Rapid Game Server Development using LDD (Language Driven Development) Framework

A Framework for Creating Domain-specific Process Modeling Languages

Co-Creation of Models and Metamodels for Enterprise. Architecture Projects.

Lecture 1: Introduction

Automatic Test Data Generation for TTCN-3 using CTE

Integrate your tools to help integrate your stakeholders

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Syntaktická analýza. Ján Šturc. Zima 208

A QUICK OVERVIEW OF THE OMNeT++ IDE

XFlash A Web Application Design Framework with Model-Driven Methodology

A Model-Driven Approach for Graph Visualization

The Mjølner BETA system

Transcription:

Textual Modeling Languages Slides 4-31 and 38-40 of this lecture are reused from the Model Engineering course at TU Vienna with the kind permission of Prof. Gerti Kappel (head of the Business Informatics Group) 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 1

Workflow Overview Text comprehension + transformation Text Lexing Token stream (tokens = lexical units: comments and whitespaces removed) Parsing Concrete syntax tree (syntactical units: for cycle, if statement) Abstraction Abstract syntax tree (AST) Transformation Model Editor specification How to provide useful feedback to the user in a GUI 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 2

Table of Contents EBNF XText ANTLR + M2M transformation Online demo 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 3

Language Specification Basics Extended Backus-Naur-Form (EBNF) Originally introduced by Niklaus Wirth to specify the syntax of Pascal In general, they can be used to specify a context-free grammar ISO Standard Fundamental assumption: A text consists of a sequence of terminal symbols (visible characters). EBNF specifies all valid terminal symbol sequences using a compact and finite representation grammar Grammar Terminal symbols (lexical units) Non-terminal symbols (syntactical units) Starting non-terminal symbol (root of the syntax tree) Production rules consist of a left side non-terminal and a right side (valid symbol sequences) 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 4

EBNF Production rules consist of: Terminal NonTerminal Choice Optional Repetition Grouping Comment 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 5

Example: Entity DSL Language constructs Arbitrary character sequences Keywords Separation characters Scope borders References type String type Boolean entity Conference { property name : String property attendees : Person[] property speakers : Speaker[] } entity Person { property name : String } entity Speaker extends Person { } 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 6

Example: Entity DSL II. EBNF grammar Model := Type*; Type := SimpleType Entity; SimpleType := 'type' Identifier; Entity := 'entity' Identifier ('extends' Identifier)? '{' Property* '}'; Property := 'property' Identifier ':' Identifier ('[]')?; Identifier := ('a'..'z' 'A'..'Z' '_') ('a'..'z' 'A'..'Z' '_' '0'..'9'); 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 7

Example: Entity DSL III. EBNF-to-Ecore mapping Model := Type*; Type := SimpleType Entity; SimpleType := 'type' Identifier; Entity := 'entity' Identifier ('extends' Identifier)? '{' Property* '}'; Property := 'property' Identifier ':' Identifier ('[]')?; Identifier := ('a'..'z' 'A'..'Z' '_') ('a'..'z' 'A'..'Z' '_' '0'..'9'); 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 8

EBNF vs. Ecore EBNF + Specifies concrete syntax + Linear order of elements No reusability Only containment relationships Ecore + Reusability by inheritance + Non-containment references + Predefined data types and user-defined enumerations ~ Specifies only abstract syntax Conclusion A meaningful EBNF cannot be generated from a metamodel and vice versa! Challenge How to overcome the gap between these two worlds? 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 9

Solution Overview Generic Syntax Like XML Metamodel is sufficient, i.e., no concrete syntax is needed For instance: HUTN (OMG Standard) - www.omg.org/spec/hutn Metamodel First! Step 1: Specify metamodel Step 2: Specify textual syntax additionally For instance: TCS (Eclipse Plug-in) - www.eclipse.org/gmt/tcs Grammar First! Step 1: Syntax is specified by a grammar (concrete syntax & abstract sytnax) Step 2: Metamodel is derived from step 1 For instance: Xtext (Eclipse Plugin) - www.eclipse.org/xtext Although Xtext supports importing metamodels in the meanwhile Separate metamodel and grammar 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 10

Table of Contents EBNF XText ANTLR + M2M transformation Online demo 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 11

XText Introduction XText was originally part of openarchitectureware, now it is more a separate project Used to develop textual domain specific languages Grammar definition similar to EBNF, but with extra features for metamodel generation Creates metamodel, parser, and editor from grammar definition Editor supports syntax check, highlighting, and code completion Context-sensitive constraints on the grammar described in OCL-like language 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 12

XText Workflow Overview oaw «artifact» Metamodel «artifact» Grammar «artifact» Constraints Xtext (Textual DSLs) «component» Parser «component» Editor Xpand (M2C) Xtend (M2M) «artifact» Model 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 13

XText Grammar I. Xtext grammar similar to EBNF Extended by Object-oriented concepts Information necessary to derive the metamodel Editor Example A A : (type = B); type B 0..1 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 14

XText Grammar II. Terminal rules Similar to EBNF rules Return value is String by default EBNF expressions Cardinalities Zero to one? Zero to many * One to many + Character range Wildcard Until Token Negated Token Predefined rules ID, String, Int, URI '0'..'9' 'f'.'o' '/*' -> '*/' '#' (!'#')* '#' 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 15

XText Grammar III. terminal ID : ('^')?('a'..'z' 'A'..'Z' '_') ('a'..'z' 'A'..'Z' '_' '0'..'9')*; terminal INT returns ecore::eint : ('0'..'9')+; terminal ML_COMMENT : '/*' -> '*/'; 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 16

XText Grammar IV. Type rules For each type rule a class is generated in the metamodel Class name corresponds to rule name Type rules contain Terminals -> Keywords Assignments -> Attributes or containment references Cross References -> Non-containment references Assignment Operators Single-valued feature = Multi-valued feature += Boolean features?= Enum rules Map Strings to enumeration literals 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 17

XText Grammar V. Assignment State : 'state' name = ID (transitions += Transition)* 'end'; Cross References Transition : event = [Event] '=>' state = [State]; Enum rules enum ChangeKind : ADD MOVE REMOVE; enum ChangeKind : ADD = 'add' ADD = '+' MOVE = 'move' MOVE = '->' REMOVE = 'remove' REMOVE = '-'; 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 18

XText Tooling I. Xtext Blueprint Projects Grammar definition Code generator IDE functionality 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 19

XText Tooling II. Xtext Grammar Project Workflow File for generating DSL Editor Properties: File Extension, Grammar Definition 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 20

XText Tooling III. Xtext Grammar Definition Grammar Name Default Terminals (ID, STRING, ) Metamodel URI 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 21

XText Tooling IV. Xtext Grammar Definition for State Machines 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 22

XText Tooling V. Generated Ecore-based Metamodel 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 23

XText Tooling VI. Generated DSL Editor Outline View Error! Code Completion (Ctrl+Space) Highlighting of keywords Error Description 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 24

Entity DSL Example Model := Type*; EBNF Grammar Type := SimpleType Entity; SimpleType := 'type' Identifier; Entity := 'entity' Identifier ('extends' Identifier)? '{' Property* '}'; Property := 'property' Identifier ':' Identifier ('[]')?; Identifier := ('a'..'z' 'A'..'Z' '_') ('a'..'z' 'A'..'Z' '_' '0'..'9'); type String type Boolean Example Model entity Conference { property name : String property attendees : Person[] property speakers : Speaker[] } entity Person { property name : String } entity Speaker extends Person { } 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 25

EBNF to XText Transition Model := Type*; EBNF Grammar Type := SimpleType Entity; SimpleType := 'type' Identifier; Entity := 'entity' Identifier ('extends' Identifier)? '{' Property* '}'; Property := 'property' Identifier ':' Identifier ('[]')?; Identifier := ('a'..'z' 'A'..'Z' '_') ('a'..'z' 'A'..'Z' '_' '0'..'9'); XText Grammar grammar MyDsl with org.eclipse.xtext.common.terminal generate mydsl "http://mydsl" Model : elements += Type*; Type : SimpleType Entity; SimpleType : 'type' name = ID; Entity : 'entity' name = ID ('extends' extends = [Entity])? '{' properties += Property* '}'; Property : 'property' name = ID ':' type = [Type](many?= '[]')?; 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 26

Specifying Context Sensitive Constraints for Textual DSLs I. Examples Entity names must start with an uppercase character Entity names must be unique Property names must be unique within one entity Answer Use the same techniques as for metamodels! XText Grammar grammar MyDsl with org.eclipse.xtext.common.terminal generate mydsl "http://mydsl" Model : elements += Type*; Type : SimpleType Entity; SimpleType : 'type' name = ID; Entity : 'entity' name = ID ('extends' extends = [Entity])? '{' properties += Property* '}'; Property : 'property' name = ID ':' type = [Type](many?= '[]')?; 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 27

Specifying Context Sensitive Constraints for Textual DSLs II. Examples 1. Entity names must start with an uppercase character 2. Entity names must be unique 3. Property names must be unique within one entity Solutions context mydsl::entity WARNING "Name should start with a capital": name.tofirstupper() == name; context mydsl::entity ERROR "Name must be unique": ((Model)this.eContainer).elements.name.select(e e == this.name).size == 1; context mydsl::property ERROR "Name must be unique": ((Model)this.eContainer.eContainer).properties.name.select(p p == this.name).size == 1; 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 28

Specifying Context Sensitive Constraints for Textual DSLs III. Every edit operation for cheap constraints Every save operation for cheap to expensive constraints Every generation operation for very expensive constraints 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 29

Specifying Context Sensitive Constraints for Textual DSLs IV. Code Generation Projects are automatically generated Code 2 Model Injector is used in the workflow file <component class="org.eclipse.xtext.mwereader" uri="${modelfile}"> <!-- this class will be generated by the xtext generator --> <register class="org.xtext.example.mydslstandalonesetup"/> </component> Xpand templates can be developed as usual «IMPORT mydsl» «DEFINE main FOR Model» «FOREACH this.elements.typeselect(entity) AS e-» «FILE e.name".class"-» class «e.name»... «ENDFILE» «ENDFOREACH» «ENDDEFINE» 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 30

XText: Standard Framework for EMF? Tight integration with Eclipse and oaw Powerful editors, constraint checks, code generation, model transformation, Allows to switch between EMF models and text-based artefacts Both are supported in Eclipse: Textual and Graphical Modeling! Allows to customize the editor by many extension points Pretty printing, code completion, Strong community 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 31

Strengths and Weaknesses of XText (+) Compact: Minimal effort for establishing small/simple DSLs EMF/Eclipse integration EBNF like (easy to learn) Editor for free text comprehension transformation editor specification 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 32

Strengths and Weaknesses of XText (-) Mixing of concerns: Text comprehension, actual transformation and editor specification are implicit and woven tightly together in one specification with the following consequences: Bidirectionality is hard to support Impossible to reuse e.g., the transformation part with a different textual comprehension part (e.g., for XML, regular expressions, directory structures, handwritten parsers, ). Complex specifications become difficult to maintain as everything becomes complex, i.e., textual comprehension and the transformation. 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 33

Strengths and Weaknesses of XText (-) Generality: Not all languages can be expressed (easily) with an Xtext grammar (mixing in Java is not possible!) Target model is usually quite low-level. In general a metamodel first approach for an arbitrary model requires a subsequent M2M transformation leading to a high complexity of the complete transformation chain due to different languages. Fixed interpretation of EBNF Using existing or preferred (e.g., bottom-up) parsers is not possible No parts of the transformation can be reused if the modeling standard (Ecore) is changed 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 34

Table of Contents EBNF XText ANTLR + M2M transformation Online demo 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 35

Alternative Tree-Based Approach Separate transformation into two distinct parts: 1. Text-to-tree (text comprehension) with a parser (e.g., generated from an EBNF specification) 2. Tree-to-model (actual transformation or interpretation) with a model transformation language (e.g., SDM, TGG) Step (1) can be achieved with just an EBNF specification and no extra effort. Step (2) involves (i) adding extra typing information to the homogeneous tree structure from a parser, and (ii) deducing context-sensitive relationships to yield a (regular) graph structure. Arbitrary metamodels can be targeted with increasing complexity of Step (2) 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 36

Workflow with ANTLR + emoflon Simple Tree Metamodel (AST) [Moca Tree] Target Metamodel EBNF SDM, TGG Lexer + Parser Transformation text tree model Text-to-Tree Tree-to-Model 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 37

Advantages of Textual DSLs Textual languages have specific strengths compared to graphical languages Scalability Pretty-printing Compact and expressive syntax Productivity for experienced users IDE support softens learning curve Configuration management/versioning Concurrent work on a model, especially with a version control system Diff, merge, search, replace, Working without a sophisticated editor 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 38

State-of-the-Art DSL Development Techniques DSLs are very common: CSS, regular expressions, ant, SQL, HQL, Rails Two types of DSLs: internal vs. external Internal DSLs Embedded languages in existing host languages Explicit internal DSLs: becoming mainstream through Ruby and Groovy Implicit internal DSLs: fluent interfaces simulate DSLs in Java and C# External DSLs Have their own custom syntax Own parser to process them Own editor to build sentences Own compiler to executable language or own interpreter Many XML-based languages have ended up as external DSLs (not user friendly) 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 39

References XText related Project Site: http://www.eclipse.org/xtext Xtext Webinar: http://live.eclipse.org/node/705 Text-based language meta-frameworks Monticore: www.monticore.org MGrammar: http://msdn.microsoft.com/en-us/library/dd857654(vs.85).aspx TCS: www.eclipse.org/gmt/tcs HUTN: http://www.omg.org/spec/hutn/ Domain specific (modeling) languages Fowler, M.: Domain Specific Languages. 2009. Mernik, M., Heering, J., and Sloane, A. M.: When and how to develop domainspecific languages. ACM Computing Surveys 37(4), pp. 316-344, 2005. Kelly, S., and Tolvanen, J.P.: Domain-Specific Modeling: Enabling Full Code Generation. Wiley-IEEE Computer Society, 2008. 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 40

Table of Contents EBNF XText ANTLR + M2M transformation Online demo 24. Mai 2012 Real-Time Systems Lab Prof. Dr. Andy Schürr Dr. Gergely Varró 41