Midterm I
Part of
materials for 22C:50, Summer 2003
|
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.
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
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: ________________________________________________
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 ______ _ ______ _
MACRO T,I ____________________ B I IF I > 1 ____________________ T (I-1) T (I-1) ____________________ ENDIF ENDMAC ____________________ X 3 ____________________ ____________________ ____________________
Name: ________________________________________________
<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 ...