Chapter 2. Chapter 2 Topics. Chapter 2 Topics (continued) Evolution of the Major Programming Languages

Similar documents
03 - Lexical Analysis

CSCI 3136 Principles of Programming Languages

Lecture 1: Introduction

Chapter 1. Dr. Chris Irwin Davis Phone: (972) Office: ECSS CS-4337 Organization of Programming Languages

Language Evaluation Criteria. Evaluation Criteria: Readability. Evaluation Criteria: Writability. ICOM 4036 Programming Languages

What is a programming language?

CSE 307: Principles of Programming Languages

Compilers. Introduction to Compilers. Lecture 1. Spring term. Mick O Donnell: michael.odonnell@uam.es Alfonso Ortega: alfonso.ortega@uam.

Programming Languages

Principles of Programming Languages Topic: Introduction Professor Louis Steinberg

Lexical analysis FORMAL LANGUAGES AND COMPILERS. Floriano Scioscia. Formal Languages and Compilers A.Y. 2015/2016

Compiler I: Syntax Analysis Human Thought

Chapter 5 Names, Bindings, Type Checking, and Scopes

Programming Assignment II Due Date: See online CISC 672 schedule Individual Assignment

CSE 130 Programming Language Principles & Paradigms

Announcements FORTRAN ALGOL COBOL. Simula & Smalltalk. Programming Languages

1/20/2016 INTRODUCTION

Compiler Construction

Chapter 6: Programming Languages

COURSE CODE: CSC 411 Organization of Programming Languages

5HFDOO &RPSLOHU 6WUXFWXUH

Lecture 9. Semantic Analysis Scoping and Symbol Table

CSC4510 AUTOMATA 2.1 Finite Automata: Examples and D efinitions Definitions

CSC Software II: Principles of Programming Languages

COMP 356 Programming Language Structures Notes for Chapter 4 of Concepts of Programming Languages Scanning and Parsing

Compiler Construction

n Introduction n Art of programming language design n Programming language spectrum n Why study programming languages? n Overview of compilation

Parsing Technology and its role in Legacy Modernization. A Metaware White Paper

Static vs. Dynamic. Lecture 10: Static Semantics Overview 1. Typical Semantic Errors: Java, C++ Typical Tasks of the Semantic Analyzer

Lexical Analysis and Scanning. Honors Compilers Feb 5 th 2001 Robert Dewar

Programming Languages CIS 443

Scoping (Readings 7.1,7.4,7.6) Parameter passing methods (7.5) Building symbol tables (7.6)

Evolution of the Major Programming Languages

Name: Class: Date: 9. The compiler ignores all comments they are there strictly for the convenience of anyone reading the program.

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

High-Level Programming Languages. Nell Dale & John Lewis (adaptation by Michael Goldwasser)

Programming Languages

Functional Programming

Introduction to programming

CA Compiler Construction

Evolution of the Major Programming Languages

Semester Review. CSC 301, Fall 2015

COS 301 Programming Languages

Scanning and parsing. Topics. Announcements Pick a partner by Monday Makeup lecture will be on Monday August 29th at 3pm

The Evolution of Programming Languages

1 Introduction. 2 An Interpreter. 2.1 Handling Source Code

Introduction. Compiler Design CSE 504. Overview. Programming problems are easier to solve in high-level languages

Course Goal CMSC 330: Organization of Programming Languages. Studying Programming Languages. All Languages Are (Kind of) Equivalent.

Asogwa Tochukwu Chijindu Department of Computer Engineering, Enugu State University of Science and Technology(ESUT), Enugu, Nigeria.

History of Programming Languages

Ed. v1.0 PROGRAMMING LANGUAGES WORKING PAPER DRAFT PROGRAMMING LANGUAGES. Ed. v1.0

Programming Project 1: Lexical Analyzer (Scanner)

Computer Programming. Course Details An Introduction to Computational Tools. Prof. Mauro Gaspari:

1.1 WHAT IS A PROGRAMMING LANGUAGE?

Language Processing Systems

Advanced compiler construction. General course information. Teacher & assistant. Course goals. Evaluation. Grading scheme. Michel Schinz

Massachusetts Institute of Technology Department of Electrical Engineering and Computer Science

How To Understand Programming Languages And Programming Languages

Introduction to Software Paradigms & Procedural Programming Paradigm

Image credits:

Implementing Programming Languages. Aarne Ranta

Programming Language Pragmatics

McGraw-Hill The McGraw-Hill Companies, Inc.,

Compilers Lexical Analysis

UNIT-I Preliminaries

Flex/Bison Tutorial. Aaron Myles Landwehr CAPSL 2/17/2012

Semantic Analysis: Types and Type Checking

How to make the computer understand? Lecture 15: Putting it all together. Example (Output assembly code) Example (input program) Anatomy of a Computer

Context free grammars and predictive parsing

Languages september 12, 2015 Éric Lévénez < FORTRAN III end-1958 FORTRAN II FORTRAN I october 1956

Master of Sciences in Informatics Engineering Programming Paradigms 2005/2006. Final Examination. January 24 th, 2006

Special Topics in Computer Science

Artificial Intelligence. Class: 3 rd

Design Patterns in Parsing

Understanding Programming Languages

Introduction to Automata Theory. Reading: Chapter 1

Fundamentals of Programming Languages

The International Journal of Digital Curation Volume 7, Issue

ATSBA: Advanced Technologies Supporting Business Areas. Programming with Java. 1 Overview and Introduction

Cedalion A Language Oriented Programming Language (Extended Abstract)

C Compiler Targeting the Java Virtual Machine

Instructor Özgür ZEYDAN BEU Dept. of Enve. Eng. CIV 112 Computer Programming Lecture Notes (1)

Programming language concepts

Introduction to formal semantics -

CE 504 Computational Hydrology Computational Environments and Tools Fritz R. Fiedler

Java Generation from UML Models specified with Alf Annotations

Chapter 13: Program Development and Programming Languages

Automatic Text Analysis Using Drupal

Lab Experience 17. Programming Language Translation

LONG BEACH CITY COLLEGE MEMORANDUM

Stack Allocation. Run-Time Data Structures. Static Structures

Programming Language Concepts for Software Developers

Embedded Systems. Review of ANSI C Topics. A Review of ANSI C and Considerations for Embedded C Programming. Basic features of C

A Programming Language Where the Syntax and Semantics Are Mutable at Runtime

Levels of Programming Languages. Gerald Penn CSC 324

University of Toronto Department of Electrical and Computer Engineering. Midterm Examination. CSC467 Compilers and Interpreters Fall Semester, 2005

COMP 356 Programming Language Structures Notes for Chapter 10 of Concepts of Programming Languages Implementing Subprograms.

Transcription:

Chapter 2 Evolution of the Major Programming Languages ISBN 0-321-33025-0 Chapter 2 Topics 1. Zuse s Plankalkul 2. Minimal Hardware Programming: Pseudocodes 3. The IBM 704 and Fortran 4. Functional Programming: LISP 5. The First Step Toward Sophistication: ALGOL 60 6. Computerizing Business Records: COBOL 7. The Beginnings of Timesharing: BASIC Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-2 Chapter 2 Topics (continued) 8. Everything for Everybody: PL/I 9. Two Early Dynamic Languages: APL and SNOBOL 10.The Beginings of Data Abstraction: SIMULA 67 11.Orthogonal Design: ALGOL 68 12.Some Early Desscendants of the ALGOLs 13.Programming Based on Logic: Prolog 14.Hisotry s Largest Design Effort: Ada Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-3 1

Chapter 2 Topics (continued) 15.Object-Oriented Programming: Smalltalk 16. Combining Imperative ad Object- Oriented Features: C++ 17. An Imperative-Based Object-Oriented Language: Java 18. Scripting Languages: JavaScript, PHP, and Python 19. A C-Based Language for the New Millennium: C# 20. Markup/Programming Hybrid Languages Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-4 Genealogy of Common Languages Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-5 Chapter 3 Describing Syntax and Semantics ISBN 0-321-33025-0 2

Chapter 3 Topics 1. Introduction 2. The General Problem of Describing Syntax 3. Formal Methods of Describing Syntax 4. Attribute Grammars 5. Describing the Meanings of Programs: Dynamic Semantics Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-7 3.1 Introduction Syntax: the form or structure of the expressions, statements, and program units Semantics: the meaning of the expressions, statements, and program units Syntax and semantics provide a language s definition Users of a language definition Other language designers Implementers Programmers (the users of the language) Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-8 3.2 The General Problem of Describing Syntax: Terminology A sentence is a string of characters over some alphabet A language is a set of sentences Alexeme is the lowest level syntactic unit of a language (e.g., *, sum, begin) A token is a category of lexemes (e.g., identifier) Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-9 3

Formal Definition of Languages Recognizers A recognition device reads input strings of the language and decides whether the input strings belong to the language Example: syntax analysis part of a compiler Detailed discussion in Chapter 4 Generators A device that generates sentences of a language One can determine if the syntax of a particular sentence is correct by comparing it to the structure of the generator Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-10 3.3 Formal Methods of Describing Syntax Backus-Naur Form and Context-Free Grammars Most widely known method for describing programming language syntax Extended BNF Improves readability and writability of BNF Grammars and Recognizers Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-11 Chapter 4 Topics 1. Introduction 2. Lexical Analysis 3. The Parsing Problem 4. Recursive-Descent Parsing 5. Bottom-Up Parsing Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-12 4

4.1 Introduction The syntax analysis portion of a language processor nearly always consists of two parts: A low-level part called a lexical analyzer (mathematically, a finite automaton based on a regular grammar) A high-level part called a syntax analyzer, or parser (mathematically, a push-down automaton based on a context-free grammar, or BNF) Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-13 4.1 Introduction (cont.) Reasons to use BNF to describe syntax: Provides a clear and concise syntax description The parser can be based directly on the BNF Parsers based on BNF are easy to maintain Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-14 4.1 Introduction (cont.) Reasons to separate lexical and syntax analysis: Simplicity - less complex approaches can be used for lexical analysis; separating them simplifies the parser Efficiency - separation allows optimization of the lexical analyzer Portability - parts of the lexical analyzer may not be portable, but the parser always is portable Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-15 5

4.2 Lexical Analysis A lexical analyzer is a pattern matcher for character strings A lexical analyzer is a front-end for the parser Identifies substrings of the source program that belong together - lexemes Lexemes match a character pattern, which is associated with a lexical category called a token sum is a lexeme; its token may be IDENT Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-16 4.2 Lexical Analysis (cont.) The lexical analyzer is usually a function that is called by the parser when it needs the next token Three approaches to building a lexical analyzer: Write a formal description of the tokens and use a software tool that constructs table-driven lexical analyzers given such a description Design a state diagram that describes the tokens and write a program that implements the state diagram Design a state diagram that describes the tokens and hand-construct a table-driven implementation of the state diagram book only discusses approach 2 Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-17 Lexical Analysis Using Finite State Machines to implement lexical scan Example:Design a FSM which translates input text line by line so that the following rule is followed correcting spelling mistakes wrt ei and cei : i should be followed by e except when immediately followed by c. Input: She will eat a pie if there is a pei and when she recieves it. Output:She will eat a pie if there is a pie and when she receives it. Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-18 6

4.2 Lexical Analysis (cont.) State diagram design: A naïve state diagram would have a transition from every state on every character in the source language - such a diagram would be very large! Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-19 4.2 Lexical Analysis (cont.) In many cases, transitions can be combined to simplify the state diagram When recognizing an identifier, all uppercase and lowercase letters are equivalent Use a character class that includes all letters When recognizing an integer literal, all digits are equivalent - use a digit class Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-20 4.2 Lexical Analysis (cont.) Reserved words and identifiers can be recognized together (rather than having a part of the diagram for each reserved word) Use a table lookup to determine whether a possible identifier is in fact a reserved word Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-21 7

4.2 Lexical Analysis (cont.) Convenient utility subprograms: getchar - gets the next character of input, puts it in nextchar, determines its class and puts the class in charclass addchar - puts the character from nextchar into the place the lexeme is being accumulated, lexeme lookup - determines whether the string in lexeme is a reserved word (returns a code) Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-22 State Diagram Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-23 4.2 Lexical Analysis (cont.) Implementation (assume initialization): int lex() { switch (charclass) { case LETTER: addchar(); while (charclass == LETTER charclass == DIGIT) { addchar(); } return lookup(lexeme); break; Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-24 8

4.2 Lexical Analysis (cont.) case DIGIT: addchar(); while (charclass == DIGIT) { addchar(); } return INT_LIT; break; } /* End of switch */ } /* End of function lex */ Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-25 HW problems for practice on FSMs Design a FSM that translates text in which properly delimited the is replaced by a. Design a FSM to strip out comments from a C or C++ program. Design a FSM to recognize identifiers in C. Copyright 2006 Pearson Addison-Wesley. All rights reserved. 2-26 9