Chapter3: Language Translation issues

Slides:



Advertisements
Similar presentations
COMPILER CONSTRUCTION
Advertisements

Programming Language Concepts
Software & Services Group, Developer Products Division Copyright© 2010, Intel Corporation. All rights reserved. *Other brands and names are the property.
Compilers and Language Translation
Chapter 2 Syntax. Syntax The syntax of a programming language specifies the structure of the language The lexical structure specifies how words can be.
Yu-Chen Kuo1 Chapter 1 Introduction to Compiling.
Structure of a C program
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.
Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.
1.3 Executing Programs. How is Computer Code Transformed into an Executable? Interpreters Compilers Hybrid systems.
ECE 265 – LECTURE 9 PROGRAM DESIGN 8/12/ ECE265.
CSC 8310 Programming Languages Meeting 2 September 2/3, 2014.
Invitation to Computer Science 5th Edition
ICS611 Introduction to Compilers Set 1. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
INTRODUCTION TO COMPUTING CHAPTER NO. 06. Compilers and Language Translation Introduction The Compilation Process Phase 1 – Lexical Analysis Phase 2 –
COP4020 Programming Languages
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.
Programming With C.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Chapter 2. C++ Program Structure C++ program is a collection of subprograms Subprograms in C++ are called FUNCTIONS Each function performs a specific.
Copyright © 2012 Pearson Education, Inc. Chapter 2: Introduction to C++
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1.  10% Assignments/ class participation  10% Pop Quizzes  05% Attendance  25% Mid Term  50% Final Term 2.
BASICS CONCEPTS OF ‘C’.  C Character Set C Character Set  Tokens in C Tokens in C  Constants Constants  Variables Variables  Global Variables Global.
Algorithms  Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
CPS 506 Comparative Programming Languages Syntax Specification.
1 Compiler Construction (CS-636) Muhammad Bilal Bashir UIIT, Rawalpindi.
Chapter 1 Introduction Study Goals: Master: the phases of a compiler Understand: what is a compiler Know: interpreter,compiler structure.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Chapter 1 Introduction Major Data Structures in Compiler
DOCUMENTATION SECTION GLOBAL DECLARATION SECTION
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
1 Compiler & its Phases Krishan Kumar Asstt. Prof. (CSE) BPRCE, Gohana.
Language Translation Issues General Syntactic Criteria.
C H A P T E R T W O Linking Syntax And Semantics Programming Languages – Principles and Paradigms by Allen Tucker, Robert Noonan.
First Compilation Rudra Dutta CSC Spring 2007, Section 001.
Compilers Computer Symbol Table Output Scanner (lexical analysis)
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
An overview of C Language. Overview of C C language is a general purpose and structured programming language developed by 'Dennis Ritchie' at AT &T's.
ICS312 Introduction to Compilers Set 23. What is a Compiler? A compiler is software (a program) that translates a high-level programming language to machine.
Overview of Compilation Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 2.
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Introduction to Computer Programming Concepts M. Uyguroğlu R. Uyguroğlu.
FG Group -Afrilia BP -Liana F.B.I -Maulidatun Nisa -Riza Amini F.
Chapter 3 – Describing Syntax CSCE 343. Syntax vs. Semantics Syntax: The form or structure of the expressions, statements, and program units. Semantics:
2.1 The Part of a C++ Program. The Parts of a C++ Program // sample C++ program #include using namespace std; int main() { cout
Component 1.6.
System Software Unit-1 (Language Processors) A TOY Compiler
Lexical Analysis.
Algorithms Problem: Write pseudocode for a program that keeps asking the user to input integers until the user enters zero, and then determines and outputs.
Objectives Identify the built-in data types in C++
PROGRAMMING LANGUAGES
Introduction to C Topics Compilation Using the gcc Compiler
CS 3304 Comparative Languages
CS 3304 Comparative Languages
Language Translation Issues
Chapter 2: Introduction to C++.
Language Translation Issues
High-Level Programming Language
The C Language: Intro.
Chapter 10: Compilers and Language Translation
Language Translation Issues
Language Translation Issues
Language Translation Issues
Presentation transcript:

Chapter3: Language Translation issues Programming language Syntax Key criteria concerning syntax Basic syntactic concepts Overall Program-Subprogram structure Stages in Translation Analysis of the source program Synthesis of the object program Bootstrapping

What is Syntax The syntax of a programming language describes the structure of programs without any consideration of their meaning.

Key criteria concerning syntax Readability – a program is considered readable if the algorithm and data are apparent by inspection. Writeability – ease of writing the program. Verifiability – ability to prove program correctness (very difficult issue) Translatability – ease of translating the program into executable form. Lack of ambiguity – the syntax should provide for ease of avoiding ambiguous structures

Basic syntactic concepts Character set – The alphabet of the language. Several different character sets are used: ASCII, EBCIDIC, Unicode Identifiers – strings of letters of digits usually beginning with a letter Operator Symbols – +-*/ Keywords or Reserved Words – used as a fixed part of the syntax of a statement

Basic syntactic concepts Noise words – optional words inserted into statements to improve readability Comments – used to improve readability and for documentation purposes. Comments are usually enclosed by special markers Blanks – rules vary from language to language. Usually only significant in literal strings

Basic syntactic concepts Delimiters – used to denote the beginning and the end of syntactic constructs Expressions – functions that access data objects in a program and return a value Statements – these are the sentences of the language, they describe a task to be performed

Overall Program-Subprogram Structure Separate subprogram definitions: Separate compilation, linked at load time E.G. C/C++ Separate data definitions: General approach in OOP. Nested subprogram definitions: Subprogram definitions appear as declarations within the main program or other subprograms. E.G. Pascal

Overall Program-Subprogram Structure Separate interface definitions: C/C++ header files Data descriptions separated from executable statements. A centralized data division contains all data declarations. E.G. COBOL Unseparated subprogram definitions: No syntactic distinction between main program statements and subprogram statements. E.G BASIC

Stages in Translation Analysis of the source program Synthesis of the object program Bootstrapping

Analysis of the source program Lexical analysis (scanning) – identifying the tokens of the programming language: keywords, identifiers, constants and other symbols In the program void main() { printf("Hello World\n"); } the tokens are void, main, (, ), {, printf, (, "Hello World\n", ), ;, }

Syntactic and semantic analysis Syntactic analysis (parsing) – determining the structure of the program, as defined by the language grammar. Semantic analysis - assigning meaning to the syntactic structures Example: int variable1; meaning: 4 bytes for variable1 , a specific set of operations to be used with variable1.

Basic semantic tasks The semantic analysis builds the bridge between analysis and synthesis. Basic semantic tasks: Symbol–table maintenance Insertion of implicit information Error detection Macro processing Result : an internal representation, suitable to be used for code optimization and code generation.

Synthesis of the object program Three main steps: Optimization - Removing redundant statements Code generation - generating assembler commands with relative memory addresses for the separate program modules - obtaining the object code of the program. Linking and loading - resolving the addresses - obtaining the executable code of the program.

Optimization example Statements in yellow can be removed Assembler code not optimized: LOAD_R B ADD_R C STORE_R Temp1 LOAD_R Temp1 ADD_R D STORE_R Temp2 LOAD_R Temp2 STORE_R A Intermediate code: Temp1 = B + C Temp2 = Temp1 + D A = Temp2 Statements in yellow can be removed

Bootstrapping The compiler for a given language can be written in the same language. a program that translates some internal representation into assembler code the programmer manually re-writes the compiler into the internal representation, using the algorithm that is encoded into the compiler. From there on the internal representation is translated into assembler and then into machine language.