Printf transformation in TXL Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica

Slides:



Advertisements
Similar presentations
Chapter 11 Introduction to Programming in C
Advertisements

Etter/Ingber Engineering Problem Solving with C Fundamental Concepts Chapter 2 Simple C Programs.
1 Mariano Ceccato FBK Fondazione Bruno Kessler The TXL Programming Language (2)
printf() Documentation info:
Character String Manipulation. Overview Character string functions sscanf() function sprintf() function.
Character String Manipulation. Overview Character string functions sscanf() function snprintf() function.
Chapter 2: Using Objects Part 1. To learn about variables To understand the concepts of classes and objects To be able to call methods To learn about.
Expressions ► An expression can be a single variable, or can include a series of variables. If an expression includes multiple variables they are combined.
Primitive Variable types Basic types –char (single character or ASCII integer value) –int (integer) –short (not longer than int) –long (longer than int)
41 A Depth Program #include int main(void) { int inches, feet, fathoms; //declarations fathoms = 7; feet = 6 * fathoms; inches = 12 * feet; printf(“Wreck.
Differences between Java and C CS-2303, C-Term Differences between Java and C CS-2303, System Programming Concepts (Slides include materials from.
Display a 12-Month Calendar CS-2301 D-term Programming Assignment #2 12-Month Calendar CS-2301 System Programming C-term 2009 (Slides include materials.
More on Numerical Computation CS-2301 B-term More on Numerical Computation CS-2301, System Programming for Non-majors (Slides include materials from.
1 Chapter 2 Introductory Programs. 2 Getting started To create and run a Java program –Create a text file with a.java extension for the source code. For.
Chapter 9 Formatted Input/Output Acknowledgment The notes are adapted from those provided by Deitel & Associates, Inc. and Pearson Education Inc.
1 Data types, operations, and expressions Overview l Format of a Java Application l Primitive Data Types l Variable Declaration l Arithmetic Operations.
C Formatted Input/Output /* Using Integer Conversion Specifiers */ #include int main ( ) { printf( "%d\n", 455 ); printf( "%i\n", 455 ); printf( "%d\n",
The printf Method The printf method is another way to format output. It is based on the printf function of the C language. System.out.printf(,,,..., );
EG280 - CS for Engineers Chapter 2, Introduction to C Part I Topics: Program structure Constants and variables Assignment Statements Standard input and.
11 Chapter 3 DECISION STRUCTURES CONT’D. 22 FORMATTING FLOATING-POINT VALUES WITH THE DecimalFormat CLASS We can use the DecimalFormat class to control.
 Pearson Education, Inc. All rights reserved Formatted Output.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Copyright © 2012 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 2 Input, Processing, and Output.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Sales person receive RM200/week plus 9% of their gross sales for that week. Write an algorithms to calculate the sales person’s earning from the input.
Chapter 3 Processing and Interactive Input. 2 Assignment  The general syntax for an assignment statement is variable = operand; The operand to the right.
CNG 140 C Programming Lecture Notes 2 Processing and Interactive Input Spring 2007.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Integer numerical data types. The integer data types The integer data types use the binary number system as encoding method There are a number of different.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Chapter 2 – Continued Basic Elements of Java. Chapter Objectives Type Conversion String Class Commonly Used String Methods Parsing Numeric Strings Commonly.
Chapter 2: Java Fundamentals Type conversion,String.
An Introduction to Java Programming and Object-Oriented Application Development Chapter 7 Characters, Strings, and Formatting.
Parse & Syntax Trees Syntax & Semantic Errors Mini-Lecture.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Operations on Strings. 8/8/2005 Copyright 2006, by the authors of these slides, and Ateneo de Manila University. All rights reserved L: String Manipulation.
Introducing Python CS 4320, SPRING Lexical Structure Two aspects of Python syntax may be challenging to Java programmers Indenting ◦Indenting is.
Lecture 2 Objectives Learn about objects and reference variables.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
CSC141 Introduction to Computer Programming Teacher: AHMED MUMTAZ MUSTEHSAN Lecture - 6.
Strings And other things. Strings Overview The String Class and its methods The char data type and Character class StringBuilder, StringTokenizer classes.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
06/03/2007 The TXL Programming Language (4) 1 Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
1 Predefined Classes and Objects Chapter 3. 2 Objectives You will be able to:  Use predefined classes available in the Java System Library in your own.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
CS 1704 Introduction to Data Structures and Software Engineering.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
Files A collection of related data treated as a unit. Two types Text
C is a high level language (HLL)
The TXL Programming Language Filippo Ricca ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
1 C Syntax and Semantics Dr. Sherif Mohamed Tawfik Lecture Two.
The TXL Programming Language Filippo Ricca & Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica
28 Formatted Output.
Information and Computer Sciences University of Hawaii, Manoa
A bit of C programming Lecture 3 Uli Raich.
File Access (7.5) CSE 2031 Fall July 2018.
Introduction to C CSE 2031 Fall /3/ :33 AM.
Chapter 7: Introduction to CLIPS
Java Programming: From Problem Analysis to Program Design, 4e
John Carelli, Instructor Kutztown University
Input and Output Lecture 4.
Chapter 08- printf and scanf
Conversions of the type of the value of an expression
Starting JavaProgramming
Lecture 13 Input/Output Files.
Chapter 2: Basic Elements of Java
Programming Assignment #1 12-Month Calendar—
By C. Shing ITEC Dept Radford University
Outline Creating Objects The String Class The Random and Math Classes
Introduction to C CSE 2031 Fall /15/2019 8:26 AM.
Presentation transcript:

Printf transformation in TXL Mariano Ceccato ITC-Irst Istituto per la ricerca Scientifica e Tecnologica

The Problem  printf is a c construct to print formatted output  java does not support a similar syntax  every printf should be converted to the appropriate java output command (automatically?) printf("Vertices:\tV = %d\n", V); System.out.print("Vertices:\tV =" + V + "\n");

Where the differences  printf uses a formatting language  this language is not parsed by TXL  a stringlit is a token, not a tree: we can not uses construct/deconstruct on it we have to modify the string by hand [expression_statement] "Vertices:\tV = %d\n"Vprintf);(

printf syntax Symbolmeaning -left adjustment numberminimum field width.separation numberprecision h, lint as a short or long Conversion character Result d, idecimal number ounsigned octal x, Xunsigned hex uunsigned decimal csingle character schar * fdouble [-]m.dddddd e, E double [-]m.dddddd e  xx g, Gwith no trailing zeros pvoid * % %

Where the problems  Behavior is type-dependent precision holds different meaning in case of string, floating point or integer  Between % and conversion character there is an (optional) variable size formatter command

Solution  Solution: resolve a restricted problem “%d” formatter only not apply to any other formatter command substitute the formatter command with the appropriate value

Index operator  N1 [index T1 T2] T1 and T2 are [stringlit] N1 is [number] it returns the index of the first instance of the text T2 in T1 it returns zero if none found N1 [index "hello, hello world" "lo"] returns 4 N1 [index "hello, hello world" "lo w"] returns 11 N1 [index "hello, hello world" "%d"] returns 0 (not found)

String manipulation  T1 [: N1 N2] T1 is [stringlit] N1 and N2 are [number] it returns the sub-string of T1 from char N1 to N2 inclusive, 1-origin T1 = "hello, hello world" T1 [: 1 5] returns "hello" T1 [: 14 18] returns "world"

String length  N1 [# T1] T1 is [stringlit] N1 is [number] it returns the length of T1 T1 = "hello, hello world" N1 [# T1] returns 18

Breaking the string construct position [number] _ [index the_string "%d"] [- 1] construct first_string [stringlit] the_string [: 1 position] construct L [number] _ [# the_string] construct rest [number] position [+ 2] [+ 1] construct second_string [stringlit] the_string[: rest L] printf(" Vertices:\tV = %d \n", V); first(1)1619last(21)

Building the new statement replace [expression_statement] 'printf '( the_string [stringlit]', values [list assignment_expression] ') ';... deconstruct values first_argument [assignment_expression] ', rest_argument [list assignment_expression] construct final_expression [binary_expression] first_string '+ '( first_argument ') '+ second_string construct result [expression_statement] 'System '. 'out '. 'print '( final_expression ') '; System.out.print(" Vertices:\tV =" + ( V ) + " \n");

Extension 1  In case of multiple “%d” call a recursive function on second_string  The recursion ends when the parameter list is empty printf("BoundingBox: %d, %d, %d, %d\n", xmin, ymin, xmax, ymax); System.out.print ("BoundingBox: " + (xmin) + ", " + (ymin) + ", " + (xmax) + ", " + (ymax) + "\n");

Extension 2  Take a copy of the function and modify it to catch the case of standard error output fprintf(stderr, "...", list); System.err.print ("..."); replace [expression_statement] 'fprintf '( 'stderr the_string [stringlit]', values [list assignment_expression] ') ';... construct result [expression_statement] 'System '. 'err '. 'print '( final_expression ') ';

Summarizing  TXL does not parse stringlit into a tree  Focus on a simpler sub-problem (this solves the 71% of the occurrences)  Use #, : and index string operators  Break the string in two segments  Construct a new expression using the sub-string and the first parameter  Apply the transformation recursively to the second sub-string  Copy and modify the rule to solve stderr