Docsity

Programming Languages: Summary, Study notes of Programming Languages

Partial preview of the text

Download Programming Languages: Summary and more Study notes Programming Languages in PDF only on Docsity!

Programming Languages, Summary

CSC419; Odelia Schwartz

Programming Domains

  • Scientific applications
    • Large numbers of floating point computations; use of arrays
    • Fortran (more recently though not stressed in book: Matlab, Python)
  • Business applications
    • Produce reports, use decimal numbers and characters
    • COBOL
  • Artificial intelligence
    • Symbols rather than numbers manipulated; use of linked lists
    • LISP

Language Categories

  • Imperative
    • Central features are variables, assignment statements, and

iteration

  • Include languages that support object-oriented programming
  • Include scripting languages
  • Include the visual languages
  • Examples: Ada, C, Java, Perl, JavaScript, Ruby, Visual

BASIC .NET, C++, Python, …

  • Functional
    • Main means of making computations is by applying functions to

given parameters

  • In pure languages, no side effects
  • Examples: LISP, Scheme, ML, Haskell

Language Evaluation Criteria

  • Readability: the ease with which programs can be read

and understood

  • Writability: the ease with which a language can be

used to create programs

  • Reliability: conformance to specifications (i.e., performs

to its specifications)

  • Cost: the ultimate total cost

Computer Architecture Influence

• Well-known computer architecture: Von Neumann

• Imperative languages, most dominant, because of von

Neumann computers

  • Data and programs stored in memory
  • Memory is separate from CPU
  • Instructions and data are piped from memory to CPU
  • Basis for imperative languages
    • Variables model memory cells
    • Assignment statements model piping
    • Iteration is efficient

• We discussed Von Neumann bottleneck

Describing Syntax and Semantics

• BNF and context-free grammars are equivalent meta-

languages

  • Well-suited for describing the syntax of programming languages

• An attribute grammar is a descriptive formalism that

can describe both the syntax and the semantics of a

language

• Three primary methods of semantics description

  • Operation, axiomatic, denotational

Example Grammar for small language

→ begin <stmt_list> end <stmt_list> → | ; <stmt_list> → = → a | b | c → + | - |

Example derivation

=> begin <stmt_list> end

=> begin ; <stmt_list> end

=> begin = ; <stmt_list> end

=> begin A = ; <stmt_list> end

=> begin A = + ; <stmt_list> end

=> begin A = B + ; <stmt_list> end

=> begin A = B + C ; <stmt_list> end

=> begin A = B + C ; end

=> begin A = B + C ; = end

=> begin A = B + C ; B = end

=> begin A = B + C ; B = end

=> begin A = B + C ; B = C end

Example derivation

=> begin <stmt_list> end

=> begin ; <stmt_list> end

=> begin = ; <stmt_list> end

=> begin A = ; <stmt_list> end

=> begin A = + ; <stmt_list> end

=> begin A = B + ; <stmt_list> end

=> begin A = B + C ; <stmt_list> end

=> begin A = B + C ; end

=> begin A = B + C ; = end

=> begin A = B + C ; B = end

=> begin A = B + C ; B = end

=> begin A = B + C ; B = C end

We derived leftmost; could have also done rightmost

Parse Tree

• A hierarchical representation of a derivation

<stmt_list> C a = + B

Ambiguity in Grammars

• A grammar is ambiguous if and only if it

generates a sentential form that has two or

more distinct parse trees

• Problematic for compilers since parse tree, and

therefore meaning of the structure, cannot be

determined uniquely

Static and Dynamic Binding

  • A binding is static if it first occurs before run time and remains unchanged throughout program execution.
  • A binding is dynamic if it first occurs during execution or can change during execution of the program

Categories of Variables by Lifetimes

  • Static--bound to memory cells before execution begins and remains bound to the same memory cell throughout execution, e.g., C and C++ static variables