Download
programming languages n.
Skip this Video
Loading SlideShow in 5 Seconds..
Programming Languages PowerPoint Presentation
Download Presentation
Programming Languages

Programming Languages

86 Views Download Presentation
Download Presentation

Programming Languages

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Programming Languages Shyh-Kang Jeng Department of Electrical Engineering/ Graduate Institute of Communication Engineering National Taiwan University

  2. Generations of programming languages

  3. Machine Instructions and Mnemonic Techniques 156C 166D 5056 306E C000 LD R5, PRICE LD R6, TAX ADDI R0, R5 R6 ST R0, TOTAL HLT

  4. Assemblers and Assembly Languages • Programs to translate other programs written in mnemonic form into machine compatible form • Assemble machine instructions out of the op-codes and operands obtained by translating mnemonics and identifiers • Mnemonic systems for representing programs are recognized as programming languages called assembly languages

  5. Assembly Languages • Second-generation language • Machine dependent • Must conform to the machine’s register configuration and instruction set • Low level primitives • A programmer is still forced to think in terms of the small, incremental steps of the machine’s language

  6. Design Process of a Product • Better suited to the use of high-level primitives, each representing a concept associated with a major feature of the product • Once the design is complete, the primitives can be translated to lower-level concepts relating to the details of implementation

  7. Third-Generation Languages • High-level primitives • Machine independent if standard is followed • FORTRAN • FORmula TRANslator • COBOL • COmmon Business-Oriented Language • BASIC

  8. Compilers vs. Interpreters • Compilers • Compile several machine instructions into short sequences to simulate the activity requested by a single high-level primitive • Produce a machine-language copy of a program that would be executed later • Interpreters • Execute the instructions as they were translated

  9. Machine Independence and Beyond • Restrictions of the machines • Size of registers and memory cells • Dialects and standard languages • ANSI (American National Standards Institute) standard • ISO (International Organization of Standardization) standard • Language extensions

  10. Evolution of Programming Paradigms

  11. Imperative Paradigm • Procedural paradigm • Develops a sequence of commands that when followed, manipulate data to produce the desired result • Approaches a problem by trying to find an algorithm for solving it

  12. Declarative Paradigm • Emphasizes • “What is the problem?” • Rather than “What algorithm is required to solve the problem?” • Implemented a general problem-solving algorithm • Develops a statement of the problem compatible with the algorithm and then applies the algorithm to solve it

  13. Functional Paradigm • Views the process of program development as connecting predefined “black boxes,” each of which accepts inputs and produces outputs • Mathematicians refer to such “boxes” as functions • Constructs functions as nested complexes of simpler functions

  14. Functional Paradigm Example

  15. Examples of LISP Expressions (Find_diff (Find_Sum Old_balance Credits) (Find_Sum Debits)) (First (Sort List))

  16. Advantages of Functional Paradigm • Constructing complex software from predefined primitive functions leads to well-organized systems • Provides an environment in which hierarchies of abstraction are easily implemented, enabling new software to be constructed from large predefined components rather than from scratch

  17. Object-Oriented Paradigm • OOP • Encapsulation of data and procedures • Lists and sorting • Graphic user interface (GUI) • Natural modular structure and program reuse • Communication between modules is accomplished by passing messages • CORBA and software components

  18. Statements in Programming Languages • Declarative statements • Define customized terminology that is used later in the program • Imperative statements • Describe steps in the underlying algorithms • Comments • Enhance the readability of a program

  19. Composition of a Typical Imperative Program or Program Unit

  20. Variables, Literals, Constants • EffectiveAlt  Altimeter + 645 • Variables • Example: EffectiveAlt, Altimeter • Literals • Example: 645 • Constants • Example: const int AirportAlt = 645;

  21. Data Type • Refers to • Interpretation of data • Operations that can be performed on the data • Common types • integer, real, character, Boolean

  22. Variable Declarations • Pascal Length, width: real; Price, Tax, Total: integer; • C, C++, Java, C# float Length, width; int Price, Tax, Total; • FORTRAN REAL Length, Width INTEGER Price, Tax, Total

  23. Data Structure • Conceptual shape of data • Common data structure • Homogeneous array • Heterogeneous array

  24. Declaration of a 2D Array • C int Scores[2][9]; • Java int Scores[][]=new int [2][9]; • Pascal Scores: array[3..4, 12..20] of integer;

  25. A two-dimensional array

  26. Declaration of a Heterogeneous Array • Pascal var Employee : record Name: packed array[1..8] of char; Age: integer; SkillRating: real; end • C struct Employee { char Name[8]; int Age; float SkillRating; };

  27. Assignment Statements and Operators • C, C++, Java Total = Price + Tax; • Ada, Pascal Total := Price + Tax; • APL Total <- Price + Tax; • Operator precedence • Operator overloading

  28. Control Statements • Alter the execution sequence of the program • goto is the simplest control statement • Example goto 40 20 Total = price + 10 goto 70 40 if Price < 50 goto 60 goto 20 60 Total = Price + 5 70 stop if( Price < 50 ) then Total = Price + 5 else Total = Price + 10 endif stop

  29. Control Structure (1)

  30. Control Structure (2)

  31. Control Structures (3)

  32. Comments • For inserting explanatory statements (internal documentation) • C++ and Java /* This is a comment */ // This is a comment • Explain the program, not to repeat it • Example: Total = Price + Tax;

  33. Procedures • A procedure is a set of instructions for performing a task that can be used as an abstract tool by other program units • Control is transferred to the procedure at the time its services are required and then returned to the original program unit (calling unit) after the procedure is finished • The process of transferring control to a procedure is often referred to as calling or invoking the procedure

  34. Procedures (1)

  35. Procedures (2) • Local variables • Global variables • Procedure’s header • Parameters • Formal parameters • Actual parameters

  36. A C Procedure

  37. 5 5 5 6 5 Pass by Value

  38. 5 6 6 Pass by Reference

  39. Functions • A program unit similar to procedure unit except that a value is transferred back to the calling unit • Example Cost = 2 * TotalCost( Price, TaxRate );

  40. A C Function

  41. Input/Output Statements • I/O statements are often not primitives of programming languages • Most programming languages implement I/O operations as procedures or functions • Examples printf( “%d %d\n”, value1, value2 ); cout << value << endl;

  42. A Formatted Output Example in C

  43. Translation Process

  44. Lexical Analyzer • Reads the source program symbol by symbol, identifying which groups of symbols represent single units, and classifying those units • As each unit is classified, the lexical analyzer generates a bit pattern known as a token to represent the unit and hands the token to the parser

  45. Parsing • Group lexical units (tokens) into statements • Identify the grammatical structure of the program • Recognize the role of each component • Fixed-format vs. free-format languages • Key words and reserved words

  46. Syntax Diagram • Pictorial representations of a program’s grammatical structure • Nonterminals • Requires further description • Terminals

  47. Syntax Diagram

  48. Parse Tree • Pictorial form which represents a particular string conforming to a set of syntax diagrams • The process of parsing a program is essentially that of constructing a parse tree for the source program • A parse tree represents the parser’s understanding of the programmer’s grammatical composition

  49. Parse Tree

  50. Dangling else Problem • if B1 then ( if B2 then S1 ) else S2 • if B1 then ( if B2 then S1 else S2 )