Midterm I

Part of materials for 22C:50, Summer 2003
by Douglas W. Jones
THE UNIVERSITY OF IOWA Department of Computer Science

 

Name: ________________________________________________ ID Number: ___________________

Please answer in the space provided! Your name must be legible and in the form used on your University ID card! Illegible and verbose answers will be penalized! This exam is open-book, open-notes, closed neighbor! This exam 10 points; allocate 4-5 minutes per point.

  1. Hand assemble the this EAL code, and show the final contents of the symbol table. There are extra blanks! Do not fill in unused symbol table entries or next to lines that assemble nothing into memory. It is OK to cross out and replace values where they are changed. (2 points)
     line     hexadecimal     source
    number  location  value    text
    
      1    ________  _______       B    B            symbol table
                                                    symbol    value
      2    ________  _______       W    #11
                                                  ________  ________
      3    ________  _______  ; Commentary
                                                  ________  ________
      4    ________  _______  B    =    5 
                                                  ________  ________
      5    ________  _______  A:   B    B
                                                  ________  ________
      6    ________  _______       B    A
    
      7    ________  _______  B    =    10
     
      8    ________  _______       W    11 
    

  2. Complete the header comments in this fragment of a parser. (2 points)
    void parse_notion()
    /* parse one notion following this EBNF grammar:
    
       _____________________________________________
    
       _____________________________________________
    */
    {
    	if (lex_ispunc( &lex_this, '$' )) {
    		lex_scan();
    		parse_notion();
    		parse_punc( '$', "dollarsign expected" );
    	} else {
    		parse_theme();
    	}
    }
    

     

    Name: ________________________________________________

     

     

  3. Hand assemble the following EAL code, and show what goes in the symbol table. For those lines of code that cause data to be stored in memory, show the memory address that is changed and the value stored in memory. All numbers should be shown in hexadecimal, with a trailing plus sign to indicate those that are relocatable. There are many extra blanks! Do not fill blanks for unused symbol table entries or lines that assemble nothing to memory. (2 points)
     line     hexadecimal     source
    number  location  value    text
    
      1    ______ _ ______ _  A    =    .
    
      2    ______ _ ______ _  .    =    #100         symbol table
                                                   symbol    value
      3    ______ _ ______ _  B:   W    D 
                                                  ________  ______ _
      4    ______ _ ______ _  C:
                                                  ________  ______ _
      5    ______ _ ______ _  .    =    A 
                                                  ________  ______ _
      6    ______ _ ______ _  D:   W    B
                                                  ________  ______ _
      7    ______ _ ______ _  .    =    C
                                                  ________  ______ _
      8    ______ _ ______ _       W    D+2
                                                  ________  ______ _
      9    ______ _ ______ _
    

     

     

     

  4. Write EAL code equivalent to that on the left, but without using any macro or conditional directives. (2.0 points)
    MACRO T,I	                           ____________________
      B I
      IF I > 1                                 ____________________
        T (I-1)
        T (I-1)                                ____________________
      ENDIF
    ENDMAC                                     ____________________
    
    X 3                                        ____________________
    
                                               ____________________
    
                                               ____________________
    

     

     

    Name: ________________________________________________

     

     

     

  5. Consider the following fragment from the EBNF grammar for C:

    <number> ::= <decimal digit> { <decimal digit> }
                |   0 { <octal digit> }
                |   0x { <hexidecmal digit> }

    This describes lexical details of C, so assume we start with a lexical analyzer such as the one used with the EAL assembler. In the fragment of lexical analysis code below, all details that don't relate to the above grammar fragment been left out, including everything about other lexeme types and everything having to do with actually evaluating the number. The blanks relate to key issues that connect with the grammar! Fill in the blanks! (2 points)

    ...
    } else if (*pos == _____ ) { /* it might be a hex or an octal number */
    	pos++; /* skip past 0 prefix */
    
    	if (*pos == 'x') { /* it must be a hexadecimal number */
    
    		____________ ; /* skip past 0x prefix */
    
    		while (isxdigit( _________ )) { /* consume hex digits */
    			pos++;
    		}
    
    	} else { /* it must be __________________ number */
    		while (isdigit( *pos )) {
    
    			if (*pos > ______ ) {
    				lex_error( &lex_next, "bad digit" );
    			}
    			pos++;
    		}
    	}
    
    } else if ( ____________ ( *pos )) { /* it must be a decimal number */
    	do {
    
    		____________ ;
    	} while (isdigit( *pos ));
    
    } else ...