Grammar Composition & Extension

Size: px
Start display at page:

Download "Grammar Composition & Extension"

Transcription

1 Grammar Composition & Extension Symposium on Language Composition and Modularity Vadim Zaytsev, SWAT, CWI 2012

2 Introduction to grammarware

3 What is a grammar? Structural description in software systems Description of structures used in software systems P. Klint, R. Lämmel, C. Verhoef, Toward an Engineering Discipline for Grammarware. TOSEM 2005.

4 Grammar use case Abstract use case syntax definition exchange format interaction protocol data model domain model metamodel Concrete use case parsing serialisation renovation refactoring static analysis reengineering P. Klint, R. Lämmel, C. Verhoef, Toward an Engineering Discipline for Grammarware. TOSEM 2005.

5 Grammarware Parser Compiler Interpreter Pretty-printer Scanner Browser Static checker Structural editor IDE DSL framework Preprocessor Postprocessor Model checker Refactorer Code slicer API XMLware Modelware Language workbench Reverse engineering tool Benchmark Recommender Renovation tool

6 Grammars everywhere

7 Grammarware

8 Grammarware

9 Grammarware

10 Grammarware

11 Grammarware

12 Grammarware

13 Grammar decomposition

14 CWI Quo usque tandem? Lexical syntax: character level (tokenisation) block level (indentation) Preprocessing syntax comments directives Base syntax Syntax highlighting Processing order Filtering / disambiguation Error handling Tree construction AST format

15 Grammar composition

16 Behind the Screen / Unknown Chaplin Fair (re)use, picture is the courtesy of chaplin.bfi.org.uk.

17 Grammar composition syntax A = B+; syntax B = b ; syntax D = C*; syntax C = c ; syntax A = B+; syntax D = C*; syntax B = b ; syntax C = c ;

18 Grammar composition syntax A = B C; syntax B = b ; syntax D = C B; syntax C = c ; syntax A = B C; syntax D = C B; syntax B = b ; syntax C = c ;

19 Grammar composition syntax A = B C; syntax B = b ; syntax C = c ; syntax A = B C; syntax B = b ; syntax C = c ; { bc }

20 Grammar composition syntax A = B C; syntax B = b ; syntax C = c ; syntax A = C B; syntax B = c ; syntax C = b ; { bc, cb }

21 Grammar composition syntax A = B CA; syntax B = b ; syntax C = c ; syntax A = B CB; syntax B = b ; syntax C = c +; n { c b }, n=0,1,2,

22 Grammar composition syntax A = B BA; syntax B = b ; syntax A = AB B; syntax B = b ; n { b }, n=1,2,

23 Grammar composition syntax A = B C; syntax C = D+; syntax = ε; syntax C = E; syntax E = B+; syntax = ε; XML

24 Grammar composition syntax A = B C { }; syntax A = B C { };?

25 Grammar composition syntax A = B C; syntax B = b ; syntax C = c ; syntax C = D E; syntax C c ;?

26 Adjacent topics: pgt gc ngt no

27 Programmable Grammar Transformations

28 Programmable G xformation Ad hoc megamodel shown at IPA Spring Days

29 Programmable G xformation Operator known semantics, well-defined algorithm rename, fold, factor, inject, remove, Ad hoc megamodel shown at IPA Spring Days

30 Programmable G xformation Arguments what exactly to rename/factor/inject/? Ad hoc megamodel shown at IPA Spring Days

31 Programmable G xformation Input grammar determines applicability Ad hoc megamodel shown at IPA Spring Days

32 Programmable G xformation Ad hoc megamodel shown at IPA Spring Days

33 XBGF Operator Suite Semantic-preserving operators fold, unfold, extract, inline, massage, factor, deyaccify, (Some) semantic-preserving operators permute, abstractize, concretize, designate, anonymize Language-increasing operators add, appear, widen, upgrade, unite Language-decreasing operators remove, disappear, narrow, downgrade Revising operators redefine, inject, project, replace, V. Zaytsev, BGF Transformation Operator Suite v.1.0, online, 2010.

34 References R. Lämmel. Grammar Adaptation. FME, LNCS 2021: R. Lämmel, G. Wachsmuth. Transformation of SDF Syntax Definitions in the ASF+SDF Meta- Environment. LDTA, ENTCS T. R. Dean, J. R. Cordy, A. J. Malton, K. A. Schneider. Grammar Programming in TXL. SCAM R. Lämmel, Transformations Everywhere. SCP 52(1 3):1 8, P. Klint, R. Lämmel, C. Verhoef. Toward an Engineering Discipline for Grammarware. ACM TOSEM 14(3): , V. Zaytsev, BGF Transformation Operator Suite v.1.0, online, V. Zaytsev, Recovery, Convergence and Documentation of Languages. PhD, R. Lämmel, V. Zaytsev, Recovering Grammar Relationships for the Java Language Specification, SQJ 19(2):

35 Guided Grammar Convergence

36

37

38 The most trivial case Equal grammars Algebraically equivalent grammars Nothing to do here V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

39 Structural resolution Nonterminal vs. value A vs. string Sequence permutations A B B A vs. B B A A Lists of symbols A* vs. A+ Separator lists irrelevant V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

40 Nominal resolution Production rule in the master grammar Production signature p 1 =p(, program, +(function)) {function, +} p 2 =p(, function, seq([str, +(str), expr])) {expr, 1, str, 1+} p 3 =p(, expr, str) {str, 1} p 4 =p(, expr, int) {int, 1} p 5 =p(, expr, apply) {apply, 1} p 6 =p(, expr, binary) {binary, 1} p 7 =p(, expr, cond) {cond, 1} p 8 =p(, apply, seq([str, +(expr)])) {expr, +, str, 1} p 9 =p(, binary, seq([expr, operator, expr])) {expr, 11, operator, 1} p 10 =p(, cond, seq([expr, expr, expr])) {expr, 111} Table 1. Production rules of the master grammar for FL, with their production signatures. V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

41 Definitions Nonterminal footprint Production signature Prodsig-equivalence Weak prodsig-equivalence Nominal resolution V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

42 Nominal resolution example Production rule q 1 =p, Fragment, Expr q 2 =p, Program, + (Function) Production signature {Expr, 1} {Function, +} q 3 =p(, Function, seq ([str, + (str), Expr])) {str, 1+, Expr, 1} q 4 =p(, Expr,int) {int, 1} q 5 =p(, Expr,str) {str, 1} q 6 =p(, Expr, Expr 1 ) {Expr 1, 1} q 7 =p(, Expr, Expr 2 ) {Expr 2, 1} q 8 =p(, Expr, Expr 3 ) {Expr 3, 1} q 9 =p(, Expr 1, seq ([Ops, Expr, Expr])) {Ops, 1, Expr, 11} q 10 =p(, Expr 2, seq ([Expr, Expr, Expr])) {Expr, 111} q 11 =p(, Expr 3, seq ([str, + (Expr)])) {str, 1, Expr, +} Prerequisite Match p i q j roots {program, Fragment } p 1 q 1 {ω, Fragment } roots {program, Program} p 1 q 2 {function, Function} p 2 q 3 {str, str, expr, Expr} {str, str} p 3 q 5 p 4 q 4 {int, int} {expr, Expr, str, str} p 5 q 8 {apply, Expr 3 } {expr, Expr, str, str} p 8 q 11 {expr, Expr} p 6 q 6 {binary, Expr 1 } {expr, Expr} p 9 q 9 {operator, Ops} {expr, Expr} p 7 q 7 {cond, Expr 2 } {expr, Expr} p 10 q 10 Table 2. On the left: production rules of the servant grammar for FL, derived from the XML schema, with their production signatures. On the right: the process of derivation of the nominal resolution relation p i q j. Note how two hypotheses must be formed and one of them rejected, because this servant grammar has two roots and both need to be checked for prodsig-equivalence with the root of the master grammar. Other than that, all production rules are matched with strong equivalence. V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

43 Nominal resolution example Production rule r 1 =p, Program, + (Function) Production signature {Function, +} r 2 =p(, Function, seq([name, +(Name), {CR, +, Expr, 1, Expr, +(CR)])) Name, 1+} r 3 =p(, Expr, Expr 1 ) {Expr 1, 1} r 4 =p(, Expr, Expr 2 ) {Expr 2, 1} r 5 =p(, Expr, Expr 3 ) {Expr 3, 1} r 6 =p(, Expr, Name) {Name, 1} r 7 =p(, Expr, Int) {Int, 1} r 8 =p(, Expr 1, seq ([Expr, Ops, Expr])) {Ops, 1, Expr, 11} r 9 =p(, Expr 2, seq ([Name, + (Expr)])) {Expr, +, Name, 1} r 10 =p(, Expr 3, seq ([Expr, Expr, Expr])) {Expr, 111} Prerequisite Match p i r j roots {program, Program} p 1 r 1 {function, Function} p 2 r 2 {ω, CR, str, Name, expr, Expr} {str, Name} p 3 r 6 p 4 r 7 {int, Int} {expr, Expr, str, Name} p 5 r 4 {apply, Expr 2 } {expr, Expr, p 8 r 9 str, Name} {expr, Expr} {expr, Expr} p 7 r 5 p 10 r 10 {cond, Expr 3 } {expr, Expr} p 6 r 3 {binary, Expr 1 } {expr, Expr} p 9 r 8 {operator, Ops} Table 3. On the left: production rules of the servant grammar for FL, derived from a corresponding SDF syntax definition, with their production signatures. On the right: the process of derivation of the nominal resolution relation p i r j. Note how a special lexical nonterminal for CR nonterminal remains unmatched due to weak equivalence of production rules that contain it. V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

44 Abstract Normal Form (1) lack of labels for production rules (2) lack of named subexpressions (3) lack of terminal symbols (4) maximal outward factoring of inner choices (5) lack of horizontal production rules (6) lack of separator lists (7) lack of trivially defined nonterminals (with α, ε or φ) (8) no mixing of chain and non-chain production rules (9) the nonterminal call graph is connected, and its top nonterminals are the starting symbols of the grammar V. Zaytsev, Guided Grammar Convergence, CoRR abs/ , draft for 2013.

45 Grammar design mutation Deyaccification B = C B C vs. B = C+ Layers vs. priorities X = Y; Y = X; vs X = ; Associativity A O A vs. A (O A)*

46 Unresolved Aggregation Master grammar exp: Meaningful chain rules Master grammar exp: STR exp + exp op exp Ecore ApplyExp: Function Exp + he master grammar, function application is defi Ecore BinaryExp: PlusExp BinaryExp: MinusExp BinaryExp: EqualExp PlusExp: Exp Exp MinusExp: Exp Exp EqualExp: Exp Exp

47 Megamodel

48

49 Grammar transformation composition

50 Adaptation through tolerance V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

51 Adaptation through tolerance V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

52 Adaptation through tolerance V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

53 Adaptation through tolerance V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

54 Adaptation through adjustment V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

55 Adaptation through adjustment V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

56 Adaptation through adjustment V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

57 Adaptation through adjustment V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

58 Grammar transformations Suite of well-defined well-studied operators Partial evaluation of transformation operators Classic grammar transformation: inapplicable? error! halt! vacuous? error! halt! transform! next!

59 Negotiated transformations Negotiated grammar transformation: applicable & non-vacuous? transform! next! vacuous? suggest to do nothing! not applicable? suggest better arguments! keep negotiating until applicability or surrender V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

60 Negotiated transformations Variability limits as a part of transformation command Interactive transformation (ask the user) Display a warning and proceed with minimal adjustment Proceed with one, save other options for fallback Halt and recomment V. Zaytsev, Negotiated Grammar Transformation. Draft for XM 2012.

61 CWI To summarise Grammars define structure Too much stuff in the grammar Decomposition Grammarware works on grammars & languages Composition Adjacent topics?

62 Questions?

of Grammarware by Grammar Transformation

of Grammarware by Grammar Transformation Maintenance and Evolution of Grammarware by Grammar Transformation IPA Spring Days on Model-Driven Software Engineering Vadim Zaytsev, SWAT, CWI 2012 Grammarware Language: Java import types.*; import

More information

Grammar Convergence. Ralf Lämmel and Vadim Zaytsev Software Languages Team Universität Koblenz-Landau. 13 февраля 2009 г.

Grammar Convergence. Ralf Lämmel and Vadim Zaytsev Software Languages Team Universität Koblenz-Landau. 13 февраля 2009 г. Grammar Convergence Ralf Lämmel and Vadim Zaytsev Software Languages Team Universität Koblenz-Landau 1 What is grammar convergence? Think of scattered grammar knowledge (say, in language documentation,

More information

C ASE STUDIES IN B IDIRECTIONALISATION

C ASE STUDIES IN B IDIRECTIONALISATION 15TH INTL. SYMPOSIUM ON TRENDS IN FUNCTIONAL PROGRAMMING C ASE STUDIES IN B IDIRECTIONALISATION V ADIM ZAYTSEV A. K. A. @GRAMMARWARE PART 1 OF 3 B IDIRECTIONAL TRANSFORMATIONS F ROM FP TO BX: UNIDIRECTIONAL

More information

... is a Programming Environment (PE)?... is Generic Language Technology (GLT)?

... is a Programming Environment (PE)?... is Generic Language Technology (GLT)? Introduction to Generic Language Technology Today Mark van den Brand Paul Klint Jurgen Vinju Tools for software analysis and manipulation Programming language independent (parametric) The story is from

More information

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341)

CSE 413 Languages & Implementation. Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) CSE 413 Languages & Implementation Hal Perkins Winter 2019 Structs, Implementing Languages (credits: Dan Grossman, CSE 341) 1 Goals Representing programs as data Racket structs as a better way to represent

More information

UPTR - a simple parse tree representation format

UPTR - a simple parse tree representation format UPTR - a simple parse tree representation format Jurgen Vinju Software Transformation Systems October 22, 2006 Quality of Software Transformation Systems Some Questions on Parsing Two pragmatical steps

More information

Syntax and Grammars 1 / 21

Syntax and Grammars 1 / 21 Syntax and Grammars 1 / 21 Outline What is a language? Abstract syntax and grammars Abstract syntax vs. concrete syntax Encoding grammars as Haskell data types What is a language? 2 / 21 What is a language?

More information

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation

9/5/17. The Design and Implementation of Programming Languages. Compilation. Interpretation. Compilation vs. Interpretation. Hybrid Implementation Language Implementation Methods The Design and Implementation of Programming Languages Compilation Interpretation Hybrid In Text: Chapter 1 2 Compilation Interpretation Translate high-level programs to

More information

LECTURE 3. Compiler Phases

LECTURE 3. Compiler Phases LECTURE 3 Compiler Phases COMPILER PHASES Compilation of a program proceeds through a fixed series of phases. Each phase uses an (intermediate) form of the program produced by an earlier phase. Subsequent

More information

A Simple Syntax-Directed Translator

A Simple Syntax-Directed Translator Chapter 2 A Simple Syntax-Directed Translator 1-1 Introduction The analysis phase of a compiler breaks up a source program into constituent pieces and produces an internal representation for it, called

More information

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail.

1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. Code No: R05320502 Set No. 1 1. Explain the input buffer scheme for scanning the source program. How the use of sentinels can improve its performance? Describe in detail. 2. Construct predictive parsing

More information

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ

Specifying Syntax. An English Grammar. Components of a Grammar. Language Specification. Types of Grammars. 1. Terminal symbols or terminals, Σ Specifying Syntax Language Specification Components of a Grammar 1. Terminal symbols or terminals, Σ Syntax Form of phrases Physical arrangement of symbols 2. Nonterminal symbols or syntactic categories,

More information

The Meta-Environment. A Language Workbench for Source code Analysis, Visualization and Transformation. Jurgen Vinju IPA herfstdagen 2008

The Meta-Environment. A Language Workbench for Source code Analysis, Visualization and Transformation. Jurgen Vinju IPA herfstdagen 2008 The Meta-Environment A Language Workbench for Source code Analysis, Visualization and Transformation Jurgen Vinju IPA herfstdagen 2008 Overview Goal of The Meta-Environment Methods of The Meta-Environment

More information

Book. Signatures and grammars. Signatures and grammars. Syntaxes. The 4-layer architecture

Book. Signatures and grammars. Signatures and grammars. Syntaxes. The 4-layer architecture Book Generic Language g Technology (2IS15) Syntaxes Software Language g Engineering g by Anneke Kleppe (Addison Wesley) Prof.dr. Mark van den Brand / Faculteit Wiskunde en Informatica 13-9-2011 PAGE 1

More information

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Winter /15/ Hal Perkins & UW CSE C-1 CSE P 501 Compilers Parsing & Context-Free Grammars Hal Perkins Winter 2008 1/15/2008 2002-08 Hal Perkins & UW CSE C-1 Agenda for Today Parsing overview Context free grammars Ambiguous grammars Reading:

More information

Pretty-Printing for Software Reengineering

Pretty-Printing for Software Reengineering Pretty-Printing for Software Reengineering Merijn de Jonge CWI P.O. Box 94079, 1090 GB Amsterdam, The Netherlands Merijn.de.Jonge@cwi.nl Abstract Automatic software reengineerings change or repair existing

More information

Grammar Engineering Support for Precedence Rule Recovery and Compatibility Checking

Grammar Engineering Support for Precedence Rule Recovery and Compatibility Checking Electronic Notes in Theoretical Computer Science 203 (2008) 85 101 www.elsevier.com/locate/entcs Grammar Engineering Support for Precedence Rule Recovery and Compatibility Checking Eric Bouwers a,1 Martin

More information

REFLECTIONS ON OPERATOR SUITES

REFLECTIONS ON OPERATOR SUITES REFLECTIONS ON OPERATOR SUITES FOR REFACTORING AND EVOLUTION Ralf Lämmel, VU & CWI, Amsterdam joint work with Jan Heering, CWI QUESTIONS What s the distance between refactoring and evolution? What are

More information

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413

Type Inference Systems. Type Judgments. Deriving a Type Judgment. Deriving a Judgment. Hypothetical Type Judgments CS412/CS413 Type Inference Systems CS412/CS413 Introduction to Compilers Tim Teitelbaum Type inference systems define types for all legal programs in a language Type inference systems are to type-checking: As regular

More information

Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2

Formal Languages and Grammars. Chapter 2: Sections 2.1 and 2.2 Formal Languages and Grammars Chapter 2: Sections 2.1 and 2.2 Formal Languages Basis for the design and implementation of programming languages Alphabet: finite set Σ of symbols String: finite sequence

More information

Language Standardization Needs Grammarware

Language Standardization Needs Grammarware Language Standardization Needs Grammarware Steven Klusener, Vadim Zaytsev Vrije Universiteit, De Boelelaan 1081a, NL-1081 HV Amsterdam Email: {steven,vadim}@cs.vu.nl September 21, 2005 Abstract The ISO

More information

Grammars and Parsing. Paul Klint. Grammars and Parsing

Grammars and Parsing. Paul Klint. Grammars and Parsing Paul Klint Grammars and Languages are one of the most established areas of Natural Language Processing and Computer Science 2 N. Chomsky, Aspects of the theory of syntax, 1965 3 A Language...... is a (possibly

More information

Question Bank. 10CS63:Compiler Design

Question Bank. 10CS63:Compiler Design Question Bank 10CS63:Compiler Design 1.Determine whether the following regular expressions define the same language? (ab)* and a*b* 2.List the properties of an operator grammar 3. Is macro processing a

More information

Rascal: A DSL for SCAM

Rascal: A DSL for SCAM Rascal: A DSL for SCAM Jurgen Vinju Tijs van der Storm Paul Klint Amsterdam, The Netherlands Hall of fame Bob Fuhrer Emilie Balland Arnold Lankamp Bas Basten The complexity of bridging an analysis tool

More information

Renaud Durlin. May 16, 2007

Renaud Durlin. May 16, 2007 A comparison of different approaches EPITA Research and Development Laboratory (LRDE) http://www.lrde.epita.fr May 16, 2007 1 / 25 1 2 3 4 5 2 / 25 1 2 3 4 5 3 / 25 Goal Transformers:

More information

CA Compiler Construction

CA Compiler Construction CA4003 - Compiler Construction Semantic Analysis David Sinclair Semantic Actions A compiler has to do more than just recognise if a sequence of characters forms a valid sentence in the language. It must

More information

Language engineering and Domain Specific Languages

Language engineering and Domain Specific Languages Language engineering and Domain Specific Languages Perdita Stevens School of Informatics University of Edinburgh Plan 1. Defining languages 2. General purpose languages vs domain specific languages 3.

More information

Plan. Language engineering and Domain Specific Languages. Language designer defines syntax. How to define language

Plan. Language engineering and Domain Specific Languages. Language designer defines syntax. How to define language Plan Language engineering and Domain Specific Languages Perdita Stevens School of Informatics University of Edinburgh 1. Defining languages 2. General purpose languages vs domain specific languages 3.

More information

Compiling Techniques

Compiling Techniques Lecture 2: The view from 35000 feet 19 September 2017 Table of contents 1 2 Passes Representations 3 Instruction Selection Register Allocation Instruction Scheduling 4 of a compiler Source Compiler Machine

More information

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1

CSE P 501 Compilers. Parsing & Context-Free Grammars Hal Perkins Spring UW CSE P 501 Spring 2018 C-1 CSE P 501 Compilers Parsing & Context-Free Grammars Hal Perkins Spring 2018 UW CSE P 501 Spring 2018 C-1 Administrivia Project partner signup: please find a partner and fill out the signup form by noon

More information

Domain-Specific Languages for Composable Editor Plugins

Domain-Specific Languages for Composable Editor Plugins Domain-Specific Languages for Composable Editor Plugins LDTA 2009, York, UK Lennart Kats (me), Delft University of Technology Karl Trygve Kalleberg, University of Bergen Eelco Visser, Delft University

More information

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF)

Chapter 3: Describing Syntax and Semantics. Introduction Formal methods of describing syntax (BNF) Chapter 3: Describing Syntax and Semantics Introduction Formal methods of describing syntax (BNF) We can analyze syntax of a computer program on two levels: 1. Lexical level 2. Syntactic level Lexical

More information

SEN. Software Engineering. Software ENgineering. A type-driven approach to concrete meta programming. J.J. Vinju

SEN. Software Engineering. Software ENgineering. A type-driven approach to concrete meta programming. J.J. Vinju C e n t r u m v o o r W i s k u n d e e n I n f o r m a t i c a SEN Software Engineering Software ENgineering A type-driven approach to concrete meta programming J.J. Vinju REPORT SEN-E0507 APRIL 2005

More information

Compiling Regular Expressions COMP360

Compiling Regular Expressions COMP360 Compiling Regular Expressions COMP360 Logic is the beginning of wisdom, not the end. Leonard Nimoy Compiler s Purpose The compiler converts the program source code into a form that can be executed by the

More information

Chapter 4. Lexical and Syntax Analysis. Topics. Compilation. Language Implementation. Issues in Lexical and Syntax Analysis.

Chapter 4. Lexical and Syntax Analysis. Topics. Compilation. Language Implementation. Issues in Lexical and Syntax Analysis. Topics Chapter 4 Lexical and Syntax Analysis Introduction Lexical Analysis Syntax Analysis Recursive -Descent Parsing Bottom-Up parsing 2 Language Implementation Compilation There are three possible approaches

More information

G53CMP: Lecture 4. Syntactic Analysis: Parser Generators. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 4 p.1/32

G53CMP: Lecture 4. Syntactic Analysis: Parser Generators. Henrik Nilsson. University of Nottingham, UK. G53CMP: Lecture 4 p.1/32 G53CMP: Lecture 4 Syntactic Analysis: Parser Generators Henrik Nilsson University of Nottingham, UK G53CMP: Lecture 4 p.1/32 This Lecture Parser generators ( compiler compilers ) The parser generator Happy

More information

Lecture 3 Local Optimizations, Intro to SSA

Lecture 3 Local Optimizations, Intro to SSA Lecture 3 Local Optimizations, Intro to SSA I. Basic blocks & Flow graphs II. Abstraction 1: DAG III. Abstraction 2: Value numbering IV. Intro to SSA ALSU 8.4-8.5, 6.2.4 Phillip B. Gibbons 15-745: Local

More information

UNIT I INTRODUCTION TO COMPILER 1. What is a Complier? A Complier is a program that reads a program written in one language-the source language-and translates it in to an equivalent program in another

More information

CMSC 330: Organization of Programming Languages

CMSC 330: Organization of Programming Languages CMSC 330: Organization of Programming Languages Context Free Grammars and Parsing 1 Recall: Architecture of Compilers, Interpreters Source Parser Static Analyzer Intermediate Representation Front End Back

More information

Chapter 4. Abstract Syntax

Chapter 4. Abstract Syntax Chapter 4 Abstract Syntax Outline compiler must do more than recognize whether a sentence belongs to the language of a grammar it must do something useful with that sentence. The semantic actions of a

More information

Project 1: Scheme Pretty-Printer

Project 1: Scheme Pretty-Printer Project 1: Scheme Pretty-Printer CSC 4101, Fall 2017 Due: 7 October 2017 For this programming assignment, you will implement a pretty-printer for a subset of Scheme in either C++ or Java. The code should

More information

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation

Context-Free Grammar. Concepts Introduced in Chapter 2. Parse Trees. Example Grammar and Derivation Concepts Introduced in Chapter 2 A more detailed overview of the compilation process. Parsing Scanning Semantic Analysis Syntax-Directed Translation Intermediate Code Generation Context-Free Grammar A

More information

Compositional Model Based Software Development

Compositional Model Based Software Development Compositional Model Based Software Development Prof. Dr. Bernhard Rumpe http://www.se-rwth.de/ Seite 2 Our Working Groups and Topics Automotive / Robotics Autonomous driving Functional architecture Variability

More information

CSCE 314 Programming Languages

CSCE 314 Programming Languages CSCE 314 Programming Languages Syntactic Analysis Dr. Hyunyoung Lee 1 What Is a Programming Language? Language = syntax + semantics The syntax of a language is concerned with the form of a program: how

More information

CS2112 Fall Assignment 4 Parsing and Fault Injection. Due: March 18, 2014 Overview draft due: March 14, 2014

CS2112 Fall Assignment 4 Parsing and Fault Injection. Due: March 18, 2014 Overview draft due: March 14, 2014 CS2112 Fall 2014 Assignment 4 Parsing and Fault Injection Due: March 18, 2014 Overview draft due: March 14, 2014 Compilers and bug-finding systems operate on source code to produce compiled code and lists

More information

CMPT 379 Compilers. Parse trees

CMPT 379 Compilers. Parse trees CMPT 379 Compilers Anoop Sarkar http://www.cs.sfu.ca/~anoop 10/25/07 1 Parse trees Given an input program, we convert the text into a parse tree Moving to the backend of the compiler: we will produce intermediate

More information

Introduction to Model Driven Engineering using Eclipse. Frameworks

Introduction to Model Driven Engineering using Eclipse. Frameworks Introduction to Model Driven Engineering using Eclipse Model Driven Development Generator s Bruce Trask Angel Roman MDE Systems Abstraction Model Driven Development Refinement 1 Part I Agenda What is Model

More information

Introduction to Compiler Construction

Introduction to Compiler Construction Introduction to Compiler Construction Robert van Engelen http://www.cs.fsu.edu/~engelen/courses/cop5621 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2005 Syllabus

More information

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 06 A LR parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 06 A LR parsing Görel Hedin Revised: 2017-09-11 This lecture Regular expressions Context-free grammar Attribute grammar Lexical analyzer (scanner) Syntactic analyzer (parser)

More information

Semantics driven disambiguation A comparison of different approaches

Semantics driven disambiguation A comparison of different approaches Semantics driven disambiguation A comparison of different approaches Clément Vasseur Technical Report n o 0416, 12 2004 revision 656 Context-free grammars allow the specification

More information

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters

CMSC 330: Organization of Programming Languages. Architecture of Compilers, Interpreters : Organization of Programming Languages Context Free Grammars 1 Architecture of Compilers, Interpreters Source Scanner Parser Static Analyzer Intermediate Representation Front End Back End Compiler / Interpreter

More information

22c:111 Programming Language Concepts. Fall Syntax III

22c:111 Programming Language Concepts. Fall Syntax III 22c:111 Programming Language Concepts Fall 2008 Syntax III Copyright 2007-08, The McGraw-Hill Company and Cesare Tinelli. These notes were originally developed by Allen Tucker, Robert Noonan and modified

More information

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS

RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 INSTRUCTIONS RYERSON POLYTECHNIC UNIVERSITY DEPARTMENT OF MATH, PHYSICS, AND COMPUTER SCIENCE CPS 710 FINAL EXAM FALL 96 STUDENT ID: INSTRUCTIONS Please write your student ID on this page. Do not write it or your name

More information

Scannerless Boolean Parsing

Scannerless Boolean Parsing LDTA 2006 Preliminary Version Scannerless Boolean Parsing Adam Megacz Computer Science UC Berkeley Abstract Scannerless generalized parsing techniques allow parsers to be derived directly from unified,

More information

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis CS 1622 Lecture 2 Lexical Analysis CS 1622 Lecture 2 1 Lecture 2 Review of last lecture and finish up overview The first compiler phase: lexical analysis Reading: Chapter 2 in text (by 1/18) CS 1622 Lecture

More information

Time : 1 Hour Max Marks : 30

Time : 1 Hour Max Marks : 30 Total No. of Questions : 6 P4890 B.E/ Insem.- 74 B.E ( Computer Engg) PRINCIPLES OF MODERN COMPILER DESIGN (2012 Pattern) (Semester I) Time : 1 Hour Max Marks : 30 Q.1 a) Explain need of symbol table with

More information

Compilers Course Lecture 4: Context Free Grammars

Compilers Course Lecture 4: Context Free Grammars Compilers Course Lecture 4: Context Free Grammars Example: attempt to define simple arithmetic expressions using named regular expressions: num = [0-9]+ sum = expr "+" expr expr = "(" sum ")" num Appears

More information

This book is licensed under a Creative Commons Attribution 3.0 License

This book is licensed under a Creative Commons Attribution 3.0 License 6. Syntax Learning objectives: syntax and semantics syntax diagrams and EBNF describe context-free grammars terminal and nonterminal symbols productions definition of EBNF by itself parse tree grammars

More information

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward

Lexical Analysis. COMP 524, Spring 2014 Bryan Ward Lexical Analysis COMP 524, Spring 2014 Bryan Ward Based in part on slides and notes by J. Erickson, S. Krishnan, B. Brandenburg, S. Olivier, A. Block and others The Big Picture Character Stream Scanner

More information

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur

VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur VALLIAMMAI ENGNIEERING COLLEGE SRM Nagar, Kattankulathur 603203. DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING Year & Semester : III & VI Section : CSE 1 & 2 Subject Code : CS6660 Subject Name : COMPILER

More information

CSE 3302 Programming Languages Lecture 2: Syntax

CSE 3302 Programming Languages Lecture 2: Syntax CSE 3302 Programming Languages Lecture 2: Syntax (based on slides by Chengkai Li) Leonidas Fegaras University of Texas at Arlington CSE 3302 L2 Spring 2011 1 How do we define a PL? Specifying a PL: Syntax:

More information

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler. More detailed overview of compiler front end Structure of a compiler Today we ll take a quick look at typical parts of a compiler. This is to give a feeling for the overall structure. source program lexical

More information

Declarative Language Definition

Declarative Language Definition Declarative Language Definition (state-of-the-art & research agenda) Eelco Visser http://eelcovisser.org IPA Spring Days 2012 Garderen, Netherlands Software Engineering Problem Domain Machine bridging

More information

More Assigned Reading and Exercises on Syntax (for Exam 2)

More Assigned Reading and Exercises on Syntax (for Exam 2) More Assigned Reading and Exercises on Syntax (for Exam 2) 1. Read sections 2.3 (Lexical Syntax) and 2.4 (Context-Free Grammars) on pp. 33 41 of Sethi. 2. Read section 2.6 (Variants of Grammars) on pp.

More information

An Evaluation of Domain-Specific Language Technologies for Code Generation

An Evaluation of Domain-Specific Language Technologies for Code Generation An Evaluation of Domain-Specific Language Technologies for Code Generation Christian Schmitt, Sebastian Kuckuk, Harald Köstler, Frank Hannig, Jürgen Teich Hardware/Software Co-Design, System Simulation,

More information

Lexical Scanning COMP360

Lexical Scanning COMP360 Lexical Scanning COMP360 Captain, we re being scanned. Spock Reading Read sections 2.1 3.2 in the textbook Regular Expression and FSA Assignment A new assignment has been posted on Blackboard It is due

More information

Overture Architecture & Status

Overture Architecture & Status Overture Architecture & Status Peter Gorm Larsen & Marcel Verhoef (updated 28 Nov 2006) OVERTURE ARCHITECTURE Overture versus VDMTools VDMTools (http://www.vdmtools.jp/en) Closed source, proprietary (available

More information

Derivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012

Derivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012 Derivations vs Parses Grammar is used to derive string or construct parser Context ree Grammars A derivation is a sequence of applications of rules Starting from the start symbol S......... (sentence)

More information

Introduction to Compiler Construction

Introduction to Compiler Construction Introduction to Compiler Construction Robert van Engelen http://www.cs.fsu.edu/~engelen/courses/cop5621 COP5621 Compiler Construction Copyright Robert van Engelen, Florida State University, 2007-2011 Syllabus

More information

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis CSE450 Translation of Programming Languages Lecture 4: Syntax Analysis http://xkcd.com/859 Structure of a Today! Compiler Source Language Lexical Analyzer Syntax Analyzer Semantic Analyzer Int. Code Generator

More information

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria

CS152 Programming Language Paradigms Prof. Tom Austin, Fall Syntax & Semantics, and Language Design Criteria CS152 Programming Language Paradigms Prof. Tom Austin, Fall 2014 Syntax & Semantics, and Language Design Criteria Lab 1 solution (in class) Formally defining a language When we define a language, we need

More information

Infrastructure for Program Transformation Systems

Infrastructure for Program Transformation Systems Master Course Program Transformation 2004-2005 Martin Bravenboer Institute of Information & Computing Sciences Utrecht University, The Netherlands February 10, 2005 Planet Stratego/XT Stratego Language

More information

Parsing II Top-down parsing. Comp 412

Parsing II Top-down parsing. Comp 412 COMP 412 FALL 2018 Parsing II Top-down parsing Comp 412 source code IR Front End Optimizer Back End IR target code Copyright 2018, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled

More information

Compiler Design Concepts. Syntax Analysis

Compiler Design Concepts. Syntax Analysis Compiler Design Concepts Syntax Analysis Introduction First task is to break up the text into meaningful words called tokens. newval=oldval+12 id = id + num Token Stream Lexical Analysis Source Code (High

More information

Introduction to Dependable Systems: Meta-modeling and modeldriven

Introduction to Dependable Systems: Meta-modeling and modeldriven Introduction to Dependable Systems: Meta-modeling and modeldriven development http://d3s.mff.cuni.cz CHARLES UNIVERSITY IN PRAGUE faculty of mathematics and physics 3 Software development Automated software

More information

BNF WAS HERE: What Have We Done About the Unnecessary Diversity of Notation for Syntactic Definitions

BNF WAS HERE: What Have We Done About the Unnecessary Diversity of Notation for Syntactic Definitions BNF WAS HERE: What Have We Done About the Unnecessary Diversity of Notation for Syntactic Definitions Vadim Zaytsev Software Analysis and Transformation Team, Centrum Wiskunde en Informatica, Amsterdam,

More information

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones

Type Inference. Prof. Clarkson Fall Today s music: Cool, Calm, and Collected by The Rolling Stones Type Inference Prof. Clarkson Fall 2016 Today s music: Cool, Calm, and Collected by The Rolling Stones Review Previously in 3110: Interpreters: ASTs, evaluation, parsing Formal syntax Formal semantics

More information

The Syntax Definition Formalism SDF

The Syntax Definition Formalism SDF Mark van den Brand Paul Klint Jurgen Vinju 2007-10-22 17:18:09 +0200 (Mon, 22 Oct 2007) Table of Contents An Introduction to SDF... 2 Why use SDF?... 2 How to use SDF... 4 Learning more... 4 This document...

More information

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING

PRINCIPLES OF COMPILER DESIGN UNIT I INTRODUCTION TO COMPILING PRINCIPLES OF COMPILER DESIGN 2 MARKS UNIT I INTRODUCTION TO COMPILING 1. Define compiler? A compiler is a program that reads a program written in one language (source language) and translates it into

More information

CPS 506 Comparative Programming Languages. Syntax Specification

CPS 506 Comparative Programming Languages. Syntax Specification CPS 506 Comparative Programming Languages Syntax Specification Compiling Process Steps Program Lexical Analysis Convert characters into a stream of tokens Lexical Analysis Syntactic Analysis Send tokens

More information

COP4020 Programming Languages. Semantics Prof. Robert van Engelen

COP4020 Programming Languages. Semantics Prof. Robert van Engelen COP4020 Programming Languages Semantics Prof. Robert van Engelen Overview Static semantics Dynamic semantics Attribute grammars Abstract syntax trees COP4020 Spring 2011 2 Static Semantics Syntax concerns

More information

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1 Defining Program Syntax Chapter Two Modern Programming Languages, 2nd ed. 1 Syntax And Semantics Programming language syntax: how programs look, their form and structure Syntax is defined using a kind

More information

Midterm 2 Solutions Many acceptable answers; one was the following: (defparameter g1

Midterm 2 Solutions Many acceptable answers; one was the following: (defparameter g1 Midterm 2 Solutions 1. [20 points] Consider the language that consist of possibly empty lists of the identifier x enclosed by parentheses and separated by commas. The language includes { () (x) (x,x) (x,x,x)

More information

DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING UNIT -1-INTRODUCTION TO COMPILERS 2 MARK QUESTIONS

DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING UNIT -1-INTRODUCTION TO COMPILERS 2 MARK QUESTIONS BHARATHIDASAN ENGINEERING COLLEGE DEPARTMENT OF INFORMATION TECHNOLOGY / COMPUTER SCIENCE AND ENGINEERING Year & Semester : III & VI Degree & Branch : B.E (CSE) /B.Tech (Information Technology) Subject

More information

Syntax Analysis/Parsing. Context-free grammars (CFG s) Context-free grammars vs. Regular Expressions. BNF description of PL/0 syntax

Syntax Analysis/Parsing. Context-free grammars (CFG s) Context-free grammars vs. Regular Expressions. BNF description of PL/0 syntax Susan Eggers 1 CSE 401 Syntax Analysis/Parsing Context-free grammars (CFG s) Purpose: determine if tokens have the right form for the language (right syntactic structure) stream of tokens abstract syntax

More information

Disambiguation Filters for Scannerless Generalized LR Parsers

Disambiguation Filters for Scannerless Generalized LR Parsers Disambiguation Filters for Scannerless Generalized LR Parsers M.G.J. van den Brand 1,4, J. Scheerder 2, J.J. Vinju 1, and E. Visser 3 1 Centrum voor Wiskunde en Informatica (CWI), Kruislaan 413, 1098 SJ

More information

Disambiguation Filters for Scannerless Generalized LR Parsers

Disambiguation Filters for Scannerless Generalized LR Parsers Disambiguation Filters for Scannerless Generalized LR Parsers Mark G. J. van den Brand 1,4, Jeroen Scheerder 2, Jurgen J. Vinju 1, and Eelco Visser 3 1 Centrum voor Wiskunde en Informatica (CWI) Kruislaan

More information

Spoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT

Spoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT Spoofax: An Extensible, Interactive Development Environment for Program Transformation with Stratego/XT Karl Trygve Kalleberg 1 Department of Informatics, University of Bergen, P.O. Box 7800, N-5020 BERGEN,

More information

Specification and Automated Detection of Code Smells using OCL

Specification and Automated Detection of Code Smells using OCL Specification and Automated Detection of Code Smells using OCL Tae-Woong Kim 1, Tae-Gong Kim 2 and Jai-Hyun Seu 3 School of Computer Engineering, Inje University, Obang-dong 607, Gimhae, Gyeong-Nam, Korea

More information

Compiling and Interpreting Programming. Overview of Compilers and Interpreters

Compiling and Interpreting Programming. Overview of Compilers and Interpreters Copyright R.A. van Engelen, FSU Department of Computer Science, 2000 Overview of Compilers and Interpreters Common compiler and interpreter configurations Virtual machines Integrated programming environments

More information

Model-Driven Engineering (MDE) Lecture 1: Metamodels and Xtext Regina Hebig, Thorsten Berger

Model-Driven Engineering (MDE) Lecture 1: Metamodels and Xtext Regina Hebig, Thorsten Berger Model-Driven Engineering (MDE) Lecture 1: Metamodels and Xtext Regina Hebig, Thorsten Berger Reuses some material from: Andrzej Wasowski, Model-Driven Development, ITU Copenhagen Where I am from WASP 2017

More information

Part I: Multiple Choice Questions (40 points)

Part I: Multiple Choice Questions (40 points) Preparatory Course Grammars and Parsing Friday, November 11, 2005 (9:00-12:00 This exam consists of 10 multiple-choice questions (Part I and 3 open questions (Part II. The maximum number of points for

More information

Announcements. Written Assignment 1 out, due Friday, July 6th at 5PM.

Announcements. Written Assignment 1 out, due Friday, July 6th at 5PM. Syntax Analysis Announcements Written Assignment 1 out, due Friday, July 6th at 5PM. xplore the theoretical aspects of scanning. See the limits of maximal-munch scanning. Class mailing list: There is an

More information

Data Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong.

Data Abstraction. An Abstraction for Inductive Data Types. Philip W. L. Fong. Data Abstraction An Abstraction for Inductive Data Types Philip W. L. Fong pwlfong@cs.uregina.ca Department of Computer Science University of Regina Regina, Saskatchewan, Canada Introduction This lecture

More information

Context-free grammars (CFG s)

Context-free grammars (CFG s) Syntax Analysis/Parsing Purpose: determine if tokens have the right form for the language (right syntactic structure) stream of tokens abstract syntax tree (AST) AST: captures hierarchical structure of

More information

Syntax-Directed Translation

Syntax-Directed Translation Syntax-Directed Translation What is syntax-directed translation? The compilation process is driven by the syntax. The semantic routines perform interpretation based on the syntax structure. Attaching attributes

More information

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised:

EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing. Görel Hedin Revised: EDAN65: Compilers, Lecture 04 Grammar transformations: Eliminating ambiguities, adapting to LL parsing Görel Hedin Revised: 2017-09-04 This lecture Regular expressions Context-free grammar Attribute grammar

More information

UNIT -1 1.1 OVERVIEW OF LANGUAGE PROCESSING SYSTEM 1.2 Preprocessor A preprocessor produce input to compilers. They may perform the following functions. 1. Macro processing: A preprocessor may allow a

More information

CS /534 Compiler Construction University of Massachusetts Lowell

CS /534 Compiler Construction University of Massachusetts Lowell CS 91.406/534 Compiler Construction University of Massachusetts Lowell Professor Li Xu Fall 2004 Lab Project 2: Parser and Type Checker for NOTHING Due: Sunday, November 14, 2004, 11:59 PM 1 Introduction

More information

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher

COP4020 Programming Languages. Compilers and Interpreters Robert van Engelen & Chris Lacher COP4020 ming Languages Compilers and Interpreters Robert van Engelen & Chris Lacher Overview Common compiler and interpreter configurations Virtual machines Integrated development environments Compiler

More information