The point
Predict what the symbol table will contain before you look. Being able to do that reliably is the difference between debugging and guessing.
Do this
- Predict. For the program below, write down what the symbol table holds after each line: names, and the storage location each one gets.
int a; int b; int sum; a = 3; b = 4; sum = a + b; print(sum); - Check. Compile without
-q, find the symbol-table trace, and reconcile any differences. - Break it three ways, predicting the message before each run:
int a; int a;— duplicate declarationx = 1;with no declaration ofxprint(y);with no declaration ofy
- Grade your own messages. For each: does it give the LINE? name the IDENTIFIER? say what was EXPECTED? suggest a FIX? Rewrite any that score below three out of four.
- Theory question. Explain in two sentences why none of these three errors could have been caught by the parser, referring to what a context-free grammar can and cannot express.
- Design question. Our table is a flat array searched linearly. Sketch what changes if it becomes a hash table. Which functions change? Which do not? Why does that second answer matter more?
Deliverable
Your predictions beside the actual traces; three improved error messages; your two-sentence answer to step 5; and a short answer to step 6. Steps 3–4 feed Lab Question 5 directly.