UP | HOME

Practice Final
COP-3402, Spring 2024

Exam Day Details

  • Online, Friday, 04/26/2024 0830–0950
  • Time-limited set of questions on webcourses
  • For SAS, please notify the instructor and you may submit answers after the above ending time as needed.
  • Questions drawn from homework, lecture, and projects
  • May use content contained on the course web page
  • May use code previously written by you solely for solving the programming projects
  • May use personal course notes
  • Any questions or need for clarifications can be made on the course's Ed Discussion site
  • Use of any other website, materials, notes, answers, communications, content, unauthorized assistance of any kind, etc. is a violation of academic integry and is cause for a failing grade and a report to UCF's Student Conduct and Academic Integrity office.

Practice Questions

  1. What command-line unix tool can be used to show the files in a directory?
  2. In the compilers we made in class (toy or simplec), how were numbers represented in the input? For instance, would the number 2 be represented with binary 00000010 in the input lanugage?
  3. What is the data structure that is output by a parser?
  4. What did we use semantic actions for in bison for the first simplec project on parsing?
  5. Represent the regular expression ab(c*) as a (nondeterministic or deterministic) finite automaton.
  6. Given the following context-free grammar, what would the parse tree look for by aaccdbb? Note that capital letters are nonterminals, lowercase letters are terminals, and productions are specified with →.
    1. T → aTb
    2. T → V
    3. V → cV
    4. V → d
  7. How does the shift action change the parsing state in an LR parser?
  8. Draw an AST for the following SimpleC program. It is not necessary to get the names of the AST nodes exactly the same as ast.h.

    f(a) int -> int {
      return 1;
    }
    
    main {
      return f(2);
    }
    
  9. Draw an AST for the following SimpleC program and annotate each exrpession node with the type discovered by the type checker. Is this program type-safe? If not, circle the node where the SimpleC type-checking discovers a type error.

    main {
      int y;
      return 2 * y + "hello";
    }
    
  10. In order to implement C-style functions, what information needs to be stored on the stack?
  11. Draw the stack frame after g is called from f and g has setup the complete stack frame. Feel free to use either the x86 32- or 64-bit conventions from any common system.

    int g(int x) {
      int y;
      return x + y;
    }
    
    int f() {
      return g(1 + 2);
    }
    
  12. Given the following C-style code, write equivalent x86 assembly code. Feel free to use any variable storage scheme you like, but say what assumptions you make.

    y = &x;
    *y = 8;
    
  13. If the variable x is stored on the stack offset -8 from the base pointer, what assembly instruction(s) would be equivalent to the following C-style code?

    x = 8;
    
  14. What assembly code would be equivalent to C's x && y, assuming x and y are in %rax and %rbx respectively?

Not on the test

  • How does a bitwise & differ from a logical && in C?

    /*
    $ gcc -o short-ciruit short-ciruit.c; ./short-ciruit 
    1 && hello, world!
    0 || hello, world!
    */
    
    #include <stdio.h>
    
    int main(int argc, char **argv) {
      1 && printf("1 && hello, world!\n");
      0 && printf("0 && hello, world!\n");
      1 || printf("1 || hello, world!\n");
      0 || printf("0 || hello, world!\n");
      return 0;
    }
    

Author: Paul Gazzillo

Created: 2024-04-19 Fri 12:46

Validate