24
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Embed Size (px)

Citation preview

Page 1: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Chapter 6Programming Languages (2)

Introduction to CS

1st Semester, 2015 Sanghyun Park

Page 2: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Outline Historical Perspective

(covered) Traditional Programming Concepts

(covered) Procedural Units Language Implementation

Object-Oriented Programming (skip) Programming Concurrent Activities (skip) Declarative Programming (skip)

Page 3: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Procedures A ________ is a set of instructions for performing a task

that can be used as an abstract tool by other program units

________ is transferred to the procedure at the time its services are required

Control is returned to the original program unit after the procedure ________

A procedure can be regarded as a _________ program

Page 4: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Flow of Control

Page 5: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Variables and Parameters Local variables

Variables declared ______ a procedure ______ to that procedure only

Global variables Variables not ________ to a particular part of a program Accessible __________ the program

Parameters Variables that are passed to ____________ Formal parameters and ______ parameters

Page 6: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Procedures: Example

Page 7: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Parameter Passing Pass by ________

Pass by ________

There are pros and cons with each

Page 8: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Pass By Value A ____ of the data represented by the actual parameters

is produced and given to the procedure

Any alterations to the data made by the procedure are reflected only in the _____ ---the data in the calling program unit are ______ changed

Therefore, this model is ____

If the parameters represent large blocks of data,this can be ___________

Page 9: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Pass By Value: Example

Page 10: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Pass By Reference The ________ of the actual parameters is given to the

procedure

The procedure has ____ access of the data represented by the actual parameters

This is more ________

This is however more _________

Page 11: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Pass By Reference: Example

Page 12: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Functions There are two types of procedures

Those that DO NOT return a value(sometimes called __________)

Those that DO return a value(usually called __________)

Page 13: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Language Implementation The process of converting a program from one language

to another is called _________ The program in its original form is the _______ program;

the translated version is the ________ program Translation process

Page 14: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Lexical Analyzer Reads the source program symbol by symbol,

________ which groups of symbols represent single units, and _________ those units (numeric values, words, …)

As each unit is classified, the lexical analyzer generatesa bit pattern known as a ______

Therefore, the lexical analyzer converts the program(a stream of _______) into a stream of _______

Page 15: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Parser Identifies the ___________ structure of the program and

recognizes the ____ of each component

Based on a set of syntax rules (= __________)that define the syntax of the programming language

A ______ tree is used to show that a stream of tokens conforms to the grammar

Page 16: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Syntax Diagram: Example 1

Page 17: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Syntax Diagram: Example 2

Page 18: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Parse Tree for x + y x z

Page 19: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Ambiguity A parse tree represents the parser’s _____________

of the program’s grammatical composition

The grammar is __________ if it is possible to havemore than one parse tree for one string

Note that the following statement leads to ambiguity:if B1 then if B2 then S1 else S2 (________ Else)

Page 20: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Parse Tree 1 for Dangling Else

Page 21: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Parse Tree 2 for Dangling Else

Page 22: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Dangling Else Resolution _________ close every if statement, or

Match every else with the ________ if

Page 23: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Code Generation Constructs the ________-language instructions

to implement the statements recognized by the parser

This process involves numerous issue, one being that of producing efficient code (code __________)

Some optimizations include Reduce number of _____instructions_____ Remove _________ and/or useless instructions Reduce number of __jumps______

Page 24: Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park

Linking and Loading When all steps of translation have been finished,

we have a piece of ______ code

Object code may contain _________ to other object code

Thus, generally several pieces of object code need to be ______ together to form an executable program

In order for an executable program to be run, it needs to be loaded into memory by a program called a ______