meljun cortes manual structured programming language csci07
TRANSCRIPT
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
1/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
INTRODUCTION
1.1 PROGRAM LANGUAGE DEFINITION
PROGRAMMING LANGUAGE
Is a notation for expressing instruction to be carried out by a computer
Is a communication between the human and the machine and often between one
human being and another.
1.2 REASON WHY STUDY PROGRAMMING LANGUAGE
1. To be able to study a new language2. To increase program vocabulary3. To have a better understanding of the language you are using4. To make it easier to design a new language.. !uit the needs of the system
1.3 THE PROGRAMMING FUNCTION IN SYSTEM DEVELOPMENT
SYSTEM DEVELOPMENT LIFE CYCLE
"igure 1.#
REQUIREMENT SPECIFICATION-This step includes a problem definition as well as
analyses of the current system and of the firm$s goals in developing the newcomputer system.
EVALUATING ALTERNATIVES- These alternative s are tested for feasibility
including technological feasibility %&an it be built'() economic feasibility %&an weafford it'( and behavioral feasibility %&an it be implemented with a minimum traumato the firm and its personnel'(
PURCHASE AND CONSTRUCTION- *nce management decides on the appropriate
system) it must be +built,. "or hardware this almost always means purchase whilesoftware can either be purchased or constructed.
IMPLEMENTING AND TESTING- The various components of the system are
integrated and put into working order. The system is tested for errors and these errorare corrected.
MAINTENANCE-Takes place throughout the lifetime of the computer system
1| - a g e
e/uirement !pecification
0valuating lternatives
-urchase and &onstruction
Implementing and Testing
aintenance
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
2/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
TRANSFORM
GENERALIZING THE PROGRAMMING FUNCTION
THE PROBLEM
PROGRAMMING MYOPIA-Is characteried by dependence on the particular programminglanguage
THE SOLUTION
In order to step beyond language) we must first of all have at least rudimentary
understanding of many different kinds of languages and many different ways ofprogramming solution. e must understand and generalie the vast conceptualcommonalities in programming languages rather than emphasie the artificialsyntactic differences.
THE FUTURE OF PROGRAMMING
-rograms are getting larger re/uiring more effort out of more programmers over
larger periods of time.
The ability to use the variety of languages will ensure the best fit for the application.
The construction of large program from blocks of relatively independent yet
interrelated program code has been popular for a long time this type of programdesign has been called modular decomposition of programs.
PROGRAMMING FUNCTION SPECIFIC CONCERNS ARE:
hat hardware will be used'
hat people will use the system'
hat procedure will the system implement'
1.4ABSTRACTION FUNCTION
ABSTRACTION- Is the means by which we consider only the information that is elevant tothe problem at hand) ignoring trivial details and unimportant facts'
BLAC BO! MODEL- 5eneral model governing abstraction adapted from the
engineering disciplines.
I6-7T! *7T-7T!
"igure 1.1
1." BASIC PRINCIIPLES OF PL
1.# SYNTA!
ules8 format in writing the program
5rammar
2.# SEMANTICS
The meaning of the different syntactical constructs of -9
3.# PRAGMATICS
The uses) origin and effects of the programming language
1.$ DIFFERENT INTEREST THAT CON%OIN THE STUDY OF PL
1.# PROGRAMMER
Translates the algorithm using a particular -9
2| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
3/25
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
4/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
n extensible language enables the programmer to define new languagecomponents which then become indistinguishable from the language$s own built>inprimitives.
The degree %and kind( of interaction of the program with this environment 9I!-) !6*=*9b. !cience80ngineering> =!I&c. =usiness ;ata -rocessing> &*=*9d. !ystems -rogramming> &) dae. rtificial Intelligence> -*9*5f. !imulation> !I79g. 0ducation> =!I&) -ascal
4| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
5/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
B. SPECIAL PURPOSE
They cannot be used for any other problem area other than the one forwhich they were designed.!tatistical package. 0xample: -5
The processing environment assumed by the language:
E. BY PROCESSING ENVIRONMENT
. BATCH PROCESSING-The oldest sort of processing environment is one inwhich there is no interaction of any sort with the executingprogram.
=. INTERACTION WITH :
1. H*( U0') Interactive -rocessing(- Is characteried by interaction between the program and its human user8
programmer during program execution.
2. P70,8*+ O=>'8 %eal>Time -rocessing(- processing environment in which external processes) such as physical
ob?ects) interact with and impose strict time constraints on the responsesfrom executing programs.
0xamples: *;79>2) da0xample is robotics) automatic pilots and space vehicles
3. O7') S/5*)' %parallel -rocessing(
C/(8))'( P)/8'00,(- the concurrent execution of two or moresubprogram called processes.
0xamples: *;79>2) da) !99T9@
They operate simultaneously) relatively independently) and maycommunicate with each other and share common resources.
multiprogramming paradigm or organiing principlesupported by the language.
F. BY PROGRAMMING PARADIGM
A. PROCESS CENTERED- concerned with the details ofcomputing a solution and with the process ofproblem decomposition.
B. DATA CENTERED- !upport the development ofprograms by way of the formal specification of the datathat will be manipulated.
data> centered language is one in which programs are developed bymeans of formal specification of the data that is to be manipulated.
| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
6/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
1.?HISTORICAL DVELOPMENT OF PL
CHARLES BABBAGE-
"ather of modern computer- "irst computer architecture- ;evelop Difference Engine- ;evelopAnalytical Engine
D,')'(8' E(,('- a mechanical device that can perform
simple mathematical calculation> see figure b
A(*+,8*+ E(,('- this device provided a changeable
se/uence of numerical operations andinternal storage for data.
LADY AGUSTA ADA- &ountless of 9ovelace) daughter
of the poet 9ord =yron- The "irst &omputer -rogrammer- !he coded programs for nalytic 0ngine
using punched cards or also called asAac/uards.
- &readited with innovating the loop) orepition) construct.
EDVAC- Electronic Discrete Variable Arithmetic
B| - a g e
%OHN VON NEUMANN
> ;eveloped the 0;C&
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
7/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
Computer
- configuration in which the processortightly coupled to primary storage)primary storage is large enough to storevast amounts of data along with theprogram code) and operations are
executed se/uentially without theparallelism that was needed on theearlier machines to counteract theirextremely limited storage capabilities.
- this design has influenced many of thehigh level programming language.
UNIVAC - UNIVersal Automatic Computer
- The first computer to be available forcommercial sale.
- The first electronic computer producedspecially for commercial use and onetechnological feature is that its usesvacuum tubes
HOWARD AIEN- ;eveloped the @ I
MAR I- the pre>first generation machinery- it was also known as the utomatic !e/uence> &ontrolled &alculator
THE SOFTWARE LADDER
A. T7' 10G'(')*,/( 1@3&- 1;"2#
The era of machine language programming
ll coding was done in machine language that
is) the computer own internal %binary> based( instruction set
The word wasn$t programming then) but coding)and programmers were called coders.
G)*8' M))* H/
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
8/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
B. T7' 2(9G'(')*,/( 1;4;- 1;"$#
The pre> compiler era) saw the development and distribution of machine> code
subroutines) interpretive routines) automatic code generators) andassemblers.
Aohn auchly) proposed and implemented
+!hort> *rder &ode, or +!hort &ode, for the =I6& % =inary utomatic &omputer(
computer as a set of interpretivesubroutines stored in memory
B' H/+=')/() developed the
S/) M')' G'(')*/)which was thefirst attempt toward using a computer
to write programs.
T7' P)'
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
9/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
C. T7' 3)9G'(')*,/( 1;"4-
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
10/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
PL1- -rogramming 9anguage8*60- The language to end all languages,.- It was a state>of>the>art language that contained virtually every
conceivable element of language design.- It inherited the features of "*T6 %its expression and statement
syntax) share data) and the external procedure() &*=*9 % its data description)record and file handling) and report generation facilities() and 95*9 %its blockstructure) type declarations) and recursion(.
LOGO- ;eveloped by !eymour -apert of IT) along with a a group of
researchers and consultants as a &ambridge research firm.- It was designed specifically for mathematics education and was
actually used experimentally in elementary school classroom in 1FBD
FORTH- ;eveloped by &harles H. oore for scientific and engineering
applications yet allow for faster programming using fewer lines of code.
SIMULA
- ;esigned in FB2 by @risten 6ygaard and *le> Aohan ;ahl at the6orwegian &omputing &enter under contract with 76IC&
- It was motivated by a desire to create a programming language for simulationapplications> techni/ue of operations research that has since beensuccessfully used in a large number of diverse applications areas > whichwould also serve as a medium for describing the system under study.
ALGOL$?- revised and extended version of 95*9- Introduced the user> defined data type and the pointer type ) both
significant features of -ascal.
PASCAL- ;eveloped by 6iklaus irth) named after the "rench philisopher and
mathematician =laise -ascal- It was intended to illustrate the direction that 95*9 should have
taken .
C LANGUAGE- In 1FD2) =ell 9aboratories$ @enneth Thompson and ;ennis itchie
developed the & language for coding the routines of the 76IJ operatingsystem.
- & was an extension of the = language> also designed by Thompson>which itself drew heavily on a earlier systems programming language) =&-9.
MODULA 2- odular 9anguage- direct descendant of -ascal is another high level language with
facilities for systems programming.
- Is characteried by strong typing and syntactic style) and) of course)the module) a type of block that can be compiled independently and easilyassembled into program libraries.
ADA- 6amed after the 1stcomputer programmer 9ady ugusta da
9ovelace) designed according to specifications developed by the 7.!;epartment of ;efense.
1#| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
11/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
- It was intended for the programming of embedded computersystems
D. T7' 47G'(')*,/(- a 4thgeneration language is declarative) in other words) its
instructions to the computer concentrate more on what is to be done ratherthan on describing in detail how to do it.
- -rogramming are sorter) and easier to code) debug) and maintain
PROLOG- -rogramming in 9ogic- It was developed by lain &olmerauer and -hilipe oassel of the
7niversity of arseille$s artificial group) in collaboration with obert @owalskiof the 7niversity of 0dinburgh.
- It has a firm mathematical basis) grounded as it is in the principles ofpredicate calculus.
OPS- *fficial -roduction !ystem- ;eveloped at &arnegie ellon 7niversity in 1FD#- Is a production> system) or rule> based) language used in the field of
artificial intelligence.
SMALLTAL- designed and implemented in 1FD2 at Jerox -alo esearch &enter
%-&(.- The language that defines the ob?ect oriented approach to
programming.
1.;WHAT MAES A GOOD PL
1. W),*=,+,- easy for the programmer to design) code) test) run) document and
modify programs.- !yntax rules will be clear) simple and consistent
2. E))/) C7'8,(- -9 contains debugging facilities for finding errors that do occurs
3. R'*9*=,+,- assumes that the program with be read by other technical personnel)
non> technical ) programmers and users.- It is clear) understandable) and easily modifiable.
4. S'+- D/8'(*,/(- other forms of documentation usually attached to the source code
for the benefit of maintenance and programming
". E'(0,=,+,- if it enables the programmer to define new language components.
$. P/)*=,+,- ensure that the language works in the same way on these different
machines so that a program written in the language and tested on aparticular computer will still work with other computer.
&. E,8,'(8- 0fficient use of memory space %as little as possible( and computer
processing time %as fast as possible(.
11| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
12/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
1.1@ CHOOSING A PROGRAMMING LANGUAGE
FEATURES OF THE APPLICATION
1. P=+,8 60. P),6*' C/in data types and data
structures for the application area.
2. P)/)*,( E(6,)/('(- lso called a Software Development Environment) is a set of tools
that includes programming language and serves to aid in programdevelopment.
0xample: Translator 0ditor) 9inker) nd *nline Help
3. L'*)(,( C)6'- How easy will it be for a programmer to learn this -9.
CHAPTER 2
LANGUAGE PROCESSOR AND RELATED CONCEPTS
12| - a g e
Assembly LanguageStatement
Assembly LanguageStatement
ASSEBLE!
INTERPRETER
ac"ine languageInstruction
ac"ine languageInstruction
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
13/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
TRANSLATORSFIGURE 2.0
translator program accepts high>level language statements as produces thee/uivalent executable machine>language instruction.
2.1 TYPES OF LANGUAGE PROCESSOR
1.# ASSEMBLER- Is a translator program that translates assembly language to
machine language.
2.# INTERPRETER- type of language processor that operates one instruction at a time)
translating a high>level language statement and executingimmediately.
- 5enerally run more slowly than compiled programs.
3.# COMPILER- Is a translator program) which transforms a source program)
composed of high>level language statement into an ob?ect programconsisting of machine>language executable code.
OB%ECT PROGRAM machine>executable program produced as output from a compiler.
SOURCE PROGRAM program written in a high>level language and then input to the compile process.
Compilation Occurs in ! Broad P"ases
1.( ;ecomposes the source program into small identifiable units and analyes it forsyntactical accuracy.
2.( Takes the machine>code modules associated with the basic units identified in the
in the 1stphase and uses them to compose the ob?ect program.
2.2 THE COMPILE PROCESS
SOURCE PROGRAM ANALYSIS The first phase of the compile process encompasses the lexical
analysis and the syntactic analysis) producing the symbol table andintermediate %assembly>level( code.
LE!ICAL ANALYSIS
Is concerned with the actual text of the program) which is
considered to be a meaningful se/uence of characters.
13| - a g e
Assembly LanguageStatement C#PILE!
ac"ine languageInstruction
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
14/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
TOENS
!eparate pieces of programs
re the basic symbols used by the program: identifiers) operators)
punctuation) language keywords) constants.
SYMBOL TABLES
lso called the dictionary
ap program symbols such as variables with their properties such
types) sie) and relative location.
SYSNTACTIC ANALYSIS
Is concerned with identifying the logical structure of the program in
accordance with the rules of grammar governing the high levellanguage
PARSE TREE SYNTA! TREE
&ontains the hierarchy of operations in the high>level language
statements.
0very leaf node contains one of the symbols %tokens( in the
statement
ERROR HANDLER ;uring the lexical and syntactical analyses) information regarding
an error encountered is sent to the error handler module of thecompiler) which will arrange to print out a message to the user.
INTERMEDIATE CODE GENERATION
The result of the lexical and syntactic analyses and the information
in the symbol table are brought together to produce program code insome intermediate from similar to assembly> language code.
*utput from the syntactic analysis step) the intermediate code
serves as input to the code generation step.
*utput from the syntactic analysis step the intermediate code
serves as input to the code generation step.
OPTIMIZATION
To produce efficient code
To make more efficient use of main storage and processor time
To correct + bad programming practice,
"or detecting code that can be moved out of a loop % to improve the
efficiency of the program) and its logical structure(.
;etection and elimination of dead code
DEAD CODE is a program code that is accessible in the normal
processing of the program and will conse/uently never be executed.
CHAPTER THREE
MA%OR ASPECTS OF PROGRAMMING LANGUAGE
DATA
=its of information to be manipulated
3.2 DATA PRIMITIVE OPERATION
I. CONSTANT
14| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
15/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
Is a data item that remains unchanged throughout the
execution of the program
Calue is unchanged through the program
USES OF CONSTANTS
1. L,')*+
- is a data value that is used explicitly or literally in a programA. N'),8*+ L,')*+ /) N'),8 C/(0*(
- aybe made up of numeric digit # to F and special character K) >)and
B. S),( L,')*+- aybe composed of any valid characters in the language character
set and is often enclosed in single or double /uote.0xample : L -rogramming 9anguage$
C. L/,8*+ C/(0*(- True or "alse
2. N*'9 C/(0*(
- re sometimes termed symbolic constant or figurative constants.- 9ook likes variables because they are identified by a name.0xample : %&*=*9 language(
!-&0 M0* HI5H C970
II. VARIABLE
Is a receptacle for storing data value and each variable is associated
with a domain of allowable values.
0nable programmer to construct program for which the actual data
values are not needed until execution.
Calue is changed depending on certain conditions.
CONTROL VARIABLE- 0xist only in relation to the executing program or in the context of
algorithmic computation and have no relevance to the outside world.0xample :
Index Cariable % is used to control iteration(
ecord 6ames
"ile 6ames
COMPONENT OF A VARIABLE
1. 6ame2. Type8 !ie> ost important. It determines the domain of values that thevariable is allowed to take on and the set of operations that may beperformed on the variable.3. Calue4. !torage 9ocation
VALUES MAY BE PROVIDED FOR VARIABLE IN ONE OF THREE WAYS :
1| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
16/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
1. Initialiation when the variable is createdvalued entities operated upon by logical operators such as
and or) not.ay be taken such values true or false or #) 1.
4. A99)'00
*#. L*='+> more properly called a program elements that a data element is
actually the address of a program statement.
> *perated by the 5*T* operation
=#. P/,(')>eference or +point to, are another data element.
reference to unnamed data ob?ectII. COMPOUND DATA ELEMENTS
!ometimes considered primitive data elements and sometimes
classified as data structure.
1. S),(
n ordered se/uence of character of dynamically changing sie.
1B| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
17/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
DATA STRUCTURE
n organied collection of data ob?ects sub?ect to certain allowable
operations.
I. L,('*)
Is one in which the individual components are unordered se/uence.
*. S,
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
18/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
F,)' 3.@9**
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
19/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
2. SUCCESSOR
Its can be stated as: N is successor of -.
hat data element is next'
6ode %-( 6ode %N(
F,)' 3.1
3. EQUIVALENCE
It can be stated as: is e/uivalent to =.
Is implied in e/uality) in other words if and = are e/ual) they must be
e/uivalent.
OPERATION ON DATA STRUCTURES
1. CONSTRUCTOR
&reate or build> up data structure
2. DESTRUCTOR
;estroy) or break down data structure
3. ACCESS
-rovides access to the individual components and to groups of a
data structure by means of one of a variety of referencing methods.
ccess may be accomplished by:
. =y Nualified 6ame 0x. Index @ey=. =y location or subscript
0x. rray&. =y 6ame
%by assigning names to data structures(
4.# PREDICATES
These =oolean functions test a data structure for the presence of a
particular propertyFILE STRUCTURE
The organiation of data residing in secondary storage and sub?ect to
input8output related operations.
FILE
Is a collection of related records) related to a particular application.
RECORD
Is a collection of related data items) or fields) related to a single ob?ect ofprocessing.
FIELD Is a data item) a piece of information) either a data element or a structured data item)that is contained within the record.
CHARACTERISTICS OF FILE
1.# ACCESS MODE
1F| - a g e
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
20/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
The mode) or direction) of access from any particular file is determined by
whether the file is to be used for input) for output or both.
A. I(
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
21/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
ssigns the value of the current or re/uested component record to a
designated record variable or input buffer variable.
4. WRITE
&reate anew component record
". EOF
Tests for + end>of>file, and returns a =oolean value.
$. MAINTENANCE
"or maintenance files re/uiring regular maintenance %aster "ile(.
A. S/),(B. M'),(C. U scale direct> access storage deviceDBMS D**=*0' M*(*''( S0'#
!pecialied ! used to access a database
It is the software interface between the physical storage of the data and the use of
the data in various applications.
DATA ABSTRACTION
language facility that integrates the representation of a programmer> defined data
ob?ect and the operations that may be performed on that data ob?ect into a singlesyntactic unit.
3.3 S''(8' C/()/+
!tructures which affects the order of execution of statements within programs.
A. S)8)'0 U0'9 ,( E &ode !e/uence2. Tree> epresentation3. Infix) -refix) -ostfix 6otations
B. S)8)'0 U0'9 B'5''( S*''(0 /) G)/< / S*''(0
1. B)*(87,(*. C/(9,,/(*+
- I 7'( '+0'
- C*0'- O( G// O( G/S=
=. U(8/(9,,/(*+- G//- G/S=- E,- R')(
2. L//
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
22/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
a. 5eneralb. !pecific
C. S)8)'0 U0'9 B'5''( S=
-
8/13/2019 MELJUN CORTES MANUAL Structured Programming Language CSCI07
23/25
CSCI07 - Structures of Programming LanguagePrepared By: MELJUN P. CORTES
C+*00,,8*,/(0:. B,(*) O valued arithmeticexpression.
RELATIONAL OPERATORS
K K K #
may operate on virtually all types of data and form conditions.
CONDITION
is an assertion of a relation that computes to a =oolean value.
LOGICAL OPERATORS *(9 /) (/#
*perate on =oolean data and enhance conditions.
CONDITIONAL E!PRESSION
is a form of expression that originated with 9I!-) made its way into 95*9S() and is
currently used in &.
0xample : %& 9ang.(
1. =O %=( ' : #If the expression %=( is true) then=O < otherwise =O#
2. I" %=( =O else bK#
PRECEDENCE OF OPERATORS%"rom Highest -recedence to 9owest(
# J - K K K
4.2 REPRESENTATION OF E!PRESSIONS
1. P*)'(7'0,'9 F/) I(, F/)#
The one most familiar to us and most commonly relied on in programming.
The expression is represented as a linear se/uence of operators and
operands) which is ordered so as to exploit as much as possible the built> in
precedence rules of each language.
F++ P*)'(7'0,'9 F/)
;oes not rely on any precedence rules at all