Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models.

Slides:



Advertisements
Similar presentations
Programming Language Concepts
Advertisements

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.
CPSC Compiler Tutorial 9 Review of Compiler.
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
ISBN Chapter 3 Describing Syntax and Semantics.
176 Formal Languages and Applications: We know that Pascal programming language is defined in terms of a CFG. All the other programming languages are context-free.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 2 Syntax A language that is simple to parse.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
Chapter3: Language Translation issues
Chapter 3 Describing Syntax and Semantics Sections 1-3.
Yu-Chen Kuo1 Chapter 2 A Simple One-Pass Compiler.
(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.
Invitation to Computer Science 5th Edition
2.2 A Simple Syntax-Directed Translator Syntax-Directed Translation 2.4 Parsing 2.5 A Translator for Simple Expressions 2.6 Lexical Analysis.
Compiler1 Chapter V: Compiler Overview: r To study the design and operation of compiler for high-level programming languages. r Contents m Basic compiler.
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.
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Syntax: 10/18/2015IT 3271 Semantics: Describe the structures of programs Describe the meaning of programs Programming Languages (formal languages) -- How.
C H A P T E R TWO Syntax and Semantic.
D. M. Akbar Hussain: Department of Software & Media Technology 1 Compiler is tool: which translate notations from one system to another, usually from source.
Unit-1 Introduction Prepared by: Prof. Harish I Rathod
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Review: Compiler Phases: Source program Lexical analyzer Syntax analyzer Semantic analyzer Intermediate code generator Code optimizer Code generator Symbol.
CPS 506 Comparative Programming Languages Syntax Specification.
Chapter 1 Introduction. Chapter 1 - Introduction 2 The Goal of Chapter 1 Introduce different forms of language translators Give a high level overview.
Overview of Previous Lesson(s) Over View  A program must be translated into a form in which it can be executed by a computer.  The software systems.
Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java.
The Functions and Purposes of Translators Syntax (& Semantic) Analysis.
Syntax (2).
Compiler Construction By: Muhammad Nadeem Edited By: M. Bilal Qureshi.
Syntax and Semantics Form and Meaning of Programming Languages Copyright © by Curt Hill.
 Fall Chart 2  Translators and Compilers  Textbook o Programming Language Processors in Java, Authors: David A. Watts & Deryck F. Brown, 2000,
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.
Compiler Construction CPCS302 Dr. Manal Abdulaziz.
Programming Language Concepts (CIS 635) Elsa L Gunter 4303 GITC NJIT,
LECTURE 3 Compiler Phases. COMPILER PHASES Compilation of a program proceeds through a fixed series of phases.  Each phase uses an (intermediate) form.
1 Asstt. Prof Navjot Kaur Computer Dept PRESENTED BY.
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.
Syntax Analysis Or Parsing. A.K.A. Syntax Analysis –Recognize sentences in a language. –Discover the structure of a document/program. –Construct (implicitly.
FG Group -Afrilia BP -Liana F.B.I -Maulidatun Nisa -Riza Amini F.
CC410: System Programming Dr. Manal Helal – Fall 2014 – Lecture 12–Compilers.
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
A Simple Syntax-Directed Translator
Compiler Lecture 1 CS510.
Introduction to C++ Programming
Review: Compiler Phases:
R.Rajkumar Asst.Professor CSE
CS 3304 Comparative Languages
Lecture 4: Lexical Analysis & Chomsky Hierarchy
CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics
CS 3304 Comparative Languages
Programming Languages 2nd edition Tucker and Noonan
Language Translation Issues
Language Translation Issues
High-Level Programming Language
Chapter 10: Compilers and Language Translation
Language Translation Issues
Language Translation Issues
Language Translation Issues
Faculty of Computer Science and Information System
Presentation transcript:

Chapter 3 Program translation1 Chapt. 3 Language Translation Syntax and Semantics Translation phases Formal translation models

Chapter 3 Program translation2 Syntax What is a valid string of the language? –First pass of a compiler Error messages (are they helpful?) –Compiler compiler (generator) such as YACC can automatically generate parser from BNF

Chapter 3 Program translation3 Good syntax criteria –Assist in Readability COBOL as self documenting Comments Length of identifiers Overloading of names –Examples of poor features for readability blank as concatenation operation in SNOBOL Identifier names in Basic –X1, Y Implicit typing Late binding

Chapter 3 Program translation4 Good syntax criteria(cont.) Assist in Writeability –Few and concise statements –Rich library–created by language and user –Support of abstraction –Orthogonality Examples of poor features for writeability –Large number of constructs –Lack of necessary constructs –Redundancy –Ambiguity Ex: if statement –Case sensitivity??

Chapter 3 Program translation5 Syntactic elements Character set –5, 6, 7, 8, 16 bit encoding schemes Identifiers –Symbols such as letters, digits, $, _, blank –Length limitation Operation symbols – various examples –LISP –prefix identifiers (ex: PLUS) –APL – special Greek characters –FORTRAN -.EQ.,.GT. –C - &&, == –Java & and &&, | and ||

Chapter 3 Program translation6 Syntactic elements (cont.) Keyword –identifier used as part of primitive program unit (ex: if, then, else, case) Reserved word –Keyword that cannot be assigned by programmer READ is not a reserved word in Pascal –Adding new reserved words to an update of a language can make old programs incorrect (upward compatability)

Chapter 3 Program translation7 Syntactic elements (cont.) Noise words –Used to improve readability-optional Ex: perform 5 [times] Comments –Used for documentation; readability Blanks –Completely ignored in FORTRAN Do 10 I = 1.5 Delimiters and brackets –Spaces, ;, paired ()[] {} begin end Fixed format vs free format

Chapter 3 Program translation8 Program Structure Expression –Precedence rules Statements –structured programming Modules/ functions/ subprograms/ classes –Nested units Static checks, efficient code for nonlocal references –Separate unit compilation. –Data and operations are compiled as a unit in classes –Interface issues – function specification to allow static checks (prototypes) –Specifications (.h files) separate from implementations

Chapter 3 Program translation9 Translation I- Lexical Analysis –Byte stream organized into lexemes, each of which is identified (tagged) –Numbers may be converted to binary –Identifiers are stored in symbol table –Tokens are output for syntactic analysis

Chapter 3 Program translation10 Translation II parsing – syntactic analysis Tokens organized into expressions, statements, etc. Is the input a valid string in the language? Generates parse tree, tables Produces error messages for invalid strings

Chapter 3 Program translation11 Translation III semantic analysis Produces error messages for invalid constructs –Ex: identifier not declared; type mismatch Compiled languages use and discard symbol table –Reference to variable as offset from data sections Information must be stored together with identifier (ex: type, range limitations) Macro substitutions Compiler directives –#define –#ifndef –Pragma suppress range_checks

Chapter 3 Program translation12 Translation IV optimization Semantic analysis output is typically one statement at a time Compiler can optimize code to optain results as efficient as assembly code –Ex:Save intermediate results in registers – remove constant operations from loop –Change 2-dimensional array storage Code generations Linking and Loading

Chapter 3 Program translation13 BNF (Backus Normal/Naur Form) Metalanguage ::= defined as | alternative <> nonterminal {} later introduced for iteration [] for optional sequence is implicit ex: ::= | ::= 0|1|2|3|4|5|6|7|8|9

Chapter 3 Program translation14 Context Free Grammars For balanced parenthesis S  SS | (S) | () Problem: generate a parse tree for a string such as (()(()))((())()) from above Some language definition issues are context sensitive, such as: each identifier must be declared before use Implementation issues such as Pass by value or reference

Chapter 3 Program translation15 Syntax Charts Term at top left is defined by the following graph Graph branches for alternative Empty branch for optional Box around string for nonterminal Circle for terminal Arrow back for iteration ex: p. 96 in text Sequence is explicit

Chapter 3 Program translation16 Finite-State Automata Table used for lexical analysis Ex: valid floating point number (note that limitations on range and precision are not specified) (whole part)  (decimal)  (fractional)  (exp)  (exp value) Where whole part, fractional, and exp value have a looping arrow Digit is input to whole part. is input leading to decimal Digit leads from decimal to fractional E leads from fractional to exp Digit leads from exp to exp value