47
Programming Language Thoery 2017 Kwangman Ko (http://compiler.sangji.ac.kr , [email protected]) Dept. of Computer Engineering, Sangji University

Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Programming Language Thoery

2017

Kwangman Ko

(http://compiler.sangji.ac.kr, [email protected])

Dept. of Computer Engineering, Sangji University

Page 2: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

강의 자료

lecture 01 : Programming Language Theory Concepts 2

- 도서명 : 프로그래밍언어론

- ISBN : 979-11-5664-329-6 93000

- 저자 : 유원희, 하상호 번역

- 출판사 : 피어슨

- 강의 자료 : http://compiler.sangji.ac.kr

- Q&A : [email protected]

- NO! Phone and SNS

Page 3: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

평가(evaluation)

lecture 01 : Programming Language Theory Concepts 3

30, 30%

30, 30%

30, 30%

10,

10%

성적평가

중간고사 기말고사 과제 출석

• 중간고사 : 8주/16.– 이론 시험 (100 점)

• 기말고사 : 16주/16.– 이론시험 (100점)

• 과제 : 5회 지정 기한 제출– 5회( 1회*20점=100점)

• 출석– ¼ 결석 : F

Page 4: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

강의 계획표 및 내용

lecture 01 : Programming Language Theory Concepts 4

주 해당 장/주제 주제

1 1장 강의 소개, 프로그래밍 언어의 기본 개념

2 3, 4장 제 3, 4장 : 프로그래밍언어 구문(syntax)과 분석(analysis, parsing)

3 5 장 제 5장: 이름, 바인딩, 기억장치 관리

4 6, 7장 제 6, 7장 : 데이터 타입과 문장

5 Python 1

6 Python 2

7 9,10장 제 9, 10 장 : 부프로그램 및 부프로그램 구현

8 중간고사

9 11, 12장 제 11, 12장 : 객체지향 페러다임 및 프로그래밍

10 Java vs. C++ 프로그래밍 언어

11 리눅스 쉘, 커널 프로그래밍

12 13장 동시성 및 스레드 프로그래밍

13 14장 예외 처리 및 이벤트 처리 프로그래밍

14 논리 및 함수 프로그래밍 언어

15 스크립트 프로그래밍 언어

16 기말고사

Page 5: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

lecture 01 : Programming Language Theory Concepts 5

Page 6: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

lecture 01 : Programming Language Theory Concepts 6

Page 7: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

가장 많이 사용되는 언어는?

lecture 01 : Programming Language Theory Concepts 7

Page 8: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Chapter 1 : Preliminaries

Page 9: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.1 Reasons for Studying Concepts of Programming Languages

Page 10: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Reasons for Studying Concepts of Programming Languages

Increased

• ability to express ideas

• ability to learn new languages

Improved

• background for choosing appropriate languages

lecture 01 : Programming Language Theory Concepts 10

Page 11: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Better

• understanding of significance of implementation

• use of languages that are already known

Overall advancement of computing ( Computing Thinking )

lecture 01 : Programming Language Theory Concepts 11

Page 12: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.2 Programming DomainsArtificial intelligence

• Symbols rather than numbers manipulated; use of linked lists• LISP

Systems programming• Need efficiency because of continuous use• C

Web Software• Eclectic collection of languages: • markup (e.g., XHTML), scripting (e.g., PHP), general-purpose (e.g., Java)

Statistic• R programming language

lecture 01 : Programming Language Theory Concepts 12

Page 13: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.3 Language Evaluation Criteria

Readability

Writability

Reliability

Cost

Page 14: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Language Evaluation Criteria

Readability

Writability

Reliability

Cost

lecture 01 : Programming Language Theory Concepts 14

Page 15: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Evaluation Criteria: ReadabilityOverall simplicity

• A manageable set of features and constructs

• Minimal feature multiplicity

count = count + 1;count += 1;count++’;++count

• Minimal operator overloading

• 3+4, 3.0+4.0

lecture 01 : Programming Language Theory Concepts 15

Page 16: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

직교성 (Orthogonality)• A relatively small set of primitive constructs can be combined in a relatively small number

of ways• 상대적으로 적은 개수의 기본 구조들이 적은 개수의 방법으로 조합하여 새로운 제어 구조 및

자료구조 생성

• Every possible combination is legal

lecture 01 : Programming Language Theory Concepts 16

Page 17: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Syntax considerations• Identifier forms: flexible composition • Special words and methods of forming compound statements• Form and meaning: self-descriptive constructs, meaningful keywords

lecture 01 : Programming Language Theory Concepts 17

Page 18: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Evaluation Criteria: Writability

Simplicity and orthogonality• Few constructs, a small number of primitives, a small set of rules for combining them

Support for abstraction• The ability to define and use complex structures or operations in ways that allow details

to be ignored

Expressivity• A set of relatively convenient ways of specifying operations• Strength and number of operators and predefined functions

lecture 01 : Programming Language Theory Concepts 18

Page 19: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Evaluation Criteria: Reliability

Type checking• Testing for type errors

Exception handling• Intercept run-time errors and take corrective measures

Aliasing• Presence of two or more distinct referencing methods for the same memory location

Readability and writability• A language that does not support “natural” ways of expressing an algorithm will require the use of

“unnatural” approaches, and hence reduced reliability

lecture 01 : Programming Language Theory Concepts 19

Page 20: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Evaluation Criteria: Cost

Training programmers to use the language

Writing programs (closeness to particular applications)

Compiling programs

Executing programs

Language implementation system: availability of free compilers

Reliability : poor reliability leads to high costs

Maintaining programs

lecture 01 : Programming Language Theory Concepts 20

Page 21: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.4 Influences on Language Design

Computer ArchitectureLanguages are developed around the prevalent computer architecture, known as the von Neumann architecture

Programming MethodologiesNew software development methodologies (e.g., object-oriented software development) led to new programming paradigms and by extension, new programming languages

Page 22: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Computer Architecture Influence

Well-known computer architecture: Von Neumann

lecture 01 : Programming Language Theory Concepts 22

Page 23: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Fetch-execute-cycle (on a von Neumann architecture computer)

initialize the program counter

repeat forever

fetch the instruction pointed by the counter

increment the counter

decode the instruction

execute the instruction

end repeat

lecture 01 : Programming Language Theory Concepts 23

Page 24: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Imperative languages because of von Neumann computers

• Data and programs stored in memory

• Memory is separate from CPU

• Instructions and data are piped from memory to CPU

• Basis for imperative languages

• Variables model memory cells

• Assignment statements model piping

• Iteration is efficient

lecture 01 : Programming Language Theory Concepts 24

Page 25: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Programming Methodologies Influences

1950s and early 1960s• Simple applications; worry about machine efficiency

Late 1960s• People efficiency became important; readability, better control structures• structured programming• top-down design and step-wise refinement

Late 1970s: Process-oriented to data-oriented• data abstraction

Middle 1980s: Object-oriented programming• Data abstraction + inheritance + polymorphism

lecture 01 : Programming Language Theory Concepts 25

Page 26: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.5 Language Categories

Page 27: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Imperative• Central features are variables, assignment statements, and iteration• Include languages that support object-oriented programming• Include scripting languages• Include the visual languages• Examples: C, Java, Perl, JavaScript, Visual BASIC .NET, C++

Functional• Main means of making computations is by applying functions to given

parameters• Examples: LISP, Scheme

lecture 01 : Programming Language Theory Concepts 27

Page 28: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Logic• Rule-based (rules are specified in no particular order)• Example: Prolog

Markup/programming hybrid • Markup languages extended to support some programming• Examples: JSTL, XSLT

lecture 01 : Programming Language Theory Concepts 28

Page 29: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.6 Language Design 절충(Trade-Offs)

Page 30: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Reliability vs. cost of execution

• Example: Java demands all references to array elements be checked for proper indexing, which leads to increased execution costs

lecture 01 : Programming Language Theory Concepts 30

Page 31: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Readability vs. writability

Example:

APL provides many powerful operators (and a large number of new symbols), allowing complex computations to be written in a compact program but at the cost of poor readability

lecture 01 : Programming Language Theory Concepts 31

Page 32: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Writability (flexibility) vs. reliability

• Example: C++ pointers are powerful and very flexible but are unreliable

lecture 01 : Programming Language Theory Concepts 32

Page 33: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

1.7 Implementation Methods

CompilationPrograms are translated into machine language

Pure InterpretationPrograms are interpreted by another program known as an interpreter

Hybrid Implementation SystemsA compromise between compilers and pure interpreters

Page 34: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Layered View of Computer

Operating system and language implementation• layered over machine interface of a computer

lecture 01 : Programming Language Theory Concepts 34

Page 35: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Compilation

Compiler

• translate high-level program (source language) into machine code (machine language)

• Slow translation, fast execution

Compilation process has several phases: • lexical analysis: converts characters in the source program into lexical units

• syntax analysis: transforms lexical units into parse trees which represent the syntactic structure of program

• Semantics analysis: generate intermediate code

• Code optimization

• code generation: machine code is generated

lecture 01 : Programming Language Theory Concepts 35

Page 36: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Compiler Process

lecture 01 : Programming Language Theory Concepts 36

Page 37: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Additional Compilation Terminologies

Load module (executable image)

• the user and system code together

Linking and loading

• the process of collecting system program units and linking them to a user program

lecture 01 : Programming Language Theory Concepts 37

Page 38: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Von Neumann Bottleneck

Connection speed between a computer’s memory and its processor determines the speed of a computer

Program instructions often can be executed much faster than the speed of the connection; the connection speed thus results in a bottleneck

Known as the von Neumann bottleneck; it is the primary limiting factor in the speed of computers

lecture 01 : Programming Language Theory Concepts 38

Page 39: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Pure Interpretation

No translation

Easier implementation of programs (run-time errors can easily and immediately be displayed)

Slower execution (10 to 100 times slower than compiled programs)

Often requires more space

Now rare for traditional high-level languages

Significant comeback with some Web scripting languages (e.g., JavaScript, PHP)

lecture 01 : Programming Language Theory Concepts 39

Page 40: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Pure Interpretation Process

lecture 01 : Programming Language Theory Concepts 40

Page 41: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Hybrid Implementation Systems

A compromise between compilers and pure interpreters

A high-level language program is translated to an intermediate language that allows easy interpretation

Faster than pure interpretation

lecture 01 : Programming Language Theory Concepts 41

Page 42: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Examples• Perl programs are partially compiled to detect errors before interpretation

• Initial implementations of Java were hybrid; the intermediate form, byte code, provides portability to any machine that has a byte code interpreter and a run-time system (together, these are called Java Virtual Machine)

lecture 01 : Programming Language Theory Concepts 42

Page 43: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Hybrid Implementation Process

lecture 01 : Programming Language Theory Concepts 43

Page 44: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Just-in-Time Implementation Systems

Initially translate programs to an intermediate language

Then compile the intermediate language of the subprograms into machine code when they are called

Machine code version is kept for subsequent calls

JIT systems are widely used for Java programs

.NET languages are implemented with a JIT system

lecture 01 : Programming Language Theory Concepts 44

Page 45: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Preprocessors

Preprocessor macros (instructions) are commonly used to specify that code from another file is to be included

A preprocessor processes a program immediately before the program is compiled to expand embedded preprocessor macros

A well-known example: C preprocessor• #include

• #define

• macros

lecture 01 : Programming Language Theory Concepts 45

Page 46: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

Programming Environments

A collection of tools used in software development

UNIX• An older operating system and tool collection• Nowadays often used through a GUI (e.g., CDE, KDE, or GNOME) that runs on top of UNIX

Microsoft Visual Studio.NET• A large, complex visual environment

Used to build Web applications and non-Web applications in any .NET language

NetBeans• Related to Visual Studio .NET, except for Web applications in Java

lecture 01 : Programming Language Theory Concepts 46

Page 47: Programming Language Thoerycompiler.sangji.ac.kr/lecture/plt/2017/lecture01.pdf · 평가(evaluation) lecture 01 : Programming Language Theory Concepts 3 30, 30% 30, 30% 30, 30% 10,

NEXT : Programming Language

Syntax and Parsing

[email protected]