Upload
erica-marsh
View
228
Download
3
Embed Size (px)
Citation preview
Chapter 6Programming Languages (2)
Introduction to CS
1st 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)
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
Flow of Control
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
Procedures: Example
Parameter Passing Pass by ________
Pass by ________
There are pros and cons with each
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 ___________
Pass By Value: Example
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 _________
Pass By Reference: Example
Functions There are two types of procedures
Those that DO NOT return a value(sometimes called __________)
Those that DO return a value(usually called __________)
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
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 _______
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
Syntax Diagram: Example 1
Syntax Diagram: Example 2
Parse Tree for x + y x z
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)
Parse Tree 1 for Dangling Else
Parse Tree 2 for Dangling Else
Dangling Else Resolution _________ close every if statement, or
Match every else with the ________ if
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______
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 ______