COMP1721 - Higher Computing 1B

Computing 1B - Week 10 Tutorial Questions

  1. What tokens would be produced by the Cavy lexical analyzer given this input:

            int answer;
            answer = 42;
            put_i(i);
    

  2. A commonly used measure of program size is the number of semi-identifiers it contains. Words in strings, comments, should not be counted.

    Write a program which prints the number of identifiers in a specified Cavy program.

    For example:


    % ./a.out /home/cs1721/public_html/05s2/cavy/examples/3/selection_sort.c	
    29
    

  3. We need to keep an int value associated with a name (string). Write a function which given a name (char *) returns a pointer (int *) to the int variable associated with that name.

    If the name has not been previously associated with an int variable, an int variable should be created (malloc'ed) and initialized to zero.


Andrew Taylor (andrewt@cse.unsw.edu.au)
Higher Computing 1B, Computer Science & Engineering, UNSW