Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University.

Slides:



Advertisements
Similar presentations
Adapted from Scott, Chapter 6:: Control Flow Programming Language Pragmatics Michael L. Scott.
Advertisements

Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Programming Languages Marjan Sirjani 2 2. Language Design Issues Design to Run efficiently : early languages Easy to write correctly : new languages.
CSI 3125, Preliminaries, page 1 Programming languages and the process of programming –Programming means more than coding. –Why study programming languages?
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering CSCE 330 Programming Language Structures Ch.2: Syntax and Semantics Fall 2005.
Comp 205: Comparative Programming Languages Semantics of Imperative Programming Languages denotational semantics operational semantics logical semantics.
Chapter 1: Preliminaries
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
Louden, Chapter 3 - Language Design Principles Programming Languages: Principles and Practice, 2nd Ed.
High-Level Programming Languages
Reasons to study concepts of PL
ISBN Chapter 1 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Chapter 1 Topics Motivation Programming Domains.
Programming Language Semantics Mooly SagivEran Yahav Schrirber 317Open space html://
Programming Languages Structure
Chapter 8 High-Level Programming Languages Nell Dale John Lewis.
ISBN Lecture 01 Preliminaries. Copyright © 2004 Pearson Addison-Wesley. All rights reserved.1-2 Lecture 01 Topics Motivation Programming.
Chapter 3 Louden1 Chapter 3 - Language Design Principles Programming Languages: Principles and Practice, 2nd Ed. Kenneth C. Louden.
ISBN Chapter 1 Topics Motivation Programming Domains Language Evaluation Criteria Influences on Language Design Language Categories Language.
Programming Language Concepts
1 Programming Languages Marjan Sirjani 2 1- The Study of Programming Languages The purpose of language is simply that it must convey meaning. (Confucius)
Language Evaluation Criteria
Overview. Copyright © 2006 The McGraw-Hill Companies, Inc. Chapter 1 Overview A good programming language is a conceptual universe for thinking about.
CSE 425: Intro to Programming Languages and their Design A Few Key Ideas No particular language is a prerequisite for this course –However you should be.
PZ01A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ01A -- Introduction Programming Language Design and.
MT311 Java Programming and Programming Languages Li Tak Sing ( 李德成 )
Chapter 8 High-Level Programming Languages (modified by Erin Chambers)
High-Level Programming Languages: C++
(1.1) COEN 171 Programming Languages Winter 2000 Ron Danielson.
Chapter 1. Introduction.
CS 363 Comparative Programming Languages
Gary MarsdenSlide 1University of Cape Town Principles of programming language design Gary Marsden Semester 2 – 2001.
Programming Languages –14 David Watt (Glasgow) Steven Wong (Singapore) Moodle : Computing Science → Level 3 → Programming Languages 3 © 2012 David.
Chapter 1 - Introduction
CS 152: Programming Language Paradigms February 10 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak.
Principles of Programming Languages Asst. Prof. Dr. Ahmet Sayar Spring-2012 Kocaeli University Computer Engineering Department Introduction.
1 Programming Languages Marjan Sirjani Course web site:
CS 326 Programming Languages, Concepts and Implementation Instructor: Mircea Nicolescu Lecture 2.
1 Programming Language History and Evolution In Text: Chapter 2.
1 Introduction Programming Language Design and Implementation (4th Edition) by T. Pratt and M. Zelkowitz Prentice Hall, 2001 Sections
Copyright © 2006 Addison-Wesley. All rights reserved.1-1 ICS 410: Programming Languages.
Chapter 8 High-Level Programming Languages. 8-2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Chapter 6 Programming Languages © 2007 Pearson Addison-Wesley. All rights reserved.
Chapter 6 Programming Languages (1) Introduction to CS 1 st Semester, 2015 Sanghyun Park.
1 Programming Languages Fundamentals Cao Hoaøng Truï Khoa Coâng Ngheä Thoâng Tin Ñaïi Hoïc Baùch Khoa TP. HCM.
ProgrammingLanguages Programming Languages Language Definition, Translation and Design.
3.2 Semantics. 2 Semantics Attribute Grammars The Meanings of Programs: Semantics Sebesta Chapter 3.
Theory of Programming Languages Introduction. What is a Programming Language? John von Neumann (1940’s) –Stored program concept –CPU actions determined.
Languages and Compilers
Chapter 3 - Language Design Principles
Chapter 8 High-Level Programming Languages. 2 Chapter Goals Describe the translation process and distinguish between assembly, compilation, interpretation,
Engr. Isabelo Jun D. Paat, ME-CoE Lecturer 1 Programming Languages.
Computer Programming CONTENTS Introduction to Operating Systems Introduction to programming languages Introduction to perl programming language Programming.
Copyright © 2006 The McGraw-Hill Companies, Inc. Programming Languages 2nd edition Tucker and Noonan Chapter 1 Overview A good programming language is.
CPS120: Introduction to Computer Science Variables and Constants.
1-1 1 Introduction  Programming linguistics: concepts and paradigms syntax, semantics, and pragmatics language processors.  Historical development of.
Programming Language Design Issues Programming Languages – Principles and Practice by Kenneth C Louden.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
Programming Languages Concepts Chapter 1: Programming Languages Concepts Lecture # 4.
Programming Language Paradigms ITSK2314 Lecture 3.
Programming Languages 2nd edition Tucker and Noonan
Zuse’s Plankalkül – 1945 Never implemented Problems Zuse Solved
PROGRAMMING LANGUAGES
Programming Languages 2nd edition Tucker and Noonan
Chapter 6: Programming Languages
Principles of Programming Languages
Chapter 1 Preliminaries.
Presentation transcript:

Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University

Chapter 1 Introduction

3 Outline What is a programming language Levels of programming languages Definition of programming languages Implementation of programming languages Abstractions in programming languages Paradigms of programming languages Language design principles

4 What Is a Programming Language A natural language is designed to communicate between human A programming language is designed to communicate between human and computers

5 How we communicate influences how we think, and vice versa.

6 A programming language is a notation for describing computation in computer-readable and human-readable form

7 Computation Computation is usually defined formally using the mathematical concept of a Turing machine Church’s thesis states that it is not possible to build a machine that is inherently more powerful than a Turing machine

8 Turing Completeness A programming language is Turing complete if it can be used to describe all the computation that a Turing machine can perform A programming language is Turing complete if it has integer variables and arithmetic operators, assignment statements, sequence statements, selection statements, and iteration statements

9 Levels of Programming Languages Machine languages Assembly languages High-level languages

10 Definition of Programming Languages The Syntax of a programming language specifies the structure of programs The Semantics of a programming language specifies the meaning of programs

11 Syntax An if-statement consists of the word “if” followed by an expression inside parentheses, followed by a statement, followed by an optional else part consisting of the word “else” and another statement.

12 Semantics An if-statement is executed by first evaluating its expression, which must have arithmetic or pointer type, including all side effects, and if it compares unequal to 0, the statement following the expression is executed. If there is an else part, and the expression is 0, the statement following the “else” is executed.

13 Formal Definition of Programming Languages The Syntax of a programming language is usually formally defined by context-free grammars The Semantics of a programming language is usually informally defined by human languages. It can be partially defined in a formal language using operational semantics, denotational semantics, or axiomatic semantics

14 Implementation of Programming Languages A compiler is a program that can translate programs written in a language into programs written in another language An interpreter is a program that can understand a language and execute programs written in that language

15 Compilers Output Compiler Source program Target program Target program Input

16 Interpreters Interpreter Output Source program Input

17 Virtual Machines An interpreter can be viewed as a virtual machine that can directly execute a high level programming language Compilers and interpreters are relative concepts. Many programming languages have both a compiler and an interpreter Java has a compiler that translates the Java programs into Java byte codes. The Java virtual machine is an interpreter that can directly execute Java byte codes

18 Abstractions in Programming Languages A programming language provides abstractions of the computation that are easy to understand, even by persons not familiar with the underlying details of the computer

19 Abstract Draw the common properties from all the instances Adopt the essential properties from the whole system 抽象摘要

20 Abstractions Operations DataControl The set of operations associated with each data object The sequence of operations to be processed

21 Abstractions Data abstractions abstract properties of data, such as numbers, character strings, trees, which are subjects of computation Control abstractions abstract properties of control, such as loops, conditional statements, and procedures

22 Data Abstractions Basic abstractions: basic data types such as integers, floating point numbers, and characters Structured abstractions: structured data types such as arrays and records Unit abstractions: abstract data types such as stacks, queues, trees, and graphs

23 Control Abstractions Basic abstractions: basic statements such as assignment statement and goto statement Structured abstractions: structured statements such as if-statement, while- statement, and procedures Unit abstractions: abstract data types such as stacks, queues, trees, graphs

24 Abstraction of Operations Basic data typesBasic statements Structured data typesStructured statements Abstract data types

25 Abstraction of Operations Machine Operations Abstract Operations High-Level Languages Machine Languages

26 Paradigms of Programming Languages Imperative programming – a series of commands: Fortran, Pascal, C, Ada Object-oriented programming – a class of objects: Simula, Smalltalk, C++, Java Functional programming – a collection of mathematical function definitions: Scheme, ML, Haskell Logic programming – a collection of logical predicates: Prolog, Godel

27 Imperative Programming int gcd(int u, int v) { int t; while (v != 0) { t = u % v; u = v; v = t; } return u; } How

28 Object-Oriented Programming public class IntWithGcd { private int value; public IntWithGcd(int val) { value = val; } public int intValue() { return value; } public int gcd(int v) { int z = value; int y = v; while (y != 0) { int t = u % v; z = y; y = t; } return z; } How

29 Functional Programming u, if v = 0; gcd(u, v) = gcd (v, u % v), otherwise. What gcd u v = if v == 0 then u else gcd(v (u ‘mod’ v))

30 Logic Programming gcd(U, V, U) :- V = 0. gcd(U, V, X) :- not (V = 0), Y is U mod V, gcd(V, Y, X). What V = 0  gcd(U, V) = U V  0, Y = U %V, gcd(V, Y) = X  gcd(U, V) = X

31 Language Design Criteria ? It is very difficult to offer criteria for good programming language design Criteria for good programming language design often conflict each other A programming language can be a success or failure for many different reasons Programming language design is a goal- orientd activity

32 Efficiency Efficiency of compiler construction: implementability Efficiency of compiler execution: simplicity, reliability Efficiency of program construction: writability, expressiveness Efficiency of program execution: optimizability Efficiency of program modification: readability, maintainability

33 Regularity Regularity is a measure of how well a language integrates its features, so that there are no unusual restrictions, interactions, or behaviors Regularity can be placed in subcategories: Generality, Orthogonality, Uniformity

34 Generality Do constructs have as few restrictions as possible? Functions  In Pascal, functions can be passed as parameters, but there are no function variables.  C lacks nested functions.  Scheme and ML have completely general functions Fortran can pass variable-length array parameters, but cannot define variable-length array variables

35 Orthogonality Can constructs be combined in any meaningful way? Return types of functions  In Pascal, functions can return only scalar or pointer types as values.  In C and C++, values of all types, except array types, can be returned.  In Ada and functional languages, values of all types can be returned

36 Uniformity Do similar things look the same, and do different things look different? In C++, a semicolon is necessary after a class definition but forbidden after a function definition In Pascal, returned values from functions look like assignments

37 Other Criteria Simplicity: make things as simple as possible, but not simpler. (Pascal, C) Expressiveness: make it possible to express conceptual abstractions directly and simply. (Scheme, Simula67) Extensibility: allow the programmer to extend the language in various ways. (Scheme, C++)

38 Other Criteria Security: programs cannot do unexpected damage. (Pascal, Java) Preciseness: having a definition that can answer programmers and implementers questions. (Most languages today, but only one has a mathematical definition: ML) Machine-independence: should run the same on any machine. (Java)

39 Other Criteria Consistent with accepted notations. (Most languages today, but not APL) Restrictability: a programmer can program effectively in a subset of the full language. (C++: avoids runtime penalties)

40 C++: A Case Study Thanks to Bjarne Stroustrup, C++ is not only a great success story, but also the best-documented language development effort in history:  1997: The C++ Programming Language, 3rd Edition (Addison-Wesley).  1994: The Design and Evolution of C++ (Addison-Wesley).  1993: A History of C , SIGPLAN Notices 28(3).

41 Course Contents Introduction Syntax Functional programming Logic programming Basic semantics Data types Expressions Statements Procedures Modules Exceptions Conclusion