Skip to content

Instantly share code, notes, and snippets.

@OmarMalik
Forked from elmerland/comp_lang_pop_quizzes.md
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OmarMalik/d691e28d83797424f071 to your computer and use it in GitHub Desktop.
Save OmarMalik/d691e28d83797424f071 to your computer and use it in GitHub Desktop.

Pop Quiz 1

Question: Give an example of a trade off between reliability and cost of execution.
Answer:

  • Exception handling - You sacrifice cost of execution by enabling exception handling but increase program reliability, particularly important in the case of embedded systems.
  • Recursive methods - Recursive methods may often be more reliable than iterative methods, but you will sometimes sacrifice performance using a recursive method as there can be much more overhead involved in pushing multiple method calls to the runtime stack.
  • Dynamic typing - Utilizing dynamic type checking will favor the cost of execution but sacrifice reliability if the program runs into a type check error during runtime.
  • Array bounds - Bound checking on arrays. If the bounds are checked invalid memory accesses can be caught but slow down execution time (it has to check the bounds for every access to the array).

Pop Quiz 2

Question: What is orthogonality in regard to programing languages?
Answer: Orthogonality is when two distinct features in a language can be used together in a way that enhances what each individual feature can do.
Example: Using an array of structs in C. Structures are flexible in what they can contain, and arrays provide an easy way of traversing constructs. When used together, an array of structures allows easy traversal of structures which may contain any type of information.

Pop Quiz 3

Question: What does the compiler do on its first pass?
Answer: It tokenizes the sources code.
Example: The first stage of a compiler is called the scanner. It takes a character stream (source code) and performs a lexical analysis on it. When its done, it outputs a Token stream.

Pop Quiz 4

Question: What do we use to implement a DFA (Deterministic Finite state Automata)
Example: A transition table
Example: A transition table has all the states on one axis (vertical), and all the possible inputs on the other axis (horizontal). Then each entry on each row holds the value for the next state taking into consideration the state it started with and the input it obtained.

Pop Quiz 5

Question: For the sentences within the Language Grammar, what are they from the prospective of the software?
Answer: That is the program. In other words, a sentence is the entire program.

Pop Quiz 6

Question: Using the Context Free Grammar given on slide 8, construct a valid grammar.
Answer: One example
a = b + c

Pop Quiz 7

Question: What are the four components of a grammar?
Answer: Terminals (T), Non-terminals (N), a start symbol (S), and productions or rules (P)

Pop Quiz 8

Question: What is the distinctive charactersitic of associativity in a grammar
Answer: A recursive definition.
Example: <expr> -> <expr> + const | const

Pop Quiz 9

Question: What characteristic of a grammar can keep it from being top down parsable?
Answer:

  • Left recursive (indirect and direct)
  • Common prefixes or pairwise disjoint (A->bcD, A->bxM)

Pop Quiz 10

Question: Why doe having static binding and dynamic type checking does not make sense?
Answer: Because that would be that all the binding is done at compile time but no error checking is done until run time, even though you have all the necessary information at compile time

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment