SD Languages and Environments Notes [doc] - Crieff High School

waisttherapeuticΛογισμικό & κατασκευή λογ/κού

4 Νοε 2013 (πριν από 4 χρόνια και 1 μήνα)

101 εμφανίσεις



Page
1

Higher


Software Development

Section

2

October 20
09

Crieff High School



Introduction


In the first section of this Unit we considered the software development process and at the
outset we stated that the implementation could be done through writing a program in a
computer language or through using a general purpose package.


Let us now look at each of these in turn, starting with:



Computer Languages


The fundamental processor language is machine code (a binary code). The difficulty of
programming in machine code quickly led to the development of other levels of language:


machine

assembly

high level

code

languages

languages


Assembly language

is a set of mnemonics for each of the machine code operations and is
translated by an assembler so that each mnemonic becomes one machine code instruction.


High level languages

frequ
ently use words of English and each high level language
instruction is translated by an interpreter or a compiler into a series of machine code
instructions.


As the graph indicates the relative cost of hardware to software has changed from the bulk
being
the cost of the hardware to the bulk being the cost of software.


1960

2000

Software

Development

Costs

Hardware

Costs

0%

100%



Sec
t
ion

2

Higher


Software Development

Page
2

Crieff High School

October

200
9

This has occurred due to the automated assembly of hardware and the increased speed,
reliability, capacity and reduced size of the components used as valves were replaced by
transistors th
en integrated circuits and finally silicon chips.


At the same time the increased capacity of the hardware has resulted in the production of
larger, more complex programs which require huge amounts of time to produce by human
methods (e.g. 10 man years to
produce a modern software package is quite common). This
has led to improvements in languages and programming environments to speed up software
development and simultaneously reduce costs.



High Level Languages


High level language is a general term, enc
ompassing an enormous range of language types.
The following features are common to most high
-
level languages:


a)

the language instructions are problem
-
oriented rather than machine
-
oriented;


b)

the source program must be translated into machine language
;


c)

in translation, each high
-
level language instruction is equivalent to more than one
machine language instruction i.e. there is not a one
-
one correspondence;


d)

the language has a degree of independence from any single machine i.e. it may be
used on
different computers with minimal adaptation
-

portable.



High level languages may be classified by the language structure:



We only have to consider procedural, declarative
, event
-
driven

and scripting languages in this
course.


Procedural Languages


Pro
cedural means a sequence of steps to a result. Examples of procedural languages are
BASIC, Comal, Pascal, FORTRAN, COBOL and Algol. All of these provide statements that
describe the steps required to solve a problem.

High Level Languages

Scripting

Procedural

Event
-

Driven

Declarative



Page
3

Higher


Software Development

Section

2

October 20
09

Crieff High School



Declarative Languages


A declarative

language provides a method of declaring facts, rules or relationships between
the facts and a way of asking queries about this structure (or database). The programmer has
no control over how the query is answered. Examples of declarative languages are
P
ROLOG, LISP and Smalltalk.


PROLOG

-

An Example


Family Tree




Facts

female(sarah).

male(abraham).

male(isaac).

male(ishmael).

parents(isaac,abraham,sarah).

parents(ishmael,abraham,sarah).


Rule

brother(X,Y) if male(X) and parents(X,A,B) and parents(Y,A,
B).


Queries

?
-

female(sarah).

Yes

?
-

female(isaac).

No

?
-

brother(isaac,ishmael).

Yes


Event
-
Driven

Languages


An event is a user action that has program code attached to it. Statements are executed when
the user carries out the action. For example,
the user may click a button or an icon
, select an
option from a pull
-
down menu

or drag a picture or text box to a new position. In each case
the programmer has written code associated with each event.


This is how y
ou interact with a WIMP program
e.g.


I
n

Word, you can click an icon on the toolbars and a sequence of programmed steps takes
place such as the document is pr
inted;

or
you can click on a down arrow to open a list such as selecting a font or size;

or you can select a menu option and a dialog box
opens to allow you

to select features
and
make entries such as File
-
> Save As… and then, of course, the next event is probably to
click OK when the appropriate code is executed to save your file with the name and file type
and in the folder that you speci
fied.


Visual Basic

is an example of an
event
-
driven language
.

The Microsoft Office suite of
programs was written using a version of this called Visual Basic for Applications.

Abraham m Sarah

Isaac

Ishmael



Sec
t
ion

2

Higher


Software Development

Page
4

Crieff High School

October

200
9

Scripting Languages


Scripting languages are built into applications packages
and are not stand
-
alone programming
languages. HTML (Hypertext Mark
-
up Language) is a scripting language that is used to
control the display of web pages on the Internet. HTML tags are added to the text and
graphics on the page and interpreted by the rec
eiver’s browser program (e.g. Internet
Explorer).


Another example is the scripting language in HyperStudio that is used to specify actions
during multimedia presentations.


In G
eneral
P
urpose
Packages,
macros

collect a sequence of individual steps or comm
ands as
one unit with an operation name. Using this name the operations can be automatically
repeated.


Macros can be “recorded” to create a file of data selections, menu selections, options, entries,
i.e. mouse and key operations, for a certain task e.g.

creating a bar chart

from spreadsheet
data
. Then using the filename will automatically repeat the steps.


This saves time for regularly repeated tasks and allows unskilled users to achieve complex
tasks.

In both cases the us
er will not make errors
or
mi
ss out a step.


Here is a

simple

macro
to insert a new row
in

an

Excel

spreadsheet
:


Sub InsertLine()






InsertLine Macro



Inserts a new line in the Products Table





Keyboard Shortcut: Ctrl + Shift + I





Range(“A3”).Select



Selection.End(x1Down).
Select



Selection.EntireRow.Insert

End Sub


This was constructed by the user selecting from the pull down menus, selecting cells etc.
Excel recorded the steps and produced the
scripting language
code above for the task being
carried out. This code can n
ow be run anytime the task is to
be
repeated
,

either by selecting
to run the “InsertLine” macro through the menus or with the keyboard shortcut,
without
interference or errors by the user.


Of course, unlike programming in a high
-
level language, the user d
oes not have to learn the
grammar and meaning

of the statements.



Page
5

Higher


Software Development

Section

2

October 20
09

Crieff High School



Examples of High Level Languages


High level languages are problem
-
oriented so languages are designed for specific problem
areas:


Area of Use

Language

Commercial

COBOL



C潭o潮⁂畳楮敳猠佲
楥湴i搠ianguage.†䕶 渠n晴f爠㐰ryea牳r
瑨t猠楳⁳瑩汬⁴桥潳 ⁣潭浯渠ma湧畡来⁩渠畳e⸠⁁.⁰牯 牡浳⁡me⁣hea灥爠
瑯⁵灤慴t⁴桡渠 ew物瑥Ⱐ灲潧ra浭e牳⁣潮瑩湵n⁴漠 ea牮⁃佂ri⁡湤⁳漠n琠
灥牳楳r献

pc楥湴楦楣

FORTRAN



c佒l畬愠呒䅎獬慴楯渮†T佒呒䅎⁨ 猠浡sy⁢畩 t
-
楮i
浡瑨m浡瑩捡氠晵湣瑩潮猠o湤⁨n湤汥猠湵浥物rⁱ an瑩瑩e猠楮any⁤ 晦e牥湴n
睡y猠s.g⸠摯畢汥⁰.ec楳io渠n湤⁳na湤n牤r景f洮

䕤畣a瑩潮

BASIC



Beg楮湥i猠䅬s
-
灵牰p獥⁓y浢潬楣if湳瑲nc瑩潮⁃潤o


睡猠
摥癩獥搠瑯⁴eac栠he潰汥⁴漠灲o杲g洠⡢m摬y>⤮†F癥ry ea牬y c
牯c潭灵oe爠
ca浥⁷楴栠h⁶e牳楯渠潦 B䅓fC.

Pascal



e湣潵oage猠獴牵c瑵牥搠灲dgra浭楮i a湤n楳⁷楤ely⁵獥搠楮d
c潬oe来猠s湤⁵湩癥牳楴re献

COMAL



C位浯渠䅬l潲楴桭楣iianguage


wa猠摥獩sne搠瑯Ⱐ
“combine the simplicity of BASIC with the power of Pascal.”

f湤畳nr
楡i

APT



䅵瑯浡瑩Aa汬y⁐r潧ra浭e搠呯潬猠


睡猠se癥汯灥搠瑯⁰l潤畣e
灵湣栠瑡灥猠景爠湵浥物ra汬y
-
c潮瑲潬oe搠dac桩湥⁴h潬献

Cogo




-
潲摩湡瑥⁇eo浥瑲y


睡猠摥ve汯灥搠l漠灥牦潲洠ge潭e瑲楣
ca汣畬l瑩潮猠o渠n楶i氠敮g楮敥物rg⁡湤⁳n牶ry楮g.

f湴n牡c瑩癥

Visual
Basic



a汬潷猠瑨e⁰牯g牡浭e爠瑯⁤r獩g渠獣牥e湳n睩瑨⁷楮摯睳Ⱐ
扵瑴潮猬楳i⁢ xe猬⁳捲潬o 扡牳⁥瑣⸠a湤⁴桥渠瑯⁰no杲g洠m桥⁲ 獵汴映a渠
e癥湴⁳畣栠n猠浯s獥⁢畴 潮⁰oe獳敤Ⱐ摲ag⁡湤⁤no瀠p瑣t

C++

-

is used to program operating systems and applicatiosn such

as
word processors.

Other

TUTOR



畳u搠景d⁣潭灵瑥p⁡楤敤⁩湳i牵r瑩潮o


a渠n畴桯物ug慮g畡来.

CDL



C潭灵oe爠re獩sn ianguage


畳e搠楮⁣潭灵瑥p⁡楤敤⁤i獩g渮

IMS



fn景f浡瑩潮⁍慮mgeme湴⁓y獴敭s


畳u搠楮⁤ 瑡扡獥慮age浥湴m
sy獴敭献

CSSL



C潮o楮畯畳⁓y
獴e洠m業畬慴楯渠uang畡ge


畳u搠楮⁣潭灵瑥d
獩s畬慴楯湳⁩渠楮摵n瑲y.




Language Environments



Selecting a Language


One critical stage in solving a computing problem is the selection of the language/package
best suited to the task. Many problems can b
e solved with the use of a standard general
purpose package which includes, for example, sort, search and report facilities.


A high level language will be chosen if no suitable general purpose package exists. The next
crucial decision for the programmer
s

is “which language?”. Obviously the task in hand is the
key consideration
-

which language will provide the features required to solve the problem?



Sec
t
ion

2

Higher


Software Development

Page
6

Crieff High School

October

200
9

The programmer
s

would assess the range of available languages, examining the standard
features, such as:


character set

ASCII, foreign language characters
, Unicode

procedures and functions

ready written e.g. graphics functions

data types

real, integer, string, arrays, records etc.

input / output facilities

I/O from a variety of peripherals

e.g. bar code reade
r

control structures

IF…THEN…ELSE…ENDIF, CASE, loops

program structure

declarations, order of procedures


These features can be used to do an initial sifting
-
out of unsuitable languages. For example,
the business
-
oriented languages would be ruled out for
a
scientific
number
-
crunching task on
the basis that they do not have a good range of mathematical functions.


Often several high
-
level languages will prove to be suitable for the task
-

then the
programmer
s

will scrutinise the software development tools a
vailable for each.



a)

T
he
text editor

-

to enter and edit the source program
-

should be equivalent to a word
processor e.g. block operations (cut, copy, paste), search and replace.


b)

T
he
linkage editor

-

to combine pre
-
compiled machine language progr
ams from a
module library into a complete unit e.g. a set of graphics routines

or sound procedures
.


c)

T
he
compiler

(or interpreter)
-

to decode the source program statements and produce a
machine language program
-

quick compilation as every edit means a
nother compilation;
efficient allocation of memory for the source program and the object code; “lean” object
code i.e. compact and giving fast object code execution time.


d)

A

formatter

-

to produce a clear and readable structured listing from the source

program
-

indentation when a structure is entered.


e)

A

de
-
bugging / trace facility

-

to aid the detection / location of errors
-

a “trace”
displays the sequence in which the source program instructions are executed

and allows
the programmer to step thr
ough one instruction at a time

watching

the result of each
instruction by displaying the current values of some or all of the program variables.

error

reports

error

reports

linkage

editor

modul
e

library

Machine code

object
program

compiler

text

editor

source

program



Page
7

Higher


Software Development

Section

2

October 20
09

Crieff High School



Compilers and Interpreters


A
compiler

takes the source code program written in the high
-
level language and tr
anslates
the whole program into a machine code object program. This machine code can then be
saved and run on another computer with the same type of processor without either the source
code or the compiler being present. A machine code object program is
what you get when
you buy software e.g. a game or Microsoft Office.


An
interpreter

translates one line of the source code program and executes the machine code
instructions before discarding the machine code and translating the next line of the source
cod
e program. It continues this sequence of translate and execute until the program ends.

The source code is saved and to run it on another similar computer

you require to have the
source code and the interpreter in memory.


Errors


A compiler creates a lis
t of all the syntax errors that it encounters during the translation of the
whole program. The programmer is then faced with a list of errors and associated error
messages to rectify. This would be disheartening to beginner programmers and also many of
t
hese errors will be as a result of one error early in the program and may not need changes
once the initial error is corrected. Until compilation is successful no execution take
s

place.


An interpreter will report each syntax error as it meets it and
it
s
tops program execution

at
that point. Many interpreters attempt to translate each line as it is entered through the text
editor and so find all syntax errors before a run is started.


Efficiency


Compilers produce more efficient code and, of course, progr
am execution is much faster as
no translation takes place during the execution phase.


Interpreters must re
-
translate every statement in a loop every time round that loop and, due to
this and the translation phase, program execution

is much slower.


Ease o
f Use


Interpreters are more helpful to beginners in programming as they allow fast editing and re
-
runs of the program. They are also appropriate here as beginners will not write large
programs where speed of execution is crucial.


Module Libraries


Often

high
-
level languages will have sets of pre
-
written routines associated with them e.g. a
set of graphics routines where by inserting

a linking statement to the graphics routines a
programmer can
use a statement such as circle(100, 140, 50) to draw a
circle with centre
(100, 140) and radius 50 without having to create the mathematical routine to draw a circle.


Every software house will create its own module library of pre
-
written and fully tested and
documented procedures which any of its programmers
can insert into any of their programs
or modules confident that the procedure will work correctly.



Sec
t
ion

2

Higher


Software Development

Page
8

Crieff High School

October

200
9


QUESTIONS


1.

Why were high level languages developed?


2.

Explain clearly the difference between a procedural language and a declarative language.


3.

For

each of the languages COBOL, COMAL and Visual Basic, describe:


a)

W
hy each was developed.


b)

I
n which application areas each is used.


4.

Describe what a scripting language is and give an example of such a language.


5.

Describe two benefits of having a

sequence of operations stored as a macro.


6
.

If you could program in Pascal and PROLOG and you were asked to write a Windows
application program, suggest two languages that you might use. Why might you be
reluctant to use either of these?


7
.

For a high

level language with which you are familiar, describe the text editing facilities
which are available.


8
.

Explain why high level languages are described as being “problem
-
oriented” while low
level languages are described as being “machine
-
oriented”.


9
.

F
or a high level language with which you are familiar, answer:


a)

Does the language provide structured listings? If it does, why do you think that this
is valuable?


b)

What utility routines are available e.g. auto numbering and renumbering?


c)

Is syntax

checking performed on line entry or at run time? Which method do you
think would be better?


d)

Is there a de
-
bug facility for detecting and reporting errors in program structures?


e)

How easily can sub
-
programs be taken from a library and combined?


f)

How helpful do you think the error messages are?


10
.

What is the most important advantage of using an external module library rather than
merging the required modules
i
nto your program.


11.

Compare the operation of a compiler and an interpreter will ref
erence to:


i)

their method of translation;

ii) error reporting;

iii) their efficiency.



Page
9

Higher


Software Development

Section

2

October 20
09

Crieff High School



Multiple Choice Questions



1
.

Which one of the following statements about interpreters is true?


A

Interpreters translate the program creating an object code file.

B

Interpreters translate one statement at a time and execute it.

C

Interpreters report all the syntax errors at one time.

D

Interpreted programs run faster than compiled programs.



2.

Which of the statements below describes a module library?


A

A set of pre
-
tested modules which can be used in a program.

B

A list of all the modules used in a program.

C

A file of the source code of the program.

D

A set of pre
-
written modules used to test a program.


3
.

Which of the following statements about compilers is false
?


A

A compiler will not run a program if a syntax error is found.

B

A compiler translates a program and creates an object program.

C

Different hardware and software platforms require different compilers.

D

Compilers translate and execute a program line by

line.