![]() |
.. (לתיקייה המכילה) | |
What should happen when a MATH program tries to print an uninitialized variable?
Like this:
int a; { print a }
|
This error is of mixed type - both compile-time and run-time, although in this specific grammar all such checks can be done during compilation. This feature will be left untested, so you're allowed not to implement handling for this case. |
1. Regarding casting: if there is a cast from int to real, such as
real(5), shall the resulting C statement be 5 or (double)5?
2. As previous for real(5.5).
3. Regarding the input statements: does the "Print enter ....:" string
is to be ended with a '\n' or with a ' '?
4. Regarding the ANSI C compliance of the resulting program: the %lf
format specifier is NOT in ANSI C, %f is (%f is for double).
5. What should we do if a malloc() fails????????????????
|
1. double(5) 2. self casting is up to you 3. '\n' 4. Consider this as an exclusion 5. Do what you were tought in programming courses. We expect you to provide stable and consistent program. |
In your example you use the keyword %left when you defined the var OP.
We would like to know what it means, and should we use it in our ex?
|
This is the way for setting operator associativity. See cheatsheet for details. |
i tried
bison math.y
i got : (among other errors )
("math.y", line 21) error: `+' is invalid in %token
whereas at line 21 in math.y i wrote:
%token +
then how are we suppose to define a token that's name is +?
|
At least reccomended to change it from + to "+". You may also define it by some variable: %type PLUS, annd support it by LEX definition. |
1. in scanf and prinf, in the complex format, it is written "%lf+%lfi".
according to the lexical definitions comlex can be 1-i.
When the input is : "print 1-i", should we print 1+-i ?
When the complex is 1-i, the scanf wont work so what will we do?
2. should we indent only one char in the main block?
3. int a = a + 2 is possible ? which error code should we print ? "undeclaredIdentifierError()" ?
4. What is the exact format of the pointer parameter in scanf ? for example: a. (&(*(int *)(data+4))) b. data + 4 c. (int *)(data +4)
5. can u publish the output file of test.math ?
|
1.For "print 1-1i" you'll print 1.000000+-1.000000i, according to the format specification. For "print 1+1i" you'll print 1.000000+1.000000i Assume, that for input you can only recive positive pairs like 3+5i, 4.5+2.3i. This should be enough to solve the ambiguity. 2. Ident is a nice thing. Identing is recommended, implementation is up to you. 3. Yes, undeclaredIdentifierError(). 4. man scanf. 5. No, the C-implementation is implicit. For run-time corectness we'll validate only final outputs of "print" statement. But still, your C-code will be checked for standing in assignment criteria. |
in the semantics of the rule
st -> print identifier sep
you defined that at the end of the print a \n is needed.
However, in the example you gave at end of exercise no
\n appeared.
Which is the correct semantics?
| There must be "\n". |
We have a question regarding the memory management: are we allowed to allocate
memory dynamically without freeing it in the end?
|
You're writing some code that gonna be executed by others (course staff for example). So your code must be accurate and stable meaning that the memory must be managed correctly. |
1. from previous questions in the FAQ section it is implied that "1+i"
is a legal complex while according to the exercise
({real}[\+\-]{real}i) its not legal.
2. do we need to check at compilation time division by zero cases when possible?
3.what is the definition of integers division in "math"?
4. is it legal to do: "int x;int y=x;{}" do we need to handle this?
|
1. Right, fixed. print can be applied only to some identifier. We used the simplified syntax to illustrate the behaviour 2. No. 3. Same as C: 3/2 = 1. 4. CORRECTED: IT IS LEGAL. WE WON"T TEST THIS FEATURE. |
1. from previous questions in the FAQ section it is implied that "1+i"
is a legal complex while according to the exercise
({real}[\+\-]{real}i) its not legal.
2. do we need to check at compilation time division by zero cases when possible?
3.what is the definition of integers division in "math"?
4. is it legal to do: "int x;int y=x;{}" do we need to handle this?
|
1. right, it should be 1+1i. Remember though, that print can be applied only to some identifier. 2. No. 3. C-like: 3/2 = 1 4. No, you use undeclared variable. |
Can we use some temporal complex variables for computations?
| You're allowed to use ONE temporal complex variable, it should be also allocated in DATA. |
Consider a definition like: "int a; int b=a;" (or "int a=5; int
b=a;"). In the assignment it's written that it's legal ("the variable
will have its value right after its declaration"), but in the FAQs (one
before the last FAQ) you said it's an error. It's logical to allow such
syntax. Can we assume that such syntax is correct?
|
My fault - it's run-time check, so you shouldn't check it in compilation time. I fixed the FAQ. |
do you forbid the use of global variables in any way?
| In the generated code - surely. But you may use them in yacc itself. |
should we ignore the possibility of dividing by zero in complex numbers as well?
| yep |
Is there a bonus if the program allows more than 50 variables? are there any other possible bonuses?
|
Not really. Personally I would promise bounty for caught cheaters, but not this time. |
What should we do if the program has symbols after the body, i.e.
"{some commands;} some other stuff"? Shall we do the same for every
error bison tells us about (i.e. implement it in yyerror()), for example
"{print 5;}"?
| Let BISON hadle it by it's default way. |
May we assume that malloc always succeed?
| Yes |
may we "postpone" claculations which can be done during compile time,
to the C program output?
such as:
g = 2+3;
| yes |
may we assume that no lexical errors exist ?
| You must report lexicalError in such case |
If there are few errors, which one are we supposed to print?
for example:
int a;
int a=5.0;
(there are both: identifierRedeclarationError and typeMismatchError)
|
You are supposed to report the earliest error you meet. In this case, before you approach 5.0 you can detect identifierRedeclarationError . |
Are we allowed to use a temporary file to write to (while parsing), and to read
and print from it at the end of parsing?
| no |
if there are aninitialized variables, should they be printed in the generated code? (in the example you wrote, there is only an initialized variable).
| Assume, that no uninitialized variable will be printed |
what should be in the target code when there is assign to a complex number:
should it be 2 commands - one for assigning the real part and one for the
immaginary part, or should it be in the same command?
| This a subject to your implementation. |
what should be done if there is exp->id , when the id is not initialized
|
No special treatment should be for checking variable initialization. This is not compile-time check. |
what is the proper code for exp -> TYPE L_PAREN EXP R_PAREN when the type
is complex - how should it be represented in the target code?
|
This is well-defined in the exercise. It must report complexConversionError. |
if any lexical or syntactical error is encountered,
the program should abort?
| Yes, in this case you're allowed not to free allocated memory. |
should i explicitly tell bison to end the program when it reduces to S
?
|
it's ok to consider that the compilation is over and to produce final c-code. Don't terminate Bison explicitly. |

