programming concept-sebesta
TRANSCRIPT
-
8/18/2019 programming concept-sebesta
1/31
ISBN 0-321-49362-1
Chapter 1
Preliminaries
-
8/18/2019 programming concept-sebesta
2/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-2
Chapter 1 Topics
• Reasons for Studying Concepts ofProgramming Languages
• Programming Domains
• Language Evaluation Criteria
• Inuences on Language Design
• Language Categories
• Language Design Trade!"#s• Implementation $ethods
• Programming Environments
-
8/18/2019 programming concept-sebesta
3/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-3
Reasons for Studying Conceptsof Programming Languages
• Increased a%ility to e&press ideas
• Improved %ac'ground for choosingappropriate languages
• Increased a%ility to learn ne( languages
• )etter understanding of signi*cance ofimplementation
• )etter use of languages that are already'no(n
• "verall advancement of computing
-
8/18/2019 programming concept-sebesta
4/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-4
Programming Domains
• Scienti*c applications+ Large num%ers of oating point computations, use of arrays+ -ortran
• )usiness applications+ Produce reports. use decimal num%ers and characters+ C")"L
• /rti*cial intelligence+ Sym%ols rather than num%ers manipulated, use of lin'ed
lists+ LISP
• Systems programming+ 0eed eciency %ecause of continuous use+ C
• 2e% Soft(are+ Eclectic collection of languages3 mar'up 4e5g5. 67T$L8.
scripting 4e5g5. P7P8. general!purpose 4e5g5. 9ava8
-
8/18/2019 programming concept-sebesta
5/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-5
Language Evaluation Criteria
• Readability3 the ease (ith (hichprograms can %e read and understood
• Writability3 the ease (ith (hich a
language can %e used to createprograms
• Reliability3 conformance tospeci*cations 4i5e5. performs to its
speci*cations8• Cost3 the ultimate total cost
-
8/18/2019 programming concept-sebesta
6/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-6
Evaluation Criteria3 Reada%ility
•"verall simplicity+ / managea%le set of features and constructs+ $inimal feature multiplicity+ $inimal operator overloading
• "rthogonality+ / relatively small set of primitive constructs can %e com%ined in a
relatively small num%er of (ays
+ Every possi%le com%ination is legal• Data types
+ /de:uate prede*ned data types
• Synta& considerations+ Identi*er forms3 e&i%le composition+ Special (ords and methods of forming compound statements
+ -orm and meaning3 self!descriptive constructs. meaningful 'ey(ords
-
8/18/2019 programming concept-sebesta
7/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-7
Evaluation Criteria3 2rita%ility
• Simplicity and orthogonality+ -e( constructs. a small num%er of primitives. a small set of
rules for com%ining them
• Support for a%straction
+ The a%ility to de*ne and use comple& structures oroperations in (ays that allo( details to %e ignored
• E&pressivity
+ / set of relatively convenient (ays of specifying operations
+ Strength and num%er of operators and prede*nedfunctions
-
8/18/2019 programming concept-sebesta
8/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-8
Evaluation Criteria3 Relia%ility
• Type chec'ing+ Testing for type errors
• E&ception handling+ Intercept run!time errors and ta'e corrective measures
• /liasing+ Presence of t(o or more distinct referencing methods for the
same memory location
• Reada%ility and (rita%ility+ / language that does not support ;natural< (ays of e&pressing
an algorithm (ill re:uire the use of ;unnatural< approaches.and hence reduced relia%ility
-
8/18/2019 programming concept-sebesta
9/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-9
Evaluation Criteria3 Cost
• Training programmers to use thelanguage
• 2riting programs 4closeness to particularapplications8
• Compiling programs• E&ecuting programs
• Language implementation system3
availa%ility of free compilers• Relia%ility3 poor relia%ility leads to highcosts
• $aintaining programs
-
8/18/2019 programming concept-sebesta
10/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-10
Evaluation Criteria3 "thers
• Porta%ility
+ The ease (ith (hich programs can %e movedfrom one implementation to another
• =enerality+ The applica%ility to a (ide range of
applications
• 2ell!de*nedness
+ The completeness and precision of thelanguage>s ocial de*nition
-
8/18/2019 programming concept-sebesta
11/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-11
Inuences on Language Design
• Computer /rchitecture+ Languages are developed around the
prevalent computer architecture. 'no(n as thevon Neumann architecture
• Programming $ethodologies+ 0e( soft(are development methodologies
4e5g5. o%?ect!oriented soft(are development8led to ne( programming paradigms and %y
e&tension. ne( programming languages
-
8/18/2019 programming concept-sebesta
12/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-12
Computer /rchitecture Inuence
• 2ell!'no(n computer architecture3 @on 0eumann
• Imperative languages. most dominant. %ecauseof von 0eumann computers+ Data and programs stored in memory
+ $emory is separate from CPA
+ Instructions and data are piped from memory to CPA
+ )asis for imperative languages
• @aria%les model memory cells
• /ssignment statements model piping• Iteration is ecient
-
8/18/2019 programming concept-sebesta
13/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-13
The von 0eumann /rchitecture
-
8/18/2019 programming concept-sebesta
14/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-14
The von 0eumann /rchitecture
• -etch!e&ecute!cycle 4on a von 0eumannarchitecture computer8
initialize the program counterrepeat forever
fetch the instruction pointed by the counter
increment the counter
decode the instruction
execute the instruction
end repeat
-
8/18/2019 programming concept-sebesta
15/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-15
Programming $ethodologiesInuences
• 1Bs and early 1Bs3 Simple applications,(orry a%out machine eciency
• Late 1Bs3 People eciency %ecame important,reada%ility. %etter control structures
+ structured programming+ top!do(n design and step!(ise re*nement
• Late 1BFs3 Process!oriented to data!oriented+ data a%straction
• $iddle 1BGs3 "%?ect!oriented programming+ Data a%straction H inheritance H polymorphism
-
8/18/2019 programming concept-sebesta
16/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-16
Language Categories
• Imperative+ Central features are varia%les. assignment statements. and
iteration+ Include languages that support o%?ect!oriented programming+ Include scripting languages+ Include the visual languages
+ E&les3 C. 9ava. Perl. 9avaScript. @isual )/SIC 50ET. CHH• -unctional+ $ain means of ma'ing computations is %y applying functions to
given parameters+ E&les3 LISP. Scheme
• Logic
+ Rule!%ased 4rules are speci*ed in no particular order8+ E&le3 Prolog
• $ar'upprogramming hy%rid+ $ar'up languages e&tended to support some programming+ E&les3 9STL. 6SLT
-
8/18/2019 programming concept-sebesta
17/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-17
Language Design Trade!"#s
• Relia%ility vs5 cost of e&ecution+ E&le3 9ava demands all references to array elements
%e chec'ed for proper inde&ing. (hich leads toincreased e&ecution costs
• Reada%ility vs5 (rita%ilityE&le3 /PL provides many po(erful operators 4and a
large num%er of ne( sym%ols8. allo(ing comple&computations to %e (ritten in a compact program %ut atthe cost of poor reada%ility
• 2rita%ility 4e&i%ility8 vs5 relia%ility+ E&le3 CHH pointers are po(erful and very e&i%le
%ut are unrelia%le
-
8/18/2019 programming concept-sebesta
18/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-18
Implementation $ethods
• Compilation+ Programs are translated into machine language
• Pure Interpretation
+ Programs are interpreted %y another program 'no(n asan interpreter
• 7y%rid Implementation Systems
+ / compromise %et(een compilers and pure interpreters
-
8/18/2019 programming concept-sebesta
19/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-19
Layered @ie( of Computer
The operating systemand languageimplementation arelayered overmachine interface of acomputer
-
8/18/2019 programming concept-sebesta
20/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-20
Compilation
• Translate high!level program 4source language8into machine code 4machine language8
• Slo( translation. fast e&ecution
• Compilation process has several phases3
+ le&ical analysis3 converts characters in the sourceprogram into le&ical units
+ synta& analysis3 transforms le&ical units into parse trees(hich represent the syntactic structure of program
+ Semantics analysis3 generate intermediate code
+ code generation3 machine code is generated
-
8/18/2019 programming concept-sebesta
21/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-21
The Compilation Process
-
8/18/2019 programming concept-sebesta
22/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-22
/dditional Compilation Terminologies
• Load module 4e&ecuta%le image83 theuser and system code together
• Linking and loading3 the process of
collecting system program units andlin'ing them to a user program
-
8/18/2019 programming concept-sebesta
23/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-23
@on 0eumann )ottlenec'
• Connection speed %et(een a computer>smemory and its processor determines thespeed of a computer
• Program instructions often can %ee&ecuted much faster than the speed ofthe connection, the connection speed thusresults in a bottleneck
• Jno(n as the von Neumann bottleneck , itis the primary limiting factor in the speedof computers
-
8/18/2019 programming concept-sebesta
24/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-24
Pure Interpretation
• 0o translation• Easier implementation of programs 4run!time
errors can easily and immediately %e displayed8
• Slo(er e&ecution 41 to 1 times slo(er than
compiled programs8• "ften re:uires more space
• 0o( rare for traditional high!level languages
• Signi*cant come%ac' (ith some 2e% scriptinglanguages 4e5g5. 9avaScript. P7P8
-
8/18/2019 programming concept-sebesta
25/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-25
Pure Interpretation Process
-
8/18/2019 programming concept-sebesta
26/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-26
7y%rid Implementation Systems
• / compromise %et(een compilers and pureinterpreters
• / high!level language program is translatedto an intermediate language that allo(s easy
interpretation• -aster than pure interpretation
• E&les+ Perl programs are partially compiled to detect errors %efore
interpretation
+ Initial implementations of 9ava (ere hy%rid, the intermediateform. byte code. provides porta%ility to any machine thathas a %yte code interpreter and a run!time system4together. these are called Java Virtual Machine8
-
8/18/2019 programming concept-sebesta
27/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-27
7y%rid Implementation Process
-
8/18/2019 programming concept-sebesta
28/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-28
9ust!in!Time Implementation Systems
• Initially translate programs to an intermediatelanguage
• Then compile the intermediate language of thesu%programs into machine code (hen they arecalled
• $achine code version is 'ept for su%se:uent calls
• 9IT systems are (idely used for 9ava programs
• 50ET languages are implemented (ith a 9ITsystem
-
8/18/2019 programming concept-sebesta
29/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-29
Preprocessors
• Preprocessor macros 4instructions8 arecommonly used to specify that code fromanother *le is to %e included
• / preprocessor processes a programimmediately %efore the program iscompiled to e&pand em%eddedpreprocessor macros
• / (ell!'no(n e&le3 C preprocessor+ e&pands #include, #define. and similar
macros
-
8/18/2019 programming concept-sebesta
30/31
Copyright © 2009 Addison-Wesley. All rights reserved. 1-30
Programming Environments
• / collection of tools used in soft(aredevelopment
• A0I6+ /n older operating system and tool collection
+ 0o(adays often used through a =AI 4e5g5. CDE. JDE. or=0"$E8 that runs on top of A0I6
• $icrosoft @isual Studio50ET+ / large. comple& visual environment
• Ased to %uild 2e% applications and non!2e% applications in
any 50ET language
• 0et)eans+ Related to @isual Studio 50ET. e&cept for 2e%
applications in 9ava
-
8/18/2019 programming concept-sebesta
31/31
Copyright © 2009 Addison Wesley All rights reserved 1 31
Summary
• The study of programming languages is valua%lefor a num%er of reasons3+ Increase our capacity to use di#erent constructs+ Ena%le us to choose languages more intelligently+ $a'es learning ne( languages easier
• $ost important criteria for evaluatingprogramming languages include3+ Reada%ility. (rita%ility. relia%ility. cost
• $a?or inuences on language design have %eenmachine architecture and soft(are developmentmethodologies
• The ma?or methods of implementing programminglanguages are3 compilation. pure interpretation.and hy%rid implementation