The TXL Programming Language Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica

Slides:



Advertisements
Similar presentations
1 Mariano Ceccato FBK Fondazione Bruno Kessler The TXL Programming Language (2)
Advertisements

Semantics Static semantics Dynamic semantics attribute grammars
ICE1341 Programming Languages Spring 2005 Lecture #6 Lecture #6 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Printf transformation in TXL Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
ICE1341 Programming Languages Spring 2005 Lecture #5 Lecture #5 In-Young Ko iko.AT. icu.ac.kr iko.AT. icu.ac.kr Information and Communications University.
Slide1 Chapter 4 Lexical and Syntax Analysis. slide2 OutLines: In this chapter a major topics will be discussed : Introduction to lexical analysis, including.
A basis for computer theory and A means of specifying languages
The TXL Programming Language Filippo Ricca ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
Slide 1 Chapter 2-b Syntax, Semantics. Slide 2 Syntax, Semantics - Definition The syntax of a programming language is the form of its expressions, statements.
Compiler Design Lexical Analysis Syntactical Analysis Semantic Analysis Optimization Code Generation.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
Slide 1 Chapter 3 Attribute Grammars. Slide 2 Attribute Grammars Certain language structures cannot be described using EBNF. Attribute grammars are extensions.
Yu-Chen Kuo1 Chapter 2 A Simple One-Pass Compiler.
CS 330 Programming Languages 09 / 16 / 2008 Instructor: Michael Eckmann.
Chapter 2 A Simple Compiler
BİL744 Derleyici Gerçekleştirimi (Compiler Design)1.
Describing Syntax and Semantics
UMBC Introduction to Compilers CMSC 431 Shon Vick 01/28/02.
CSE 413 Programming Languages & Implementation Hal Perkins Autumn 2012 Context-Free Grammars and Parsing 1.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
CSE 341, S. Tanimoto Concepts 1- 1 Programming Language Concepts Formal Syntax Paradigms Data Types Polymorphism.
Chapter 17 Programming Tools The Architecture of Computer Hardware and Systems Software: An Information Technology Approach 3rd Edition, Irv Englander.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
Course Revision Contents  Compilers  Compilers Vs Interpreters  Structure of Compiler  Compilation Phases  Compiler Construction Tools  A Simple.
Syntax & Semantic Introduction Organization of Language Description Abstract Syntax Formal Syntax The Way of Writing Grammars Formal Semantic.
C++ Code Analysis: an Open Architecture for the Verification of Coding Rules Paolo Tonella ITC-irst, Centro per la Ricerca Scientifica e Tecnologica
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Chapter 10: Compilers and Language Translation Invitation to Computer Science, Java Version, Third Edition.
A Survey of Rewriting Strategies in Program Transformation Systems Part 1 Author: Eelco Visser Speaker: Wei Zhao.
Winter 2007SEG2101 Chapter 71 Chapter 7 Introduction to Languages and Compiler.
Syntax Specification and BNF © Allan C. Milne Abertay University v
Concordia University Department of Computer Science and Software Engineering Click to edit Master title style COMPILER DESIGN Review Joey Paquet,
Joey Paquet, Lecture 12 Review. Joey Paquet, Course Review Compiler architecture –Lexical analysis, syntactic analysis, semantic.
C H A P T E R TWO Syntax and Semantic.
Interpretation Environments and Evaluation. CS 354 Spring Translation Stages Lexical analysis (scanning) Parsing –Recognizing –Building parse tree.
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Chapter 2. Design of a Simple Compiler J. H. Wang Sep. 21, 2015.
CPS 506 Comparative Programming Languages Syntax Specification.
Compiler design Lecture 1: Compiler Overview Sulaimany University 2 Oct
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
Chapter 3 Part II Describing Syntax and Semantics.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 3: Introduction to Syntactic Analysis.
Compiler Design Introduction 1. 2 Course Outline Introduction to Compiling Lexical Analysis Syntax Analysis –Context Free Grammars –Top-Down Parsing –Bottom-Up.
Programming Languages and Design Lecture 2 Syntax Specifications of Programming Languages Instructor: Li Ma Department of Computer Science Texas Southern.
06/03/2007 The TXL Programming Language (4) 1 Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
CSC 4181 Compiler Construction
C H A P T E R T W O Syntax and Semantic. 2 Introduction Who must use language definitions? Other language designers Implementors Programmers (the users.
©SoftMoore ConsultingSlide 1 Structure of Compilers.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
The TXL Programming Language Filippo Ricca ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
CS416 Compiler Design1. 2 Course Information Instructor : Dr. Ilyas Cicekli –Office: EA504, –Phone: , – Course Web.
The TXL Programming Language Filippo Ricca & Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Advanced programming language theory. week 2. Attribute grammars and semantics.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
Chapter 3 – Describing Syntax
Lexical and Syntax Analysis
CS416 Compiler Design lec00-outline September 19, 2018
Introduction CI612 Compiler Design CI612 Compiler Design.
CSE401 Introduction to Compiler Construction
R.Rajkumar Asst.Professor CSE
CS416 Compiler Design lec00-outline February 23, 2019
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
Faculty of Computer Science and Information System
Compiler design Review COMP 442/6421 – Compiler Design
Presentation transcript:

The TXL Programming Language Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica

2 What is TXL?  TXL is a programming language specifically designed to support software analysis and program transformation.  The TXL programming language is a functional rule-based language. example: functional rule-based program functions: F(x) = x-1; G(x) = x+1; rules: If x<5 then x:=G(x); Flow execution is not sequential! If x>5 then x:=F(x); If x=5 then stop;

3 Program Transformations  Program transformation is the act of changing one program into another. source language Ltarget language L’ PP’ L is different to L’ ----> translation L is equal to L’ -----> rephrasing transformation

4 What is TXL good for (1)?  Translation Aspect Language High-level Language 1 High-level Language 2 Low-level Language analysis migration reverse engineering synthesis

5 Translations  Program synthesis: compilation, code generation, …  Program migration: porting a Pascal program to C, translation between dialects (Fortran77 to Fortran90), …  Reverse engineering: architecture extraction, design recovery, …  Program analysis: measurement, clone detection, type inference, call graph, control flow graph, …

6 Reverse engineering Java code Class A; Class B; Class C, Example: design recovery Class Diagram A C B * Reverse engineering

7 Program analysis  Example: clone analysis … 20: FOR I=1 TO 10 30: V[I] = V[I] +1; 40: PRINT V[I] 50: ENDFOR 60: PRINT X; 70: CALL F; … 100: FOR J=1 TO : W[J] = W[J] +1; 120: PRINT W[J] 130: ENDFOR … Lines and ; … Clones:

8 What is TXL good for (2) Rephrasing:  Normalization: reduces a program to a program in a sub- language to decrease its syntactic complexity (ex. Pascal to “core Pascal”).  Optimization: improves the run-time and/or space performance of a program (ex. Code motion optimization).  Refactoring or restructuring: changes the structure of the program to make it easier to understand.  Renovation: Error repair (ex. Year 2000) and changed requirements (ex. “lira” to “euro”). Does not preserve semantics.

9 Optimization Example: Code motion optimization: moves all loop- independent assignment statements outside of loops. Loop x := a + b; y := x; a := y + 3; x := b + c; y := x – 2; z := x + a * y; End loop x4 := b + c; y2 := x4 – 2; Loop x := a + b; y := x; a := y + 3; z := x4 + a * y2; End loop Code motion optimization

10 Restructuring  Example: goto elimination f := 0; A_0: if x >n goto B_3; x := x –1; f := f * x; goto A_0; B_3: print f f := 0; while x <=n do x := x –1; f := f * x; end while print f goto elimination

11 TXL Components  A description of the structure to be transformed specified as an EBNF grammar, in context-free ambiguos form.  A set of Transformation Rules specified by example, using pattern/replacement pairs. Each TXL program has two components:

12 Syntax definition  A grammar G describes the syntax of a language.  L(G) is the language defined by the grammar G.  Usually a grammar G is given in (E)BNF notation. Example: E --> E + E | E * E | 0 | 1| 2 0+1*2 is in L(E) 3+0 is not in L(E) non-terminalterminal

13 BNF vs. EBNF List --> List Element ; List --> Element ; Element --> number Element --> word Element --> word sign word List --> ((word [sign word] | number) ; )* BNF EBNF

14 Parse Tree vs. AST E --> E + E | E * E | 0 | 1| 2 E EE * 1 Parse tree + * 01 2 Abstract syntax tree E E

15 Ambiguity  A grammar that produces more than one parse tree for some term is said to be ambiguos. Example: E --> E + E | E * E | 0 | 1| 2 is ambiguos. 0+1*2 has two parse tree.

16 Ambiguity E --> E + E | E * E | 0 | 1| 2 E EE * *2 E EE + * 0 E E 1 2 EE

17 Transformation rules - A transformation rule is a rule of then form: Lhs ----> Rhs if cond where Lhs and Rhs are term patterns the condition is optional - The application of a rule to a term succeds if the term matches (pattern matching) with the Lhs pattern and the condition is true. - The result is the instantiation of the Rhs pattern. For example, if we have the term: and applying the rule: x > x to it the result is 3 (the pattern variable x match the number 3)

18 The three phases of TXL txl “input file” “txl file” Parse Transform Unparse Input textParse tree Transformed parse tree Output text “blue fish” [words] [word] [words] blue [word][empty] fish [words] [word] marlin [empty] “marlin”

19 First example: ‘expr’ grammar % BNF: Expr --> Num | Expr+Expr | Expr*Expr | (Expr) % Part I. Syntax specification define program [Expr] end define define Expr [number] | [Expr] ‘+ [Expr] | [Expr] ‘* [Expr] | ‘( [Expr] ‘) end define

20 First example: rules rule removePlusZero replace [Expr] N [number] ‘+ ‘0 by N end rule rule resolveBracketedExpressions replace [Expr] ‘( N [number] ‘) by N end rule N + 0N (N)N

21 First example: main rule % Part 2: main rule rule main replace [Expr] E [Expr] construct NewE [Expr] E [removePlusZero] [resolveBracketedExpr] where not NewE [= E] by NewE end rule *: Expr +: Expr 1: number 9: number 0: number *: Expr 9: number1: number NewE E

22 First example:parsing txl –Dparse es.txt Expr.Grm 9+0Program Expr + number Input Parse Tree Output Parse Tree

23 First example: transforming Txl –Dapply es.txt Expr.txl Transforming … ==> 9 [removePlusZero] (9) ==> 9 [resolveBracketedExpressions] (9 + 0) * 1 ==> 9 * 1 [main] 9 * 1 ==> 9 [removeMultiplicationByOne] 9 * 1 ==> 9 [main] 9 Input: (9+0) * 1

24 First example: unparsing  [NL] force a new line of output.  [IN] indent all following output lines by four spaces.  [EX] exdent all following output lines by four spaces. Example: define Procedure [id] [Parameters] [NL] [IN] ‘begin [NL] [IN] [body] [NL] [EX] ‘ end [NL] [EX] end define

25 Exercises  Download the TXL manual (  Create the TXL directory.  Write in TXL the ambiguous expr-language (+, *, -, /)  Check the parse tree of: 0+1*9  Write in Txl the rules: removePluszero, removeMinusZero, removeMultiplicationbyOne, removeDivisionbyOne, resolveMultiplicationbyZero, resolveBracketedExpr, X +X -- ->2*X, X/X ---->1.  Test the txl program with: (((3*0)+4)+4)*(5/5).  Think (and implement) a possible formatting of the ambiguous expr-language.

26 Homework Write in TXL the non-ambiguous expr-language (+, *, -, /) Check the parse tree of: 0+1*9 Adapt the rules: removePluszero, removeMinusZero, removeMultiplicationbyOne, removeDivisionbyOne, resolveMultiplicationbyZero, resolveBracketedExpr, X +X --->2*X, X/X ---->1. Test the txl program with: (((3*0)+4)+4)*(5/5). Think (and implement) a possible formatting of the non- ambiguous expr-language.