Unit1 principle of programming language

48,276 views

Published on

Published in: Education
3 Comments
68 Likes
Statistics
Notes
No Downloads
Views
Total views
48,276
On SlideShare
0
From Embeds
0
Number of Embeds
13
Actions
Shares
0
Downloads
2,304
Comments
3
Likes
68
Embeds 0
No embeds

No notes for slide

Unit1 principle of programming language

  1. 1. UNIT 1 By- Garima Jain
  2. 2.  Programming Language: Definition, History ,Feature Issues in Language Design Structure and Operation of Computer Programming Language Paradigms Efficiency, Regularity Issues in Language Translation Syntax and Semantics
  3. 3.  Definition : A notation of a algorithm and data structures are called a programming language.
  4. 4.  To improve your ability to develop effective algorithms To improve your use of existing programming languages To increase your vocabulary of useful programming constructs To allow a better choice of programming language To make it easier to learn a new language To make it easier to design a new language
  5. 5.  1951- 55: Experimental use of expression compilers. 1956- 60: FORTRAN, COBOL, LISP, Algol 60. 1961- 65: APL notation, Algol 60 (revised), SNOBOL, CPL. 1966- 70: APL, SNOBOL 4, FORTRAN 66, BASIC, SIMULA, Algol 68, Algol-W, BCPL. 1971- 75: Pascal, PL/1 (Standard), C, Scheme, Prolog. 1976- 80: Smalltalk, Ada, FORTRAN 77, ML.
  6. 6.  1981- 85: Smalltalk-80, Prolog, Ada 83. 1986- 90: C++, SML, Haskell. 1991- 95: Ada 95, TCL, Perl. 1996- 2000: Java. 2000- 05: C#, Python, Ruby, Scala.
  7. 7. Numerically based languages Computing mathematical expressions FORTRAN, Algol, Pascal, PL/1, BASIC, C, C++Business languages COBOL (Common Business Oriented Language) English-like notation
  8. 8. Artificial intelligence languages Tree search; Rule-based paradigm LISP (LISt Processing) PROLOG (PROgramming in LOGic)System languages C, C++ Script languages: AWK, Perl, TCL/TKWeb programming: HTML, XML, Java, Microsoft *.NET family
  9. 9. Batch processing (batches of files) Interactive processing (time sharing)Effects on language design File I/O in batch processing Error handling in batch processing Time constraints in interactive processing
  10. 10. Interactive processing Embedded system environmentsEffects on language design No need for time sharing Good interactive graphics Non-standard I/O devices for embedded systems
  11. 11. Client-server model of computing Server: a program that provides information Client - a program that requests informationEffects on language design Interaction between the client and server programs Active web pages, Security issues, Performance
  12. 12.  Conceptual integrity Orthogonality Naturalness for the application Support for abstraction Ease of program verification Programming environment Portability of programs Cost of use Cost of execution. Cost of program translation. Cost of program creation, testing, and use. Cost of program maintenance.
  13. 13.  Design to  Run efficiently : early languages  Easy to write correctly : new languages  Data typing features in ML  Class of C++  Package of Ada
  14. 14.  A computer is an integrated set of algorithms and data structures capable of storing and executing programs.  Hardware computer or  virtual computer
  15. 15. •Well-known computer architecture: Von Neumann• Imperative languages, most dominant, because ofvon Neumann computers– Data and programs stored in memory– Memory is separate from CPU– Instructions and data are piped from memory toCPU– Basis for imperative languages• Variables model memory cells• Assignment statements model piping• Iteration is efficient
  16. 16.  Hardware realization  Physical devices Firmware realization  microprogramming Software simulation  Some other programming language Combination of these techniques
  17. 17.  Data  Various kinds of elementary and structured data. Primitive operations Sequence control  Controlling the sequence of primitive operations execution.
  18. 18.  Data access  Controlling the data supplied to each execution of an operation. Storage management  Controlling the allocation of storage for programs and data. Operating environment  Providing mechanisms for communication with an external environment containing programs and data.
  19. 19.  Main memory High-speed register High-speed cache memory External filesData and Program
  20. 20.  A set of build-in primitive operations  Arithmetic operations on each built-in numeric data (+,-,*,/)  Testing various properties of data items (test for zero, positive, and negative numbers)  Accessing and modifying various parts of a data item  Controlling input-output devices  Sequence control (jumps)
  21. 21.  There is an interpreter :  Fetch the instruction  Decode instruction  Fetch designated operands  Branch to designated operation  Execute primitive operations 1 to n Using an address register
  22. 22.  Access to operands of the operation
  23. 23.  Keeping all resources of the computer operating as much as possible  Memory  Central processor  External data devices Multiprogramming Cache memory
  24. 24.  The outside world of computer; a set of peripherals and input-output devices
  25. 25.  Imperative / procedural languages Applicative / functional languages Rule-based / declarative languages Object-oriented languages
  26. 26. Statement oriented languages that change machinestate (C, Pascal, FORTRAN, COBOL)Computation: a sequence of machine states (contentsof memory)Syntax: S1, S2, S3, ... where S1, S2, … are statements
  27. 27. Programming consists of building the function thatcomputes the answerComputation: Function composition is majoroperation (ML, LISP)Syntax: P1(P2(P3(X)))
  28. 28. Computation: Actions are specified by rules thatcheck for the presence of certain enabling conditions.(Prolog)The order of execution is determined by the enablingconditions, not by the order of the statements.Syntax: Condition  Action
  29. 29. Imperative languages that merge applicative designwith imperative statements (Java, C++, Smalltalk)Syntax: Set of objects (classes) containing data(imperative concepts) and methods (applicativeconcepts)
  30. 30.  Programming language Syntax  Key criteria concerning syntax  Basic syntactic concepts  Overall Program-Subprogram structure Stages in Translation  Analysis of the source program  Synthesis of the object program  Bootstrapping
  31. 31. The syntax of a programming language describes thestructure of programs without any consideration oftheir meaning.
  32. 32. Readability – a program is considered readable if thealgorithm and data are apparent by inspection.Write-ability – ease of writing the program.Verifiability – ability to prove program correctness (very difficult issue)Translatability – ease of translating the program into executable form.Lack of ambiguity – the syntax should provide for ease of avoiding ambiguous structures
  33. 33.  Character set – The alphabet of the language. Several different character sets are used: ASCII, EBCIDIC, Unicode Identifiers – strings of letters of digits usually beginning with a letter Operator Symbols – +-*/ Keywords or Reserved Words – used as a fixed part of the syntax of a statement
  34. 34.  Noise words – optional words inserted into statements to improve readability Comments – used to improve readability and for documentation purposes. Comments are usually enclosed by special markers Blanks – rules vary from language to language. Usually only significant in literal strings
  35. 35.  Delimiters – used to denote the beginning and the end of syntactic constructs Expressions – functions that access data objects in a program and return a value Statements – these are the sentences of the language, they describe a task to be performed
  36. 36. Separate subprogram definitions: Separatecompilation, linked at load time E.g. C/C++Separate data definitions: General approach inOOP.Nested subprogram definitions: Subprogramdefinitions appear as declarations within the mainprogram or other subprograms. E.g. Pascal
  37. 37. Separate interface definitions:C/C++ header filesData descriptions separated from executablestatements. A centralized data division contains all datadeclarations. E.g. COBOLUn-separated subprogram definitions: No syntacticdistinction between main program statements andsubprogram statements.E.g. BASIC
  38. 38.  Analysis of the source program Synthesis of the object program Bootstrapping
  39. 39. Lexical analysis (scanning) – identifying the tokens of theprogramming language: keywords, identifiers, constantsand other symbolsIn the program void main() { printf("Hello Worldn"); }the tokens arevoid, main, (, ), {, printf, (, "Hello Worldn", ), ;, }
  40. 40. Syntactic analysis (parsing) – determining the structureof the program, as defined by the language grammar.Semantic analysis - assigning meaning to the syntacticstructuresExample: int variable1;meaning: 4 bytes for variable1 , a specific set ofoperations to be used with variable1.
  41. 41. The semantic analysis builds the bridge between analysis andsynthesis. Basic semantic tasks: • Symbol–table maintenance • Insertion of implicit information • Error detection • Macro processingResult : an internal representation, suitable to be used forcode optimization and code generation.
  42. 42. Three main steps:Optimization - Removing redundant statementsCode generation - generating assembler commands withrelative memory addresses for the separate programmodules - obtaining the object code of the program.Linking and loading - resolving the addresses -obtaining the executable code of the program.
  43. 43. Assembler code not optimized:Intermediate code: LOAD_R BTemp1 = B + C ADD_R CTemp2 = Temp1 + D STORE_R Temp1A = Temp2 LOAD_R Temp1 ADD_R D STORE_R Temp2 LOAD_R Temp2 STORE_R AStatements in yellowcan be removed
  44. 44. The compiler for a given language can be written inthe same language.• A program that translates some internal representationinto assembler code.• The programmer manually re-writes the compiler intothe internal representation, using the algorithm that isencoded into the compiler.From there on the internal representation is translated intoassembler and then into machine language.
  45. 45.  Syntax: what the program looks like. Semantics: the meaning given to the various syntactic constructs. Example: V: array [0..9] of integer; int V[10];

×