![]() |
.. (לתיקייה המכילה) | |
Should we support struct nesting? | |
No. As the syntax is described, the fields of a struct can be only primitive types. |
For an if / while statement followed by a block {} how many scopes should we open? | |
Two scopes. One for the if / while and one for the block. Notice that in this case the if / while scope will be empty. The test t2.{in,out} shows such an example. |
Can a struct with some name can be declared in a function with the same name? | |
The shadowing rule that appears for variables, functions an structs holds for all identifiers: an identifier cannot be declared if another identifier of the same name already exists in scope or in one of the parent scopes. In the case that the input contains this error you should call errorDef. |
What is the order of printing the output when struct declarations are involved? | |
In the end of each scope (also the global) all of the struct declarations would be printed last (in the order of their declarations, in case there is more than one). For example the output of this scope: { int x = 4; struct j { int y; bool r; }; byte y = 100 b; int z; } would be: x INT 0 y BYTE 1 z INT 2 struct j {INT y,BOOL r} In the global scope all structs should be printed after all functions. |
What error should we output if we encounter x.y where x is defined but is not of struct type? | |
You should call errorUndef. |
What error should we output if a struct is defined with 2 members of the same identifier? | |
You should call errorDef in both cases. |
Can 2 structs have the same members? | |
Yes. |
Are the assignment rules for struct members the same as for regular variables? | |
Yes, the assignment form byte to int is allowed also for struct members. For example: struct t { int num; }; byte x = 100b; struct t y; y.num = x; is valid. |
When trying to use x.y where x is of an already declared struct type, but doesn't have a struct member named y, what id should we pass to errorUndefStructMember? | |
As it says in the assignment you should pass x (the struct variable). |
In the case of type mismatch in the condition of an if statement that opens a new block, for example: | |
The output can be either: ---end scope--- y INT 0 ---end scope--- line 2: type mismatch In the case that you check the type matching after reducing all of the if statement or: line 2: type mismatch In the case that you check the type matching right after reducing the expression. Both outputs are acceptable. |
Can a struct member have the same identifier as some other identifier that is defined already? | |
Yes. For example, this is valid: struct a { int a }; the same is also for any other defined identifier. |