Introduction to Programming Languages NaiWei Lin Department of
- Slides: 41
Introduction to Programming Languages Nai-Wei Lin Department of Computer Science and Information Engineering National Chung Cheng University
Chapter 1 Introduction
Outline n What is a programming language n Levels of programming languages n Definition of programming languages n Implementation of programming languages n Abstractions in programming languages n Paradigms of programming languages n Language design principles 3
What Is a Programming Language n A natural language is designed to communicate between human n A programming language is designed to communicate between human and computers 4
How we communicate influences how we think, and vice versa. 5
A programming language is a notation for describing computation in computer-readable and human-readable form 6
Computation n Computation is usually defined formally using the mathematical concept of a Turing machine n Church’s thesis states that it is not possible to build a machine that is inherently more powerful than a Turing machine 7
Turing Completeness n n 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 8
Levels of Programming Languages n Machine languages n Assembly languages n High-level languages 9
Definition of Programming Languages n The Syntax of a programming language specifies the structure of programs n The Semantics of a programming language specifies the meaning of programs 10
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. 11
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. 12
Formal Definition of Programming Languages n n 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 13
Implementation of Programming Languages n A compiler is a program that can translate programs written in a language into programs written in another language n An interpreter is a program that can understand a language and execute programs written in that language 14
Compilers Source program Compiler Target program Input Target program Output 15
Interpreters Input Source program Interpreter Output 16
Virtual Machines n n n 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 17
Abstractions in Programming Languages n 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 18
Abstract 抽象 摘要 n Draw the common properties from all the instances n Adopt the essential properties from the whole system 19
Abstractions The set of operations associated with each data object The sequence of operations to be processed Data Control Operations 20
Abstractions n Data abstractions abstract properties of data, such as numbers, character strings, trees, which are subjects of computation n Control abstractions abstract properties of control, such as loops, conditional statements, and procedures 21
Data Abstractions n Basic abstractions: basic data types such as integers, floating point numbers, and characters n Structured abstractions: structured data types such as arrays and records n Unit abstractions: abstract data types such as stacks, queues, trees, and graphs 22
Control Abstractions n Basic abstractions: basic statements such as assignment statement and goto statement n Structured abstractions: structured statements such as if-statement, whilestatement, and procedures n Unit abstractions: abstract data types such as stacks, queues, trees, graphs 23
Abstraction of Operations Basic data types Basic statements Structured data types Structured statements Abstract data types 24
Abstraction of Operations High-Level Languages Abstract Operations Machine Languages 25
Paradigms of Programming Languages n Imperative programming – a series of commands: Fortran, Pascal, C, Ada n Object-oriented programming – a class of objects: Simula, Smalltalk, C++, Java n Functional programming – a collection of mathematical function definitions: Scheme, ML, Haskell n Logic programming – a collection of logical predicates: Prolog, Godel 26
Imperative Programming int gcd(int u, int v) { int t; while (v != 0) { t = u % v; u = v; v = t; } return u; } How 27
Object-Oriented Programming public class Int. With. Gcd { private int value; public Int. With. Gcd(int val) { value = val; } public int. Value() { return value; } public int gcd(int v) { int z = value; int y = v; while (y != 0) { How int t = u % v; z = y; y = t; } return z; } 28
Functional Programming u , if v = 0; gcd(u, v) = gcd (v, u % v), otherwise. gcd u v = if v == 0 then u else gcd(v (u ‘mod’ v)) What 29
Logic Programming V = 0 gcd(U, V) = U V 0, Y = U %V, gcd(V, Y) = X gcd(U, V) = X gcd(U, V, U) : - V = 0. gcd(U, V, X) : - not (V = 0), Y is U mod V, What gcd(V, Y, X). 30
Language Design Criteria ? n n 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 goalorientd activity 31
Efficiency n n n 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 32
Regularity n n 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 33
Generality n n Do constructs have as few restrictions as possible? Functions q q q n 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 34
Orthogonality n n Can constructs be combined in any meaningful way? Return types of functions q q q 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 35
Uniformity n n n 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 36
Other Criteria n n n Simplicity: make things as simple as possible, but not simpler. (Pascal, C) Expressiveness: make it possible to express conceptual abstractions directly and simply. (Scheme, Simula 67) Extensibility: allow the programmer to extend the language in various ways. (Scheme, C++) 37
Other Criteria n n n 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) 38
Other Criteria n n 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) 39
C++: A Case Study n Thanks to Bjarne Stroustrup, C++ is not only a great success story, but also the best -documented language development effort in history: q 1997: The C++ Programming Language, 3 rd Edition (Addison-Wesley). q 1994: The Design and Evolution of C++ (Addison-Wesley). q 1993: A History of C++ 1979 -1991, SIGPLAN Notices 28(3). 40
Course Contents n n n Introduction Syntax Functional programming Logic programming Basic semantics Data types n. Expressions n. Statements n. Procedures n. Modules n. Exceptions n. Conclusion 41
- Introduction to programming languages
- Real-time systems and programming languages
- Cs 421 uiuc
- Multithreading program in java
- Programming languages levels
- Plc programming languages
- Joey paquet
- Imperative programming languages
- Alternative programming languages
- Types of programming languages
- Transmission programming languages
- Cse 340 principles of programming languages
- Int vs short
- Xenia programming languages
- Advantages of application software
- Mainstream programming languages
- Cse 340 principles of programming languages
- Programing languages
- Programming languages
- Programming languages
- Programming languages
- Attribute grammar in principles of programming languages
- Brief history of programming languages
- Lisp_q
- Real-time systems and programming languages
- Xkcd programming
- If programming languages were cars
- Reasons for studying concepts of programming languages
- Cornell programming languages
- Low level programming languages
- Middle level programming languages
- Programming languages flowchart
- Cs 421 uiuc
- Iat 265
- Storage management in programming languages
- Introduction to scripting languages
- Gtg stands for in automata
- Perbedaan linear programming dan integer programming
- Greedy vs dynamic programming
- What is system program
- Integer programming vs linear programming
- Programing adalah