click below
click below
Normal Size Small Size show me how
COP 4020: Midterm
| Question | Answer |
|---|---|
| Syntax concerns the ____________________. | form of a valid program |
| Semantic concerns the ___________________. | meaning of a program |
| Static semantic rules are enforced _________________________________. | by the compiler at compile time |
| Examples of Static semantic rules include: | Type Checking, Identifiers are used in appropriate context, Check subroutine call arguments, Check labels |
| Dynamic semantic rules are enforced _____________________________________________. | By the compiler, by generating code to perform the checks at run-time. |
| Examples of Dynamic Semantic rules include: | Array subscript values are in within bounds, Arithmetic errors, Pointers are not dereferenced unless pointing at valid object, a variable is used by not initialized |
| True or False: Some languages allow programmers to add explicit dynamic semantic checks in the form of assertions. | True |
| True or False: When a (dynamic semantic) check fails at run-time, an exception is raised. | True |
| An attribute grammar connects ____________ with _____________. | syntax; semantics |
| Semantic rules are used by the compiler to ____________________________________________. | enforce static semantics and/or to produce an abstract syntax tree while parsing tokens. |
| True or False: Attribute Grammar cannot be used to build a simple language interpreter | False, it is possible to build an a simple language interpreter. |
| Synthesized attributes flow in which direction? Describe the process. | Upwards; Synthesized attributes hold values that are computed from the attribute values of the child nodes. Therefore, the information flows upward. |
| Inherited attributes flow in which direction? Explain. | Downwards, child nodes inherit from the parent nodes, therefore information moves down the tree. |
| Explain an Attribute flow algorithm. | It propagates attribute values through the parse tree by traversing the tree according to the set(write) and use(read) dependencies. |
| Describe a S-Attributed grammar. | All attributes are synthesized. |
| Describe a L-Attributed grammar. | the parse tree traversal to update attribute values is always left-to-right and depth-first |
| Describe the specific properties of an L-Attributed Grammar. | Synthesized attributes always OK. Values of inherited attributes must be passed down to children from left to right. Semantic rules can be applied immediately during parsing. It is an essential grammar property for a one-pass compiler |
| True or False: A S-Attributed grammar is a special case of an L-attributed grammar. | True |
| What is Functional Programming | A declarative programming style (programming paradigm). |
| List the Pros of Functional Programming: | 1 .Flow of computation is declarative. 2. Promotes building more complex functions that serve as building blocks. 3. Behavior of functions defined by the values of input arguments only (no side-effects via global/static variables). |
| List the cons of Functional Programming: | 1. function composition is (considered to be) stateless 2. Programmers prefer imperative programming constructs such as statement composition, while functional languages emphasize function composition. |
| Functional programming defines the outputs of a program as ______________________________. | purely as a mathematical function of the inputs with no notion of internal state (no side effects). |
| A pure function ________________________________. | can be counted on to return the same output each time we invoke it with the same input parameter values |
| True or False: Functional programs contain global variables. | False |
| True or False, and explain the implication: Functional programs do not contain explicit pointer assignments. | True. No Dangling pointers and and uninitialized variables can occur |
| Non-pure functional programming languages __________________________________. | Include "imperative features" that cause side effects such as destructive assignments, global variables, or assignment/changes to lists and data structs. EG: Lisp, Scheme, and ML |
| Describe Functional Language Constructs: | 1. Building blocks are functions 2. No statem composition 3. No variable assignment (local variables assigned once) 4. No loops 5. Conditional flow with if-then-else or argument patterns 6. Functional can be typed or untyped. |
| Explain Church's thesis for functional programming. | All models of computation are equally powerful. Functional programming implements Lambda Calculus |
| Explain Functional Program Computational Theory: | A program can be viewed as a constructive proof that some mathematical object with a desired property exists; A function is a mapping from inputs to outputs and computes outputs from appropriate inputs. |
| List the 5 impacts of Functional Programming on modern programming languages: | Fist Class Function values, High-order functions Polymorphism, Aggregate constructs, and Garbage Collection. |
| Explain Fist Class Function values: | the ability of functions to return newly constructed functions, |
| Explain High-order functions: | functions that take other functions as input parameters or return functions, |
| Explain Polymorphism: | The ability to write functions that operate on more than one type of data |
| Explain Aggregate Constructs: | for constructing structured objects: the ability to specify a structured object in-line such as a complete list or record value |
| List improvements of functional programs in recent years: | Strongly typed, Modular, Sugaring, Improved efficiency |
| Explain Sugaring: | Imperative language features that are automatically translated into functional constructs. eg: loops by recursion. |
| Explain the Remaining obstacles to functional programming: | Social: most programmers are trained in imperative programming and aren't used to think in terms of function composition. Commercial: Not many libraries, not very portable, and no IDEs. |
| List some applications created with functional programming: | Computer Algebra, Natural language processing, Artificial Intelligence, Automatic theorem proving, Algorithmic optimization of functional programs. |
| True or False: Lisp is the original language and implementation of Lambda Calculus | True |
| True or False: Scheme is the original language and implementation of Lambda Calculus | False |
| Describe the design of Lisp and its dialects that make it the most widely used functional languages: | Homogeneity of programs and data - A lisp program is a list and can be manipulated in Lisp as a list, Self-definition A List interpreter can be written in Lisp, Interactive - user interaction via "read-eval-print" loop. |
| What is Cambridge Polish? | A Lisp and Scheme prefix notation. |
| List the major characteristics of Scheme. | Case Sensitive, Expressions are composed of atoms(literal number, string, or identifier name), Lists, or Function invocation written in list notation. |
| What is "Read-eval-print" loop significance in Scheme? | Provides user interaction, accepts an input and provides a responding output: eg - Input: 9 Output 9; Input: (+ 3 4) Output: 7 |
| How can a user load a program from file in Scheme? | With "load" function (load "my_scheme_program") |
| Lisp function: car(xs) | returns the head element of the list xs |
| Lisp function: cdr(xs) | returns the tail element of the list xs |
| Lisp function: cons(x xs) | joins an element x and a list xs to create a new list |
| Lisp function: list(x1, x2, ... xn) | generates a list from its arguments |
| Explain what is different about a Special Form in Lisp. | Resembles a function, but have special evaluation rules, rather than just standard function. eg: if, evaluates the first argument, and returns the next if true, or the one after if false |
| What is a lambda abstraction? | A nameless function specified with a lambda special form. (lambda args body) where args is a list of formal arguments and body is an expression that returns the result of the function evaluation when applied to actual arguments |
| How do you define global names in Lisp? | Special form define (define name value); usually values are lambda abstractions |
| What is the value of the following Scheme expression? (cons (car (cdr (cdr '(1 2 3 4 5)))) '(6 7)) | (3 6 7) |
| Scheme belongs to which class of languages? | Functional |
| What sort of error is made when a variable is used in a function in C/C++ that has never been declared? | Static Semantic Error |
| Which of the following classes of programming languages is also classified as imperative? | Procedural |
| What language was the first to have the concept of a class as a data abstraction? | Simula 67 |
| What language was the first block structured language? | Algol 60 |
| Which programming language is arguably considered the first high-level programming languages? | Fortran |
| The name of the notation used for Scheme's operators and function calls is | Cambridge Polish notation |
| What is the value of the Scheme expression? (cons (car (cdr ‘(1 2 3 4 5)))) ‘(6 7)) | (2 6 7) |
| The main strength of Cobol is in the area of… | Business computation |
| Given the unification goal vehicle(car, X, green) = vehicle(Y, tow(trailer, Z), green) what variables are bound to which values? | Y = car, X = tow(trailer, Z) |
| Which of the following characteristics are considered essential (by the textbook) to make a programming language successful? | It has excellent compilers; It is easy to use by a novice |
| What kind of parsing technique(s) can be used to implement a parser for an LL(1) grammar? | Recursive descent parser; Bottom up parser; Top down parser |
| Which of the programming tools below is called a virtual machine? Compiler Preprocessor Linker Interpreter | Interpreter |
| What class of error is detected by the parser component of a compiler? | Syntax error |
| The C programming language belongs to which classification category? | Imperative, von Neuman |
| Logic programming is a _________________________. | form of declarative programming, and a program is a collection of axioms.The logic programming system uses inference steps to prove the goal is true using a logical resolution strategy. |
| Given) C:- A,B. D:- C. Explain what forward and backward chaining is. | Forward chaining deduces first that C is true and then that D is true because C is true. Backward chaining finds that D can be proven if sub-goal C is true, the system determines that C is true, therefore D is true. |
| Which Chaining does Prolog use and why? | Backward chaining, it is more efficient for large collections of axioms |
| True or False: Prolog is mixed compiled and interpreted (interactive). | True |
| List example applications for Prolog: | Expert systems, Artifical Intelligence, Natural Language, understanding, Logical puzzles and games. |
| True or False: rainy(rochester) is different than rainy(rochester) :- true. | False |
| What are queries? | Interactive entries used to execute goals eg: ?- G1, G2, ... Gn. |
| What does ?- rainy(C) do? | it as the goal to find a city C for which rainy is true, if any. |
| What causes backtracking (prolog)? | An unsuccessful match in a query forces backtracking in which alternative clauses are searched that match (sub-)goals |
| What is an AST? | A form of intermediate code produced by the semantic analyzer, it is annotated with useful information such as pointers to the symbol table entry of identifiers |
| What kind of parsing technique(s) can be used to implement a parser for an LL(1) grammar? | Recursive descent parser; Bottom up parser; Top down parser |