The TXL Programming Language Filippo Ricca ITC-Irst Istituto per la ricerca Scientifica e Tecnologica

Slides:



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

1 Mariano Ceccato FBK Fondazione Bruno Kessler The TXL Programming Language (2)
Chapter 2-2 A Simple One-Pass Compiler
CPSC 388 – Compiler Design and Construction
1 Programming Languages (CS 550) Mini Language Interpreter Jeremy R. Johnson.
Semantics Static semantics Dynamic semantics attribute grammars
Printf transformation in TXL Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
1 Programming Languages (CS 550) Lecture Summary Functional Programming and Operational Semantics for Scheme Jeremy R. Johnson.
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.
Fall Semantics Juan Carlos Guzmán CS 3123 Programming Languages Concepts Southern Polytechnic State University.
1 Contents Introduction A Simple Compiler Scanning – Theory and Practice Grammars and Parsing LL(1) Parsing LR Parsing Lex and yacc Semantic Processing.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
The TXL Programming Language Filippo Ricca ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
Yu-Chen Kuo1 Chapter 2 A Simple One-Pass Compiler.
The TXL Programming Language Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
Chapter 2 A Simple Compiler
UMBC Introduction to Compilers CMSC 431 Shon Vick 01/28/02.
(2.1) Grammars  Definitions  Grammars  Backus-Naur Form  Derivation – terminology – trees  Grammars and ambiguity  Simple example  Grammar hierarchies.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
1 Syntax and Semantics The Purpose of Syntax Problem of Describing Syntax Formal Methods of Describing Syntax Derivations and Parse Trees Sebesta Chapter.
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
CSc 453 Semantic Analysis Saumya Debray The University of Arizona Tucson.
Syntax Directed Definitions Synthesized Attributes
1 Abstract Syntax Tree--motivation The parse tree –contains too much detail e.g. unnecessary terminals such as parentheses –depends heavily on the structure.
CPSC 388 – Compiler Design and Construction Parsers – Context Free Grammars.
1 Chapter 5 LL (1) Grammars and Parsers. 2 Naming of parsing techniques The way to parse token sequence L: Leftmost R: Righmost Top-down  LL Bottom-up.
Language Translators - Lee McCluskey LANGUAGE TRANSLATORS: WEEK 21 LECTURE: Using JavaCup to create simple interpreters
CS Describing Syntax CS 3360 Spring 2012 Sec Adapted from Addison Wesley’s lecture notes (Copyright © 2004 Pearson Addison Wesley)
Context-Free Grammars and Parsing
Supported by ELTE IKKK, Ericsson Hungary, in cooperation with University of Kent Erlang refactoring with relational database Anikó Víg and Tamás Nagy Supervisors:
TextBook Concepts of Programming Languages, Robert W. Sebesta, (10th edition), Addison-Wesley Publishing Company CSCI18 - Concepts of Programming languages.
Semantics. Semantics is a precise definition of the meaning of a syntactically and type-wise correct program. Ideas of meaning: –Operational Semantics.
CPS 506 Comparative Programming Languages Syntax Specification.
ISBN Chapter 3 Describing Semantics.
Chapter 3 Part II Describing Syntax and Semantics.
D Goforth COSC Translating High Level Languages Note error in assignment 1: #4 - refer to Example grammar 3.4, p. 126.
Chapter 3 Describing Syntax and Semantics
1 A Simple Syntax-Directed Translator CS308 Compiler Theory.
Semantic Values and Symbol Tables © Allan C. Milne Abertay University v
CS412/413 Introduction to Compilers Radu Rugina Lecture 13 : Static Semantics 18 Feb 02.
06/03/2007 The TXL Programming Language (4) 1 Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
Overview of Previous Lesson(s) Over View 3 Model of a Compiler Front End.
1 Programming Languages (CS 550) Lecture 2 Summary Mini Language Interpreter Jeremy R. Johnson.
Chap. 7, Syntax-Directed Compilation J. H. Wang Nov. 24, 2015.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
Programming Languages Meeting 3 September 9/10, 2014.
CS 403: Programming Languages Lecture 20 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
PPL Syntax & Formal Semantics Lecture Notes: Chapter 2.
Compiler Design Lecture 10 Semantic Analysis. int aintegers int a[2][3]array(2, array(3, integer)) int f(int, float, char) int x float x char  int Int.
The TXL Programming Language Filippo Ricca & Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
Chapter 3 – Describing Syntax
Describing Syntax and Semantics
System Software Unit-1 (Language Processors) A TOY Compiler
A Simple Syntax-Directed Translator
Introduction to Parsing (adapted from CS 164 at Berkeley)
Chapter 3 – Describing Syntax
Syntax Specification and Analysis
Ch. 4 – Semantic Analysis Errors can arise in syntax, static semantics, dynamic semantics Some PL features are impossible or infeasible to specify in grammar.
Organization of Programming Languages
Syntax versus Semantics
Compiler Construction (CS-636)
Syntax Questions 6. Define a left recursive grammar rule.
Mini Language Interpreter Programming Languages (CS 550)
CSE 3302 Programming Languages
R.Rajkumar Asst.Professor CSE
Chapter 3 Describing Syntax and Semantics.
Faculty of Computer Science and Information System
Presentation transcript:

The TXL Programming Language Filippo Ricca ITC-Irst Istituto per la ricerca Scientifica e Tecnologica

Recursive functions function fact replace [number] n [number] construct n_minus_one [number] n [- 1] where n [> 1] construct fact_minus_one [number] n_minus_one [fact] by n [* fact_minus_one] end function Recursion

Using rule parameters rule resolveConstants replace [repeat statement] ‘const C [id] = V [expr] RestOfscope [repeat statement] by RestOfScope [replaceByValue C V] end rule rule replaceByValue ConstName [id] Value [expr] replace [primary] ConstName by (Value) end rule Example: Const Pi = 3.14; Area := r*r*Pi; Area := r*r*3.14; Parameters

Deconstruct and searching functions rule vectorizeScalarAssignments replace [repeat statement] C1 [statement] C2 [statement] rest [repeat statement] deconstruct C1 V1 [var] := E1 [expr]; deconstruct C2 V2 [var] := E2 [expr]; where not E2 [reference V1] where not E1 [reference V2] construct Passign [statement] := ; by Passign rest end rule function reference V [variable] match * [variable] V end function Example: x:=x+1; y:=t+4; := ; x:=x+1; y:=x+4; No!

Working with Global Variables  Global variables are a rich and powerful feature that can be used for many distinct purposes, including: - global tables. - multiple results from a rule. - “deep” parameters. - “message-passing” communication between rules in a rule set (e.g, avoiding interference).

Setting Global Table  Global tables can be set up using an export clause before the replace clause in the main rule of a program. Example: function main export Table [repeat table_entry] “Veggie” -> “Cabbage” “Fruit” -> “Apple” “Fruit” -> “Orange” replace [program] P [program] by P [R1] end function define table_entry [stringlit] -> [stringlit] end define

Adding Table Entry  Global tables can be modified by exporting a new binding for the table based on the imported original binding. function addTableEntry import Table [repeat table_entry] … construct newEntry [table_entry] … export Table Table [. NewEntry] … end function Example:

Searching in a Table  Global tables can be easily queried using searching deconstructors. Example: deconstruct * [table_entry] Table Kind [stringlit] -> “Orange”  The binding for “Kind” will be the [stringlit] “Fruit”. If no match were to be found, then the deconstructor would fail.

Avoiding interference between rules function shiftByOne export Flag [id] ‘not_found replace [number] N [number] by N [replaceOneByTwo] [replaceTwoByThree] end function function replaceOneByTwo replace [number] 1 export Flag ‘found by 2 end function function replaceTwoByThree import Flag [id] deconstruct Flag ‘not_found replace [number] 2 by 3 end function 1 ---> 2 ---> > 3 We want:

Counting items in TXL  TXL can be used for counting items (i.e. LOCs, number of cycles, etc.). For example: given a tag-language counting the number of tags and end-tags. uno due tags: 2 end Tags: 1

% Tags grammar define program [repeat element] end define define element [Tag] | [endTag] | [id] end define define Tag end define define endTag end define % Count number of tag function main replace [program] P [program] construct ListTags [repeat Tag] _ [^ P] construct NumberTags [number] _ [countTag each ListTags] [printf] by end function R1 [^ X1] Replace R1 of type [repeat T] with a sequence consisting of every subtree of type [T] contained in X1.

function countTag A [Tag] replace [number] N [number] by N [+ 1] end function function printf match [number] N [number] construct PrintObj [number] N [print] end function print is a built-in function! Only pattern matching!

Using attributes TXL allows a grammar definition to have attributes associated with it: 1.Attributes act like optional non-terminals, but normally do not appear in the output (txl –attr force the print of all attributes). 2.Attributes may be added to the parse tree during transformations. 3.Attributes are denotated in the grammar by the nonterminal modifier attr.

define type ‘int | ‘string end define define typed_id [id] [attr type] end define function InferType expr [expression] replace [typed_id] Id [id] deconstruct expr f [number] op [operator] s [number] by Id ‘int end function The attribute ‘type’ is Optional.

Remark 1.Several functions (or rules) may be applied to a scope in succession. For example: X [f][g][h] (the meaning is: h(g(f(X))) )

Exercises  Adding to the ‘expr-grammar’ the exponential i.e Exp(x, n). Computing the exponential: - in syntax way: ex. Exp(2, 3) ----> 2*2*2 - in semantic way: by means a recursive function that substitute at Exp(x, n) the correct value. 1+exp(3, 2) 1+3*

Homework  Implementing a simple version of “commands-language” where commands can be: - assignments i.e. [id] := [expr]; - declarations i.e. const [id] = [number];  Implementing some transformation rules (page 19) that substitute in the assignments identifiers with related values. Example: Const Pi = 3.14; Area := r*r*Pi; Area := r*r*3.14;