Machine-translated by Google. Questions are authored in English.
Top

Discussion

Detecting that a floating point value has been used to index an array is the responsibility of

  • A.the code generator when it computes the address offset
  • B.the semantic analyser
  • C.the lexical analyser as it recognises the numeric literal
  • D.the parser as it reduces the subscript expression

Answer: B

Correct answer: the semantic analyser

A floating-point subscript is grammatically perfectly valid - the parser reduces it happily, since the grammar says a subscript is an expression and says nothing about its type.

What is wrong is meaning: an index must be of an integral type, and only type checking discovers that. That is the semantic analyser's work, using the types recorded in the symbol table. The pattern is general: the parser enforces form, and errors that are well-formed but nonsensical fall to semantic analysis.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.