Parts vs. the whole in the procedural logic hierarchy

advertisement
Parts vs. the whole in the procedural logic hierarchy.
We have added significant tools to our problem solving tool kit. You have already encountered many of the terms for
methods expressed using this problem-solving tool kit: algorithm, function, method (in the object-oriented sense),
procedure, procedural logic, process, program, routine, subprogram, subroutine, to name just a few. You have also
encountered terms for the parts that make up methods.
We should note that terms for the whole and terms for the part are relative. The parts of the whole are not necessarily
“atomic”. (The term “atomic” comes from Greek for “not able to be cut”, or not able to be divided. It is interesting that
chemists considered their “atoms” to be indivisible, until the physicists figured out their internal structure and how they
can split apart.)
We have seen that data, especially as stored on auxiliary storage media, are commonly organized according to a data
hierarchy. A hierarchical view can also be helpful in understanding and organizing procedural logic. There is, however,
much less agreement among computer technology authors and others about the precise structure and terminology of
this procedural logic hierarchy. Second, there is a considerable amount of variation between programming languages
regarding the terms they use to identify the various aspects of procedural logic. Third, virtually all programming
languages allow the programmer unlimited levels of decomposition or aggregation within each major level of the
procedural logic hierarchy. For example, a subprogram can invoke another subprogram, which can invoke yet another
subprogram, etc. A structured construct can be nested inside another structured construct. Also, statements can be
aggregated into a compound statement, and simple expressions can be aggregated into more complex expressions. For
the above reasons, you should be rather more flexible in understanding procedural logic hierarchy compared to the
classic data hierarchy.
I would propose the following procedural logic hierarchy for general terms:
--->general terms for the whole--->
------->general terms for the parts------->
I would propose the following programming-specific procedural logic hierarchy:
--->collections of programs
----->the program
------->named modules: separately compiled/assembled modules
--------->named modules: embedded modules
----------->unnamed in-line modules
------------->structured programming constructs
--------------->steps in higher-level (3rd generation) programs: statements
----------------->steps in higher-level (3rd generation) programs: expressions
------------------->steps in lower-level (machine language (first generation)
and assembly language (second generation)) programs
I have based the definitions on several sources, including:
(1): Webster's Collegiate Dictionary, 5th ed. (1943: G. & C. Merriam Co.)
(2): Webster's New Collegiate Dictionary (1981: G. & C. Merriam Co.)
(3): Encyclopedia of Computer Science, 3rd ed., Anthony Ralston & Edwin D. Reilly, eds. (1993: Van Nostrand
Reinhold)
(4): the textbook: Programming Logic and Design, 2nd ed., Joyce Farrell (2002: Course Technology)
and, of course, my own thoughts [(ARR)].
I hope this will help clarify some of the structural issues involved with procedural logic where the textbook only
implies the relationships or leaves them unstated. Where the textbook does discuss these concepts, it generally moves
from the lower levels up to the higher levels.
533582227
-1-
03/08/2016
--->general terms for the whole--->
algorithm (2): a procedure for solving a mathematical problem (as of finding the greatest common divisor) in a finite
number of steps that frequently involves repetition of an operation; broadly: a step-by-step procedure for solving a
problem or accomplishing some end
algorithm (3, p. 37):
Hermes (1956). “An algorithm is a general procedure such that for any appropriate question the answer can be
obtained by the use of a simple computation according to a specified method. … [A] general procedure [is] a
process the execution of which is clearly specified to the smallest details.”
Minsky (1967). “… an effective procedure is a set of rules which tells us, from moment to moment, precisely how to
behave.”
Rogers (1967). “… an algorithm is a clerical (i.e. deterministic, bookkeeping) procedure which can be applied to
any of a certain class of symbolic inputs and which will eventually yield, for each such input, a corresponding
symbolic output.”
Hopcroft and Ullman (1979). “A procedure is a finite sequence of instructions that can be mechanically carried out,
such as a computer program. … A procedure which always terminates is called an algorithm.”
[The author of the article adopts the Hopcroft and Ullman definition. The requirement that an algorithm must
terminate holds even if there is no solution for a given set of inputs. Procedures are generally required to
terminate only when a solution for a given set of inputs is found, which there might not be. (ARR)]
method (1): 1. an orderly procedure or process; hence, a set form of procedure, as in investigation or instruction.
method (2): 1: a procedure or process for obtaining an object: as ... b (1): a way, technique, or process of doing
something
procedure (1): 1. Manner or method of proceeding in a process or course of action; also, a particular way of proceeding.
2. The continuance of a process or operation; progress
procedure (2): 1 a: a particular way of accomplishing something or of acting b: a step in a procedure 2: a series of
steps followed in a regular definite order <legal ~>
process (1): 2. b A series of actions or operations definitely conducing to an end; continuous operation or treatment,
esp. in manufacture; as a process of making steel.
process (2): 2 b: a series of actions or operation conducing to an end; esp: a continuous operation or treatment esp. in
manufacture
routine (2): 1 a: a regular course of procedure b: habitual or mechanical performance of an established procedure 4: a
sequence of computer instructions for performing a particular task
------->general terms for the parts------->
step (2): 5 b: a stage in a process 7: an action, proceeding, or measure often occurring as one in a series
These steps are the things that you want the computer to actually execute. Don’t confuse this type of steps with the
programming steps mentioned on pp. 5ff of the textbook (4). Those programming steps are what a programmer
typically does to develop a computer program.
action
--->collections of programs
application system: a group of application programs that coordinate by sharing data, typically via data files
----->the program
533582227
-2-
03/08/2016
program (2): 3: a plan or system under which action may be taken toward a goal 6 a: a plan for the programming of a
mechanism (as a computer) b: a sequence of coded instructions that can be inserted into a mechanism (as a
computer) or that is part of an organism
A program is generally distinguished by having a start point and (usually) a stop point. In modern computer systems, an
application program starts when it receives initial resources and control from the operating system. A very common
way of directing the operating system to start an application program is via some type of user interface, such as a
command line command, or a mouse double-click in a graphic user interface. Similarly, an application program stops
via a final or terminal relinquishing of control and resources back to the operating system. Most commonly, an
application program stops as result of an application program step.
If a program uses modular design, one of the modules (the “main” module) is designated implicitly or explicitly to
receive control from the operating system.
------->named modules: separately compiled/assembled modules
module (3, p. 898): A program or system module can be defined as a logically self-contained and discrete part of a
larger program. A complete program can thus be considered to be a collection of modules. A properly constructed
module accepts input that is well defined as to content and structure, carries out a well-defined set of processing
actions, and produces output that is well defined as to content and structure. A properly constructed module, as the
term is normally used, has only one entry point and only one exit point. If it is a subroutine, it always returns only to
the statement following the one that called it into play.
In many languages, a subroutine is functionally equivalent to a module, although most languages permit
violations of the guidelines just stated, such as allowing multiple entry and exit points.
modules (4, p. 61): Programmers seldom write programs as one long series of steps. Instead, they break the
programming problem down into reasonable units and tackle one small task at a time. These reasonable units are
called modules. Programmers also refer to them as subroutines, procedures, functions, or methods.
subprogram (2): a semi-independent portion of a program (as for a computer)
For languages that are compiled or assembled, the amount of source code submitted as a single source code file for a
single act of compilation or assembly forms a natural module. Typically, such a separately compiled or assembled
module (compilation module) will contain at least one embedded module—either the main module of the program or a
subprogram module (See below). Many programming languages now allow multiple embedded modules in a
compilation module. They may also allow the inclusion of declarations for global variables and other programmerdefined entities. These global declarations may be embedded with procedural logic modules or stand by themselves in
the compilation module.
Typically, for each act of translation, what the compiler or assembler knows about the program is only what is
presented in the source code file it is called upon to translate. It has no knowledge of other compilation modules it may
have already translated or may be called upon to translate. If a program is made up of more than one compilation
module, it requires the services of additional software, such as a “linkage editor”, or “linking loader” to tie the various
modules of the program together and put it in its final form ready for execution.
It is common for the more complex features of a programming language, such as input and output, to be implemented
implicitly or explicitly as a standard “object” library of separately compiled or assembled modules. Therefore, even if
the programmer specifies only a single compilation module, the services of a linkage editor or linking loader may still
be required in order to access and integrate needed components of this standard object library.
The linkage editor or linking loader is commonly provided as part of the operating system. In these cases, the assembly
language and major compiler languages for a given hardware and operating system platform will translate to a common
form required by those linkage facilities. This can allow modules written in different programming languages to be
linked to form a single executable program.
Because the linkage editor process takes place after all compilation of the program is complete, embedded subprogram
modules which will be invoked from other compilation modules must use an execution-time linkage implementation
533582227
-3-
03/08/2016
method. (See below.) Some programming languages allow a separately compiled/assembled module to be programmed
in such as way that either the module can be invoked from a program’s main or other modules; or it can be started and
stopped as an independent program or main module.
--------->named modules: embedded modules
I have used the term “embedded modules” to distinguish the following from compilation modules (See above).
subprogram (3, p. 1315): a portion of a high-level language program that performs a specified task necessary for that
program. This term is often used interchangeably with the term subroutine when referring to high-level languages,
although the term subroutine is more usual in the context of machine languages. … There are two kinds of
subprograms: procedures and functions.
subroutine (2): a subordinate routine; esp: a sequence of computer instructions for performing a specified task that can
be used repeatedly in a program or in different programs
procedure (3, p. 1316): a collection of code that performs an action but returns no value. … A procedure call is
therefore a statement, as statements perform actions. [See below. (ARR)]
function (2): 5 a: a mathematical correspondence that assigns exactly one element of one set to each element of the
same or another set
function (3, p. 1316): a sequence of code that returns a single value, as do mathematical functions. … Since it returns a
value, a function call is an expression. [See below. (ARR)]
local variables (4, p. 71): When you use many modern programming languages, variables typically are declared within
each module that uses them. Such variables are known as local variables. As you continue your study of
programming logic, you will learn how to use local variables and understand their advantages.
local variable (4, p. 344): Newer, more modularized languages allow you to use local variables as well. A local
variable is one whose name and value are known only to its module. A local variable is declared within a module
and ceases to exist when the module ends.
global variables (4, p. 71): For now, this text will use global variables—variables that are given a type and name once,
and then used in all modules of the program.
global variable (4, p. 344): A global variable is one that is available to every module in a program. That is, every
module has access to the variable, can use its value, and can change its value. … With many older computer
programming languages all variables are global variables.
Named modules in some high-level languages may take advantage of block structure to extend and regulate the
concepts of local and global identifiers. (See below.)
parameter (2): 1: an arbitrary constant whose value characterizes a member of a system (as a family of curves); … 2:
any set of physical properties whose values determine the characteristics or behavior of something
argument (1): 7. Math. One of the independent variables upon whose value that of a function depends.
argument (2): 6 a one of the independent variables upon whose value that of a function depends
argument (3, p. 76): In strict analogy to mathematics, where an argument of a function is the value of a variable used to
evaluate the function, an argument in computing is a value supplied to a procedure, a function, or a
macroinstruction which is required in order to evaluate the procedure, function, or macro. Another term sometimes
used instead of argument is parameter.
Two different kinds of arguments need to be distinguished: dummy or formal arguments, and actual or calling
arguments. A dummy argument is an argument used in the definition of a procedure, function, or macro; an actual
argument is that which is substituted when the procedure, function, or macro is invoked. …
… dummy arguments [may be] call-by-reference arguments in that only the storage locations but not the values
of the calling arguments are transferred to the procedure. In this way, the values given the [dummy arguments] in
the procedure are returned directly to the calling program. On the other hand, [dummy arguments may be] call-byvalue arguments in that their values are transmitted to the procedure, since there is no need to send new values of
these arguments back to the calling program.
533582227
-4-
03/08/2016
Formal arguments are always required to be identifiers, but … actual arguments may be identifiers or numbers
[or any type of constant] or arithmetic [or any other type of] expressions. Most languages allow great generality in
the form of actual arguments, although there may be requirements that the calling arguments have the same type as
the formal arguments (i.e. a real calling argument if the formal argument denotes a real variable).
Subprogram arguments may also be classified as input or output arguments, with the former denoting arguments
provided to the subprogram and the latter the arguments that convey results back to the main program. …
Sometimes an argument may be both an input and output argument. … Sometimes the arguments of a subprogram
may be implicit; i.e. they are not stated explicitly in the statement heading the subprogram. This happens, for
example, when a procedure in a subblock uses variables global to that block.
passing a variable (4, p. 350): The solution to using a locally declared variable within another module lies in passing
the local variable from one module to the other. Passing a variable means that you are sending a copy of data in
one module of a program to another module for use. Exactly how you accomplish this differs slightly among
languages, but it usually involves including the variable name within parentheses in the call to the module that
needs to receive a copy of the value. … Then, in the [called] module you declare a name for the passed value within
parentheses in the module header or introductory title statement; … The passed variable named within the module
header is called a parameter or an argument. … Declaring a variable within the parentheses of the module header
indicates that this variable is not a regular variable that is declared locally within the module, but is a special
variable that receives its value from the outside.
In some programming languages, the value (expression) that the calling module passes is called an “actual” parameter
or argument. If there are multiple values (expressions), they form an actual parameter or argument list. The
corresponding variable in the header of the called module is called a “formal” parameter or argument. If there are
multiple variables, they form a formal parameter or argument list. Most programming languages match actual
parameters to formal parameters according to their relative positions in their respective lists. In C and its descendants
(C++, Java, etc.), an actual argument is referred to as an “argument” and a formal parameter is referred to as a
“parameter”.
Some languages allow subprograms to be distinguished not only by name, but also by the sequence of parameter types
in their respective parameter lists. Subprograms which share the same name but have distinctive parameter list type
sequences are said to be “overloaded”.
Some languages, including object-oriented languages, allow (or require) subprograms (or even the main module) to be
embedded in or associated with “data” structures (“structs”), object classes, or other kinds of programmer-defined
abstract “data” types. In the case of object-oriented languages, these subprograms are usually referred to as “methods”.
These subprograms are invoked in conjunction with or via a message to a particular struct variable, object, object class,
etc. There is usually some facility by which the programmer writing the subprogram may access the particular entity
that the subprogram was invoked in conjunction with or as a message to. Subprograms in different abstract data types
may share the same name. This is referred to as “polymorphism”. The abstract data type of the particular entity by
which the subprogram is invoked, and possibly the resolution of “overloading”, determines which subprogram is
actually applied. Object-oriented programming languages provide for additional refinements, such as “inheritance” and
control over access to attributes and methods. The definition of the abstract data type may itself act as a named
embedded module.
returning a value (4, p. 352): the [called] module must return the value … back to the [calling] module. Just as you
can pass a value into a module, you can pass back, or return a value to a calling module. Usually, this is
accomplished within the return statement of the called module
Some languages provide for more than one implementation method for named modules. The most common
implementation method uses an execution-time “linkage”. The translator arranges for a single copy of the machine
language object code of the module to be stored in a separate area of memory “out-of-line” of the flow of control of any
calling module. Each invocation of the module in calling program’s source code is translated into a machine language
“calling sequence”. At execution time, the calling sequence arranges for the passing of data to the called module, if
required. It also establishes a linkage back to the instruction in the calling module that immediately follows that
particular module invocation. Then it transfers control to the entry point of the called module’s object code. When the
called module exits or returns, it establishes the return of data back to the calling program, if required; and uses the
533582227
-5-
03/08/2016
linkage established by the calling sequence to return control to the calling program. Virtually all machine language
architectures have some feature or features to help implement execution-time calling sequences.
There may be a “light-weight” form of named modules that only share data and other entities “globally” and do not
provide for argument/parameter lists, local variables, or other local programmer-defined entities. The COBOL
Procedure Division, for example, provides for programmer named “sections” and “paragraphs” that can be called from
other sections or paragraphs. BASIC provides for programmer labeled sequences of statements, which can be called
from within a program. Lower-level languages also commonly provide a light-weight module form. Light-weight
modules typically use a simplified form of execution-time linkage for implementation.
Another implementation method for embedded named modules is the “macro”. When the named macro is invoked, the
translator replaces the invocation with the related source code for the invoked module. The resulting source code is
then translated as if the programmer had written it “in-line”. Compiled and assembly languages commonly provide a
macro facility.
A third implementation method is the named “inline” module. In this case, the translator translates the module when it
is defined. When the module is invoked, instead of creating an execution-time linkage to the module located out-ofline, the translator inserts a copy of the module’s translated code at the point in the program (that is, “inline”) where the
module was invoked.
For both macros and named inline modules, the translator may provide for translation-time linkage between arguments
(expressions) and parameters (variables). The distinction between the various methods of implementing embedded
named modules has little significance for interpreted languages.
Textbook (4): Chapters 3, 12, & 14
----------->unnamed in-line modules
block structure (3, p. 133): a programming language concept that allows related declarations and statements to be
grouped together. [See below. (ARR)] When used judiciously, it can help transform a large, unwieldy program into
a disciplined, well-structured, easy-to-understand program.
Because of the important function it performs, block structure (first introduced in ALGOL 60) is found in one
form or another in many procedural languages developed after 1960. …
From the programmer’s point of view, block structure performs two major functions:
1. It allows a sequence of executable statements to be grouped into a single compound statement.
2. It provides explicit control over the allocation of storage to variables and over the programmer’s ability
to refer to variables [and other programmer-defined entities (ARR)].
The first function means that we can create and use a compound statement anywhere that the programming
language allows a single statement to be used (e.g. in either branch of an if-then-else statement [See “structured
programming constructs”, below (ARR)]). This allows us to think of a sequence of statements as a single entity and
thus simplify the process of program construction.
Since a block may contain other blocks as components, block structure can be used to decompose a large
program into an orderly nest of blocks. This is perhaps the most important use of block structure from the
programmer’s point of view, since it allows programs to be constructed in a hierarchical fashion which often results
in increased program clarity and elegance.
Control over storage allocation and visibility of variables [and other programmer-defined entities] implies two
things. First there is the ability to control dynamically the allocation and freeing of storage during program
execution. The storage for variables [and other programmer-defined entities] declared within a block is allocated
when the block is entered during program execution. Unless explicitly inhibited, this storage is freed automatically
when the block is exited.
Second, each block introduces a new scope (i.e. a domain of definition of variables [and other programmerdefined entities]). Variables [and other programmer-defined entities] declared within a block (i.e. local to the block)
may be used only within that block (and any contained block). Thus, variables [and other programmer-defined
entities] declared within a block can have no effect on the program outside the block. This provides a degree of data
security, since a programmer can use a block to “hide” variables [and other programmer-defined entities]
(information hiding) and thereby make them inaccessible outside of this block. …
533582227
-6-
03/08/2016
Scope Rules A block body is a sequence of executable statements and a block is itself an executable statement.
Therefore, blocks may be nested to any depth. This has several consequences:
1. Although an identifier may be used only once as the name of an object in a block, the same identifier
may be used to name different objects in different blocks. A good programmer will use this facility
sparingly (e.g. for utility variables like i, j, k used as counters and loop indices). Widespread re-use of
identifiers can make a program difficult to understand.
2. If the same identifier is used to name objects in several nested blocks, the programming language’s
scope rule is used to disambiguate references to the identifier. The ALGOL 60 scope rule (used in most
procedural languages) starts at the point where the identifier is used and searches block heads
[declarations preceding the identifier usage in the block] starting with the block containing the use of
the identifier and working outward toward the main program block until a declaration of the identifier
is found. Note that with this rule the redeclaration of an identifier in an inner block will make the object
named by the same identifier in an outer block inaccessible [unless the language has some other scope
resolution facility]. …
3. Whenever a block is entered during program execution, fresh storage is allocated for all the variables
[and other programmer-defined entities] declared in the block head. This storage, known as the
activation record of the block, defines a particular instance of the block in time. When execution leaves
the block, the storage occupied by the activation record is freed. In most procedural languages, the
allocation and freeing of activation records follows a strict last-in-first-out discipline. This implies that
a stack mechanism is ideally suited for the storage of activation records. This also facilitates the
implementation of recursive procedures [procedures that directly or indirectly invoke themselves
(ARR)].
Beginning with COBOL 85, an entire program definition (including IDENTIFICATION, ENVIRONMENT, DATA,
and PROCEDURE DIVISIONS) may be embedded as a block in an enclosing Procedure Division or other appropriate
context. The COBOL Procedure Division (all versions) also provides for the concept of a “sentence”. A sentence
consists of one or more statements (including structured programming constructs), and ends with a period. A paragraph
must contain at least one sentence. The statements within a sentence may be nested. However, sentences may not be
nested within one another.
------------->structured programming constructs
control structure (3, p. 361): a programming language construct that specifies a departure from the normal sequential
execution of statements.
In its broadest sense, this includes calling a procedure, resuming a coroutine, and initiating tasks, all of which
involve transferring the path of execution to another program unit. (In the case of recursion, the “other” program
unit is a copy of the calling program.) It also includes, in its broadest sense, the “parallel” (simultaneous)
performance of two or more operations within a given program unit.)
In its more common usage, however, control structure refers to the facilities for controlling the sequence of
statements within a given program unit, and includes special facilities for selection control, repetition control, and
exception handling. … Usually, such facilities are in the form of “extended” statements [See below. (ARR)],
involving several parts in different lines—hence, the term control structure.
structured programming (3, p. 1308): (SP), a methodological style whereby a computer program is constructed by
concatenating [literally, “chaining together”; that is, connecting serially, end to beginning (ARR)] or coherently
nesting logical subunits that either are themselves structured programs or else are of the form of one or another of a
small number of particularly well-understood control structures. Such a definition [but not necessarily the
procedural logic] is inherently and deliberately recursive.
structure (4, p. 31): a basic unit of programming logic; each structure is a sequence, selection, or loop. With these three
structures alone, you can diagram any event, from doubling a number to performing brain surgery.
sequence (4, p. 32): The first of these structures is a sequence … . With a sequence, you perform an action or event,
and then you perform the next action in order. …
selection (4, p. 32): The second structure is called a selection, or a decision … . With this structure, you ask a question,
and depending on the answer, you take one of two courses of action. …
533582227
-7-
03/08/2016
loop (4, p. 33): The third structure, …, is a loop. You may hear programmers refer to looping as repetition or
iteration. In a [pre-test] loop, you ask a question; if the answer requires an action, you perform the action and ask
the original question again. … This continues until the answer to the question is such that the action is no longer
required; then you exit the structure. … (often called a “do while”) … In a [pre-test] do while loop, you ask a
question and, depending on the answer, you might never enter the loop to execute the loop’s procedure. [p. 52]
stacking (4, p. 34): Attaching structures end-to-end is called stacking structures.
nesting (4, p. 35): Placing a structure within another structure is called nesting the structures.
case structure (4, p. 49): You use a case structure when there are several distinct possible values for a variable you are
testing. [Some programming languages allow you to test any type of expression, not just a variable. Other
programming languages restrict you to testing integer (or integer-related) type variables. (ARR)]
do until loop (4, p. 52): in a [post-test] do until loop you ensure that the [loop] procedure executes at least once; then
depending on the answer to the controlling question, the loop may or may not execute additional times.
Textbook (4): Chapters 2, 5, & 6
--------------->steps in higher-level (3rd generation) programs: statements
statement (3, p. 1280): In much the same way that a sentence is the structural unit of expression in a stream of natural
language discourse, the statement may be viewed as the elemental organizational component of a high-level
language program. As such, it embodies a unit of activity in terms of the algorithm being implemented. This is quite
different from, and bears no direct correspondence with, processor activity [involved in the execution of the
program. See the discussion of lower-level language steps, below. (ARR)]
Many high-level programming languages distinguish between statements and expressions (but see the discussion of
expressions below). While a statement may certainly cause values to be input, processed, stored, output, etc., its main
focus is on a particular action, and the precise location of that action with respect to the overall procedural logic. The
statement, taken as a whole, is not thought of as “having a specific value” which could be used in further processing or
output.
On the other hand, while an expression may certainly include symbols that affect or influence the order of execution or
evaluation, its main focus is on calculating a value in whatever manner the translator finds most convenient, provided
the rules of expression evaluation are honored. The expression, or sub-expression, is thought of as “having the specific
value” which its symbols, taken as whole, imply. That value may be combined with other expressions or used in
statements for further processing or output. Any other change in the state of memory, storage, the CPU, etc., which
might result from the evaluation of the expression, is considered to be a “side effect”. (Side effects can be tricky but
sometimes useful.)
The variable is a special case. When used in or as an expression, it “has a specific value” just as expressions in general
do. However, it is also able to receive a value by definition, or through input or assignment. The specific value of the
variable then is just the most recent value that it has received. If a variable has never received a value (been initialized),
in many languages its value will be undefined.
The statement form may also be used for declarations and other elements of the language which provide information to
the translator but do not result directly in execution-time machine language code.
Textbook (4): Chapter 1
----------------->steps in higher-level (3rd generation) programs: expressions
expression (1): 6. Math. A group of characters or signs, esp. algebraic symbols, representing a quantity or operation.
expression (2): 1 b (3): a mathematical or logical symbol or a meaningful combination of symbols
expression (3, p. 540): An expression, one of the fundamental constituents of high-level language syntax, is a character
sequence that specifies a rule for calculating a value. That value may be either numeric … or alphanumeric.
533582227
-8-
03/08/2016
[Commonly, values may also be bitwise (“strings” of ones and zeros) or logical/Boolean (a result that is “true” or
“false”. In some languages bitwise and logical values may be distinct data types. In other languages, they may be
specialized usages of another data type, such as “integer”. (ARR)] An expression may appear [as part of a
statement] … in statement-oriented languages such as Pascal or FORTRAN [or COBOL, BASIC, C, C++, or Java],
or may stand alone and be evaluated immediately to yield a particular value in expression-oriented languages such
as Lisp or APL. [Note that authors differ as to how to classify both Lisp and APL. (ARR)]
Boolean expression (4, p. 113): A Boolean expression is one that represents … one of [only] two states, usually
expressed as true or false. Every decision you make in a computer program involves evaluating a Boolean
expression.
ALGOL 68 is interesting in that it is based on a statement-oriented language, ALGOL 60, but completely dissolves the
distinction between expressions and statements. Everything, except declarations, is considered to be a “clause”. The
concept of a “phrase” encompasses both declarations and clauses. Phrases can be separated by a comma where
collateral evaluation is acceptable. Phrases can be separated by a semi-colon where sequential evaluation is required.
When a value must be discarded because only an action is required, the language provides a “coercion” called
“voiding”.
C and its descendants (C++, Java, etc.) do not go quite as far as ALGOL 68, but they do fuzz things up rather a lot.
They provide for an “expression statement” (an expression followed by a semi-colon) in place of “voiding”. They
consider assignment to be an expression rather than a statement. They implement virtually all input/output as functions
or operators. So, these features, as well, are fundamentally expressions rather than statements. Of course, you may
place these “expressions” in expression statements and make them, in effect, statements. In addition to the usual
selection constructs, which they consider to be statements, they provide a “ternary conditional” operator, which selects
between two values (expressions), based on a conditional (logical/Boolean) expression. All subprograms are
“functions” (hence, expressions. See above.). However, a function may be defined as returning “void” when a return
value from the subprogram is never required, such as when all its calls are the only expressions in expression
statements. These languages provide a comma operator which allows for the sequencing of expressions, much like a
sequence of statements. The entire sequence acts like a single expression. If the context requires a single value, the
value the expression sequence provides is the value of the last expression in the expression sequence. It may be
necessary to enclose an expression sequence in parentheses to avoid ambiguity with other uses of the comma, such as
in argument or initializer lists.
operation (1): 7. Math. Some transformation, indicated by rules or symbols, to be made upon quantities.
operation (2): 5: any of various mathematical or logical processes (as addition) of deriving one expression from others
according to a rule
arithmetic operation statements (4, p. 12): are examples of processing.
text or character data (4, p. 23): Every computer and every computer application handles text or character data
differently from the way it handles numeric data. Every programming language requires that you distinguish
variables as to their correct type and that you use each type of variable appropriately. (For example, you cannot
perform arithmetic calculations with string data.)
operator (2): 3 a: a mathematical or logical symbol denoting an operation to be performed b: a mathematical function
logical comparison operators (4, p. 114): Each programming language supports its own set of logical comparison
operators, or comparison symbols, that express these Boolean tests. For example, many languages use the equal
sign (=) to express testing for equivalency …
NOT comparisons (4, p. 117): Although NOT comparisons can be awkward to use, there are times when your meaning
is clearest if you use one. For example, the mainline logic of many programs … includes a statement like while
not eof, perform mainLoop().
logical AND operator (4, p. 124): Most programming languages allow you to ask two or more questions in a single
comparison by using a logical AND operator.
logical OR operator (4, p. 131): most programming languages allow you to ask two or more questions in a single
comparison by using a logical OR operator—for example, …
Textbook (4): Chapters 1 & 5
533582227
-9-
03/08/2016
------------------->steps in lower-level (machine language (first generation)
and assembly language (second generation)) programs
Machine language code is the form that procedural logic must ultimately take in order for it to be executed by the CPU.
Every CPU “family” or “architecture” has it own particular form of machine language, which is incompatible with the
machine language of other CPU families or architectures. Basic assembly language (a second generation language)
follows the structure of the machine language for its particular processor “family” or “architecture” very closely.
Usually, one basic assembly language instruction generates one machine language instruction. High-level languages
(3rd generation or higher) must also have some form of machine language as their ultimate object, usually through some
sort of translation process, such as a compiler or an interpreter.
However, not every assembly language or high-level language instruction, expression, or statement necessarily results
directly in “execution-time” machine language. Assembly and high-level languages usually have one or more types of
“non-executable” instructions or statements. These typically include definitions, declarations, and declarative
statements. Non-executable instructions and statements typically provide information to the particular translation
software you are planning to use. In addition, high-level languages usually have several types of “aggregation devices”
which affect the way machine language is generated but may not generate machine language code in and of themselves.
For example, parentheses group simpler expressions together mainly to affect the order in which operations are
evaluated and thus affect the order of instructions at the machine language level. Also, devices, such as curly braces
and terminators (e.g. endif), may be available to group statements together, mainly to control the scope of definitions
and declarations or to control the extent of selection and repetition constructs.
“High-level” assembly languages present a second exception to the one-to-one relationship between assembly language
and machine language instructions. They typically provide facilities, such as “macros”, that allow a single assembly
language instruction to generate multiple machine language instructions.
instruction (2): 1 d: a code that tells a computer to perform a particular operation [and, commonly, what data or device
to perform the operation on and where to save the result (ARR)]
instruction (3, p. 684): A machine instruction is a string of digits in the base in which the machine operates which,
when interpreted by the hardware, causes a unique and well-defined change in the state of the computer.
Most computers are based on the binary system. For most cases, therefore, the “string of digits” will be a string
of bits, each having the value 0 or 1. … we [commonly] express those bits using hexadecimal notation.
In the definition given, the words “interpreted by the hardware” really mean “used by the hardware”. The
change in state of the machine is, in fact, a change in the contents of various registers or memory locations. …
The types of operations available on contemporary machines are roughly divided into arithmetic, logical, data
move [i.e. data copying, including register, memory, and input-output instructions], and control operations …
[including] conditional and unconditional branches, test instructions, and status-changing instructions.
operation (2): 8: a single step performed by a computer in the execution of a program
We can take decomposition in the procedural logic hierarchy even lower than a single machine language instruction. In
order for the CPU to fetch, interpret, and execute a machine language instruction, the CPU hardware must perform a
series of steps, that is to say, a procedure, commonly known as the “instruct-execute cycle”. At the most basic level,
these steps are “wired” into the electronic circuitry of the CPU. However, if the operation specified by the machine
language instruction is fairly complex compared to the CPU design philosophy, there may also be an intermediate level
of “microcode” between the machine language instruction and the “wiring”. The microcode sequences that specify the
action of various complex operations are typically stored in very high speed read-only memory on the CPU chip itself.
As a programmer in a high-level language, you may never need to know the precise machine language form that your
programs will take. It may be helpful, though, to understand that the appropriate translation software must be able to
break the executable statements and expressions of your program down to particular sequences of machine language
instructions. Studying the machine language of your particular computer architecture or of computer architectures in
general, may help you understand how to write more time and space efficient high-level language programs.
-----
533582227
- 10 -
03/08/2016
Download