Answer (A) The actions can be used to correctly type-check any syntactically correct program
SHORT ANSWER:
A grammar is given with the SDT actions on it.
Now, the option A:
“ The actions can be used to correctly type-check any syntactically correct program “
- syntactically correct program: so we have to do SDT TYPE-CHECKING on any SYNTACTICALLY CORRECT PROGRAM
this means the PROGRAM (string) is legally generated by the grammar
(so syntactically correct programs ensured)
- now correctly type-check: the SDT defined can ONLY TELL what the CORRECT SYNTAX is!
Thus, the SDT that defines the semantics of the declarations and expressions IS USED TO type-check the declaration and expressions of integer and boolean type
this will ensure that correct type-checking of any syntactically correct program is happening!
Long Answer:
OFFICIAL KEY says option (B) The actions can be used to type-check syntactically correct integer variable declarations and integer expressions
So, as said above, we have already a SYNTACTICALLY CORRECT program (string generated by the grammar)
The KEY thing for me while answering this question would always be to see
- GRAMMAR : syntactically correct programs
- SDT : type-checking
both separately.
First Grammar will generate SYNTACTICALLY correct programs (as always if grammar is used to generate the strings, THOSE STRINGS WILL BELONG to the grammar and thus THOSE PROGRAMS WOULD BE SYNTACTICALLY CORRECT)
Second step, the program is passed to the SDT and it type-checks it for both
Now, the program generated by grammar be like:
ID
So, after generating the string (program) : ID
we perform SEMANTIC ACTIONS.
So, our example: string: ID
Now the program is having integer expressions or boolean expression can NOT BE DETERMINED IN syntax analyzer phase, and ONLY THE SDT ACTIONS will determine the nature of expression (integer or boolean)
Thus, never this SDT could fail to correctly type-check boolean variable expressions: as there be none.
All the expressions are of INTEGER VARIABLE only.
And integer variables too are being correctly type-checked as per the specified SDT rules, as the actions seem to correctly propagate and check type-meaning of the variables.