Download presentation
Presentation is loading. Please wait.
Published byErica Marsh Modified over 9 years ago
1
Chapter 6 Programming Languages (2) Introduction to CS 1 st Semester, 2015 Sanghyun Park
2
Outline Historical Perspective(covered) Traditional Programming Concepts(covered) Procedural Units Language Implementation Object-Oriented Programming(skip) Programming Concurrent Activities(skip) Declarative Programming(skip)
3
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
4
Flow of Control
5
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
6
Procedures: Example
7
Parameter Passing Pass by ________ There are pros and cons with each
8
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 ___________
9
Pass By Value: Example
10
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 _________
11
Pass By Reference: Example
12
Functions There are two types of procedures Those that DO NOT return a value (sometimes called __________) Those that DO return a value (usually called __________)
13
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
14
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 generates a bit pattern known as a ______ Therefore, the lexical analyzer converts the program (a stream of _______) into a stream of _______
15
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
16
Syntax Diagram: Example 1
17
Syntax Diagram: Example 2
18
Parse Tree for x + y x z
19
Ambiguity A parse tree represents the parser’s _____________ of the program’s grammatical composition The grammar is __________ if it is possible to have more 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)
20
Parse Tree 1 for Dangling Else
21
Parse Tree 2 for Dangling Else
22
Dangling Else Resolution _________ close every if statement, or Match every else with the ________ if
23
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______
24
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 ______
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.