The test is open-everything with the sole limitation that you neither solicit nor give help while the exam is in progress.
The final exam is in two parts.
| Problem | You got | Out of |
|---|---|---|
| 1 | 15 | |
| 2 | 10 | |
| 3 | 15 | |
| 4 | 10 | |
| 5 | 15 | |
| 6 | 10 | |
| 7 | 15 | |
| 8 | 10 | |
| TOTAL | 100 |
{dog: "spike",
id: 234234,
pups: [234, 25254, "spot", 3.2e5, false],
house: {color: "GREEN", date: {m:4, y:2005, d:22}},
nothings: [{}, {}]
}
Write the JavaCC TOKEN clauses, SKIP clauses, and parsing functions for syntax analysis of this little object description language. Do not include the PARSER_BEGIN/PARSER_END section or any action routines.
void f(string z, ...) {
struct e {
double x;
string f() {return " " * y * #z;}
};
e[] p;
print (p.c[1].f()[6 |~ x+2 >> x]);
}
EXP -> "{" EXP "}" | "[" EXP "]" | "(" EXP ")" | EXP EXP | ID
for (int i = 0; i < #a; i++) {
print($a[i]);
print(", ") if (i != #a-1);
}
With optimizations turned off, my compiler produces:
p0: copy 0, i1 L0: copy [i0-4], r0 less i1, r0, r1 jz r1, L1 assert_not_null i0 copy [i0-4], r2 assert_in_range i1, 0, r2 mul i1, 4, r3 add i0, r3, r4 copy [r4], r5 to_string r5, r6 param r6 call __print, 4 copy [i0-4], r7 sub r7, 1, r8 not_equal i1, r8, r9 jz r9, L2 param s0 call __print, 4 L2: inc i1 jump L0 L1: exit s0: [44, 32]