/
C h a p t e r   1 Pr elimin a r ies Cha pt e r 1 Topic s Language Categories C h a p t e r   1 Pr elimin a r ies Cha pt e r 1 Topic s Language Categories

C h a p t e r 1 Pr elimin a r ies Cha pt e r 1 Topic s Language Categories - PowerPoint Presentation

calandra-battersby
calandra-battersby . @calandra-battersby
Follow
342 views
Uploaded On 2019-11-05

C h a p t e r 1 Pr elimin a r ies Cha pt e r 1 Topic s Language Categories - PPT Presentation

C h a p t e r 1 Pr elimin a r ies Cha pt e r 1 Topic s Language Categories L anguag e Eva l ua tio n C riteria I m ple m e n t a tio n Me th od s Copyrigh t 2012 Addison W esle y All ID: 763588

2012 language reserved addison language 2012 addison reserved rights wesley evaluation amp code criteria program readability data copyrigh languages

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "C h a p t e r 1 Pr elimin a r ies Cha ..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Chapter 1 Preliminaries

Chapter 1 TopicsLanguage CategoriesL anguage Evaluation Criteria I m plementation Methods Copyrigh t © 2012 Addison-Wesley. All rights reserved. 1- 2

Language CategoriesImperative Central featu res are v ariables, assignment statements, a nd iteration Inclu de la ngu a g e s th at su pport objec t- orie n ted pro g ra mm i ng I n cl u de s cripti ng la ngu a g e s I n cl u de th e v i su al la ngu a g e s Exa m ple s : C , Ja v a, P erl, Ja v a S cript, V i su al B AS I C . N ET, C++ F un ctio n al Mai n m ea ns o f m aki ng co m p u tatio ns i s by applyi ng fun ctio ns to g i v e n para m eter s Exa m ple s : LI SP , S c h e m e, ML, F# Lo g ic R u le - ba s ed (r u le s are s peci fi ed i n n o partic u lar order) Exa m ple: P rolo g Mark up/pro gra m m i n g h ybrid Mark u p la ngu a g e s exte n ded to su pport s o m e pro g ra mm i ng Exa m ple s : JS TL, XS LT

Language Evaluation CriteriaReadabilit y: the ease wi th wh ic h programs can be read and understood Writability : the ease wi th wh ic h a language can be used to create programsReliability: conformance to specifications (i.e., performs to its specifications)Cost: the ultimate total cost Copyrigh t © 2012 Addison-Wesley. All rights reserved. 1-5 Thursday , 6 Septembe r 2012

Language Evaluation Criteria• Readability– Ease at which a program can be read & understood– Factors that affect readability • Overall simplicity• Orthogonality• Control statements• Data types & structures• Syntax considerations

Evaluation Criteria: Readability Overall si mplicity A m anageable set of f eatu res and co ns tr u cts The overall simplicity of a programming language strongly affects its readability. A language with a large number of basic constructs is more difficult to learn than one with a smaller number. Programmers who must use a large language often learn a subset of the language and ignore its other features. This learning pattern is sometimes used to excuse the large number of language constructs.Minimal feature multiplicity: Feature multiplicity—that is, having more than one way to accomplish a particular operation. For example, in Java, a user can increment a simple integer variable in four different ways:count = count + 1 count += 1count++++count Mini m al operator o v erloading: in which a single operator symbol has more than one meaning

Ortho gonalityA relati v ely sm all set of primitive cons tru cts can be co m bi n ed i n a relatively small number of waysFor example, if the language has three primitive data types, an integer, double, and character, and two type operators, array and pointer, then a large number of data structures can be defined Lack of orthogonality leads to exceptions to rules. example, in C you can't return an array(static array), C is said to be unorthognal in this case– Too much orthogonality can also be bad, such as if youhad the ability to add a pointer to another pointer in C3. Control Statements the use of “goto ” statements was replaced by structured programming, which could be read from top to bottomMost programming languages now contain sufficient control statements• if (x < y) x++; if (x < y) goto L1;else y++; y++; goto L2; L1: x++; L2: Eva l ua tio n C rit e ri a : R ea d a bility

Evaluation Criteria: Readability Data types: Adequate data types and data structures also aids readabilityA language with Boolean type is easier to read than one without • inFlag = 0 is more difficult to read than inFlag = false

Evaluation Criteria: Readability Syntax considerationsIdentifier forms If too short , reduces readability ex: FORTAN 90 use 6 litters for identifierSpecial wordsC and its descendants use braces to specify compound statements. All of these languages suffer because statement groups are always terminated in thesame way, Fortran 95 and Ada make this clearerby using a distinct closing syntax for each type of statement group. Forexample, Ada uses end if to terminate a selection construct and end loopto terminate a loop construct.Form & meaning In C, static changes meaning depending on position

• WritabilityEase at which a language can be used to createprograms for a specific problem domain Factors that affect writability • Simplicity & orthogonality• Support for abstraction• Expressivity Language Evaluation Criteria : Writability

Evaluation Criteria: WritabilityS implicity and orthog onality Fe w constructs, a small number of primiti ves, a small set of ru le s f or co m bining themSupport for abstractionAbstraction: the ability to define and use complex structures or operations in ways that allow details to be ignored Programming languages can support two distinct categories of abstraction, process and data.Example of process abstraction is the use of a subprogram or function (Using the same function several times in the program)Example of data abstraction , consider a binary tree To implement a binary tree in Fortran 77 requires arrays, while C++ uses nodes with two pointers and an integer Expressivity A language has relatively convenient, rather than cumbersome, ways for specifying computations For example, in C x++ is shorter & moreconvenient than x=x+1

Language Evaluation Criteria• Reliability A reliable program performs to its specifications under all conditions Factors that affect reliability• Type checking• Exception handling• Aliasing• Readability & writability

Evaluation Criteria: Reliability Type checking – Testing for type errors in a given program • For example, can have errors if a function that is expecting an integer receives a float insteadException handlingIntercept run-time errors and take correcti ve m easures– Used in Ada C++ and Java, but not in C and Fortran • For example, the try & catch blocks of C++ catch runtime errors , fix the problem, and then continue the program without an “abnormal end”Copyright © 2012 Addison-Wesley. All rights reserved.1-8

Language EvaluationAliasing– Referencing the same memory cell with morethan one name• For example, in this C code both x & y can be used tothe same memory cell int x = 5;int *y = &x;Readability & writability – If a program is difficult to read or write, its easyto make mistakes and difficult to find them

Evaluation Criteria: CostTr aining progr ammer s to use the languageWriting programs (close ness to p articular a pplic a tio ns )Compiling programsExecuting programsLanguage implementation system: availability of free compilersReliability: poor reliability lead s to hi gh costsMa int a i n i ng programsCopyright © 2012 Addison-Wesley . All rights reserved.1-9

Evaluation Criteria: OthersP ortabilityThe e ase w i th which programs can be moved f rom on e implement a tio n to anotherGeneralityThe applicability to a wide range of applicationsWell-definitenessThe completeness and precision of the language’ s offici al definition Copyrigh t © 2012 Addison- Wesley. All rights reserved.1-10

Implementation MethodsCo mpilationP rog ra ms are translated into machine language; incl udes JIT systems Us e: Lar g e co mmercial applicationsPure InterpretationPrograms are interpreted by another program known as an interpreterUse: Small programs or when efficiency i s not an i ssueHybrid I mplem e n t a tion SystemsA comprom i se between compilers and pure interpretersUse: Small and m edi um s y s te ms wh e n e ffi cie n cy i s n ot th e fi r s t co n cer n Copyrigh t © 2012 Addison- W esle y . All rights reserved. 1-18

Layered View of Computer The operating sys tem a n d la nguage implementation are layered over machi ne interface o f a co m p uterCopyright © 2012 Addison-Wesley. All rights reserved.1-19

CompilationTransl ate high-level pro gram ( s ource language) into machine code (mach ine languag e)Slow tr ans l a tio n, fast executionCompilation process has several phases:lexical analysis: converts characters in the source program into lexical units syntax analy sis : tra nsf or ms lexical units into parse trees which repre s ent the syntactic structure of programSeman tic s a n aly s i s : g e n erate i n ter m ediate code code g e n eratio n : m ac h i n e code i s g e n erated Copyrigh t © 2012 Addison- W esle y . All rights reserved. 1-20

The Compilation Process Copyright © 2012 Addison-Wesley. All rights reserved . 1-21

Additional Compilation Terminologies Load module (execu ta ble i mag e): the user and system code togeth erLi nking and l oad i n g: the process of collecting system program units and linking them to a user programCopyright © 2012 Addison-Wesley. All rights reserved.1-22

Pure InterpretationNo tr anslationE asier i m ple mentation of programs (run-tim e errors can easily and immedi a tely be di s pl ayed)Slower execution (10 to 100 times slower than compiled programs)Often requires more spaceNow rare for traditional high-lev el languages Signifi cant co m eb a ck with some Web scripting languag e s (e.g., JavaScript, PHP)Copyright © 2012 Addison-Wesley. All rights reserved.1-24

Pure Interpretation Process Copyright © 2012 Addison-Wesley. All rights reserved. 1-25

Hybrid Implementation SystemsA co mpromise betwee n com piler s an d pure interpretersA high-level language progra m is tr anslated to an in ter m edi a te language that allows easy interpretationFaster than pure interpretationExamplesPerl programs are partially compiled to detect errors before interpretationInitial imple mentatio ns of Java w ere h ybrid; th e i n termediate form, byte code, provides portability to any m ac hine that has a byte code interpreter and a run-time system (toge th er, th e s e are called Ja v a V ir tu al Mac h i n e) Copyrigh t © 2012 Addison- W esle y . All righ t s reserved. 1-26

Hybrid Implementation Process Copyright © 2012 Addison-Wesley. All rights reserved . 1-27

Just-in-Time Implementation Systems Initially trans late pro g r ams to an intermediate languageTh en com pile the intermedi a te l anguag e o f the subprograms into machine code when they are calledMachine code version is kept for subsequent callsJIT syste ms are widely used f or Java pro g r ams . NET languages are impleme n ted with a JIT systemIn essence, JIT systems are dela yed co m piler s Copyrigh t © 2012 Addison- W esle y . All righ t s reserved . 1-28

PreprocessorsPreprocess or macros (instru ctions) a re co mmonly used to specify that code from ano ther file i s to be included A p re p rocesso r processes a program immediately before the program is compiled to expand embedded preprocessor macrosA well-known example: C preprocessor– expands #include, #define, and similar macros Copyrigh t © 2012 Addison- Wesley. All rights reserved.1-29

Copyright © 2012 Addison-Wesley. All righ ts reserved.1-31 Summary • • ••Th e study of programming l anguag e s i s valuable for a number of reasons:Increase our capacity to use different constructsEnable us to choose languages more intelligently Makes learnin g new langu ages ea s ier Mo st important criteria for evaluati ng programming languages include:Readability, writability, reliability, costMajor influ e n ces on la n gu a g e desi g n h a v e been ma c h i n e a rc h itec tu re an d so ftwa re de v elop m e n t m e thodolo g ie s T h e ma jor m e th od s o f i m ple m e n ti ng pro g r amm i ng l anguag e s a re: co m pil a tio n , p u re i n terpret a tio n, and hybrid implementation Thursday , 6 Septembe r 2012

Assignment #1 Evaluate the C & Java l a nguage s using the criteria just describe d. Wha t kind of problem-s olvi ng dom a i n would C be useful for?What about Java? C vs. JavaReadabilityWritabilityRealiabilityCostability