 |
 |
 |
 |
|
| In Bison tutorial you said that we may insert semantic rules in the middle of a grammar rule. But also you showed how to use "marker" variables to avoid using semantics inside the grammar rule. Which should we use? | | You can use either markers or semantic rules in the middle of grammar rules -- there is no restriction. It is recommended to use mid-rule semantic actions. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
| First we have "Stmt::=type Init {,Init} semicol".
Elsewhere we have "type identifier {comma type identifier}". Is there a
difference between the "," and the "comma"? What does "," stand for? | | That's just a typo -- the "," was supposed to be "comma". |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
| What are the "tklp", "tkrp" tokens? | | That is a mistake, it should say "lp" and "rp" respectively. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
Should the following program produce an error?
int a=2.2; | | No, you don't need to check that the expression's type matches the variable into which it is being assigned. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
| There is a mistake on page 4. Instead of "int a = 1 + 2 ;" it should be "a = 1 + 2", because there shouldn't be output for variable declarations. | | The mistake is fixed now. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
Should we do type checking for:
int a;
real b;
c = a + b; | | No, "a" and "b" are non-constant expressions, so no type-checking should be done for "a + b". |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
You said that we should ignore variable declarations, but should the following:
int a = 1 + 1.1 or
real a = 1 + 1.1
produce a type mismatch error ? | | Those two should produce type mismatch errors. What you shouldn't print for variable declarations is the "id : type" message. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
When compiling our parser we get this error:
"attributes.h:24: error: member `idAttribute ::id' with
constructor not allowed in union" | | Switch the type of STYPE from a union to a struct (instead of "typedef union { ... } STYPE;", use "typedef struct { ... } STYPE;". |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
| In a case of syntax error, is it allowed for our compiler to print output
for previuos lines in that program (before the syntax error)? | | Yes. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
| In the lex file operator "^" is legal .. but in the hw pdf file is not
mintioned. do we have to consider it? | | You can ignore "^". It will not be used in the testing. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
| Can we assume, that there is a maximum length the “identifier” may be? | | No, you can't make such an assumption. Use STL's std::string to avoid having to handle memory allocation for strings. |
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
Do we have to print the "identifier : type" message for variable assignments that occur anywhere in the parse tree, or just in the top level? For example, should the message be printed for the following:
if (a==5) while (true) while (false) if (b==7) c=9; | | You should print the message for *every* assignment into a variable, no matter where it occurs in the parse tree. In the example, the message "c : int" should be printed. |
|
 |
 |
 |
 |
 |