Name: ________________________________________________
ID Number: ___________________
Please write your answers in the space provided! Make sure your name is in the same form as it appears on your University ID card! Illegible and excessively long answers will be penalized! This exam is open-book, open-notes, closed neighbor! This exam is worth 1/5 of the final grade (10 points; allocate 4 minutes per point).
line hexadecimal source
number location value text
1 ________ ________ B 22 symbol table
symbol value
2 ________ ________ X: B #22
________ ________
3 ________ ________ B X
________ ________
4 ________ ________ ; Commentary
________ ________
5 ________ ________ B Y
________ ________
6 ________ ________ B Z
7 ________ ________ Y = 10
8 ________ ________ Z:
For a bit more credit, circle the line numbers of the
lines that cannot be properly processed on the first pass of a two
pass assembler. (0.5 points)
(1.2 points)#define twice(x) x * 2 #define next(x) x + 1 int i = twice(next(4));
a) What is the actual parameter to next? __________
b) What is the actual parameter to twice? __________
c) What does twice(next(4)) get replaced with? _______________
c) What is the initial value of i ? __________
line hexadecimal source
number location value text
1 ________ ________ B X
2 ________ ________ Z: symbol table
symbol value abs/rel
3 ________ ________ . = .+1
________ ________ ____
4 ________ ________ X: B 15
________ ________ ____
5 ________ ________ Y: B 15
________ ________ ____
6 ________ ________ . = Z
________ ________ ____
7 ________ ________ B Y
8 ________ ________ . = Y+1
For a bit more credit, for each symbol in the above symbol
table, indicate whether it would be absolute or relocatable. (0.5 points)
<s-expr> ::= <atom>
| ( [ <s-expr> { <s-expr> } [ . <s-expr> ] ] )
Fill in the blanks in the following C code fragment to complete the
skeleton for a parser for this fragment. (2 points)
void parse_s_exper()
{
if (lex_this != '(') {
_________________________________
} else {
lex_scan();
if ( ) {
_________________________________
parse_s_expr();
while (( )
_________________________________
&& (lex_this != ')')) {
;
_________________________________
}
if (lex_this == '.') {
;
_________________________________
parse_s_expr();
}
}
if (lex_this != ')') EXCEPT_RAISE( parse_error );
lex_scan();
}
}
MACRO X I 0000: _________
IF I > 0
B I 0001: _________
X (I-1)
ENDIF 0002: _________
ENDMAC
0003: _________
X 0
X 1 0004: _________
X 2
X 3 0005: _________