Programming Languages Exam 1, Exams of Programming Languages

Programming Languages Exam 1..

Typology: Exams

2023/2024

Available from 03/13/2024

EmmaMoss
EmmaMoss 🇬🇧

99 documents

1 / 6

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Programming Languages Exam 1
imperative languages
- central features are variables, assignment statements, and iteration
- include languages that support object-oriented programming
- include scripting languages
- C, C++, C#, Go, Java, JavaScript, Python, etc
functional languages
- main means of making computations is by applying functions to given parameters
- in its purest form defined as mathematical function, there is no concept of memory
(variables), time, or state
- a purely functional language has no loops and requires recursion to iterate
- every parameter of a function is bound to a value and remains constant through
evaluation
- no such thing as a variable that models a memory location
- LISP, Haskell, OCaml, Erlang, Racket, Scheme, Clojure
logic languages
- program statements describe facts and rules
- the computer's job is to construct a proof based on the given axioms (facts + rules)
- no imperatives at all
- don't specify the steps to solve a problem
- Prolog
compilation
languages where programs are translated into machine language
-> slow translation
-> fast execution
-> translation occurs only once, but the program can be run multiple times
pure interpretation
languages where programs are interpreted/executed in a stepwise fashion by another
program known as an interpreter
-> no translation into machine language
-> code is executed on the fly
-> rare for traditional high-level languages
-> execution is immediate
-> easier implementation of debugging programs but errors are not found until actually
executed
-> slower execution
-> often requires more space
lexical analysis
step one of compilation: converts characters in the source program into lexical units
syntax analysis
pf3
pf4
pf5

Partial preview of the text

Download Programming Languages Exam 1 and more Exams Programming Languages in PDF only on Docsity!

imperative languages

  • central features are variables, assignment statements, and iteration
  • include languages that support object-oriented programming
  • include scripting languages
  • C, C++, C#, Go, Java, JavaScript, Python, etc functional languages
  • main means of making computations is by applying functions to given parameters
  • in its purest form defined as mathematical function, there is no concept of memory (variables), time, or state
  • a purely functional language has no loops and requires recursion to iterate
  • every parameter of a function is bound to a value and remains constant through evaluation
  • no such thing as a variable that models a memory location
  • LISP, Haskell, OCaml, Erlang, Racket, Scheme, Clojure logic languages
  • program statements describe facts and rules
  • the computer's job is to construct a proof based on the given axioms (facts + rules)
  • no imperatives at all
  • don't specify the steps to solve a problem
  • Prolog compilation languages where programs are translated into machine language -> slow translation -> fast execution -> translation occurs only once, but the program can be run multiple times pure interpretation languages where programs are interpreted/executed in a stepwise fashion by another program known as an interpreter -> no translation into machine language -> code is executed on the fly -> rare for traditional high-level languages -> execution is immediate -> easier implementation of debugging programs but errors are not found until actually executed -> slower execution -> often requires more space lexical analysis step one of compilation: converts characters in the source program into lexical units syntax analysis

step two of compilation: transforms lexical units into parse tree and checks for syntactic correctness by trying to create a parse tree semantics analysis step three of compilation: type checking and intermediate code generation code generation step four of compilation: machine code is generated readability, writability, reliability, cost the most important criteria for evaluating programming languages machine architecture and software development methodologies major influences on language design ALGOL 60

  • all subsequent imperative languages are based on it
  • first machine-independent language
  • first language whose syntax was formally defined (using BNF)
  • it was the standard way to publish algorithms for over 20 years
  • never widely used, especially in the US
  • lack of I/O definition made programs non-portable
  • too flexible and hard to implement
  • entrenchment of Fortran/lack of support from IBM
  • formal syntax description (BNF) seemed too complex PL/
  • designed to be used by both scientists a businesses
  • instructional vehicle in college in subset form
  • many new features were poorly designed
  • too large and complex BNF
  • a natural notation for describing syntax
  • equivalent to context-free gamers
  • consists of: -> start symbol -> finite set of production rules -> finite set of terminal symbols -> finite set of nonterminal symbols terminals lexemes or tokens -> if, while, else, then nonterminals

an association, such as between an attribute and an entity, or between an operation and a symbol static binding bindings that first occur before run time and remains unchanged throughout Programming execution -> during compile time -> explicit declaration -> type information supplied in source code -> standard "run of the mill" declaration such as int x = 0 dynamic binding bindings that first occur during execution or can change during execution of the program -> occurs during run time -> the variable is bound to a type when it is assigned a value in an assignment statement -> good for flexibility but has a high cost of time lifetime the time during which the variable is bound to a particular memory cell static variables

  • bound to memory cells before execution begins and remains bound to the same memory cell throughout execution
  • pros: efficiency (direct addressing), globally accessible, history-sensitive subprogram support
  • cons: lack of flexibility (no recursion), no shared storage stack-dynamic variables
  • storage bindings are created for variables when their declaration statements are elaborated (when the executable code associated with it is executed)
  • allows recursion
  • conserves storage
  • overhead of allocation and deallocation
  • subprograms not history-sensitive
  • inefficient references (indirect addressing) explicit heap-dynamic variables
  • allocated and deallocated by explicit directives, specified by the programmer, which take effect during execution
  • most often used for linked lists and pointers
  • provides for dynamic storage management
  • inefficient (indirect addressing)
  • unreliable & error prone
  • complex storage management implementation

implicit heap-dynamic variables

  • allocation and deallocation caused by assignment statements
  • flexibility (generic code)
  • inefficient (all attributes are dynamic) scope the range job the statements in which a variable is visible (can be referenced) static scope
  • to connect a name reference to a variable, yo must find the declaration
  • works well in most situations
  • programs are easy to reason about
  • in many cases too much access is possible and we want variables to be accessed only where needed
  • as a program evolves, the initial structure is destroyed and local variables often become global dynamic scope
  • references to nonlocal variables are connected to declarations by searching back through the chain of subprogram calls that forced execution to this point
  • has disappeared from recent programming languages
  • the exception is exception handling which essentially uses dynamic scope to associate a handler with an exception
  • convenient: the called subprogram is executed in the context of the caller
  • poor readability: programs are difficult to reason about
  • no static type checking
  • all variables from caller are visible to called subprogram referencing environment the collection of all names that are visible at the statement lambdas
  • describe nameless functions
  • expressions are applied to parameters by placing the parameters after the expression
  • handy for creating functions to pass as parameters to other functions that expect to receive functions
  • used when you want to write a function and forget about it atom the smallest unit that has meaning in a language cons makes a new list by inserting its first argument (after evaluation) onto the front o the new list which is its second argument -> creates a new node at the front of the linked list -> a copy of the second argument is not made