Skip to content
Official PYQ · 2005

GATE CS 2005 Q61 — Parsing (LL, LR)

Explain with AI

Consider line number 33 of the following C-program.

int main() {                /*Line 1 */
    int I, N;               /*Line 2 */
    fro (I=0, I<N, I++);	/*Line 3 */
}

Identify the compiler’s response about this line while creating the object-module:

Choose one option
View worked solution

Answer: A

To determine the compiler's response to Line 3, let us analyze it phase-by-phase during compilation:

fro (I=0, I<N, I++);
  1. Lexical Analysis:
    • The lexer groups characters into tokens.
    • fro is not a keyword, but it is a perfectly valid sequence of characters representing an identifier (like a variable or function name).
    • Therefore, there is no lexical error.
  2. Syntax Analysis (Parsing):
    • Since fro is treated as an identifier, the parser interprets the statement as:
      identifier ( expression , expression , expression ) ;
    • This matches the syntax of a function call to a function named fro with three arguments separated by the comma operator.
    • Therefore, there is no syntax error.
  3. Compilation to Object Module:
    • In C (specifically C89/C90, which was the standard at the time of this question), calling an undeclared function is permitted under the implicit function declaration rule (the compiler assumes the function returns an int).
    • This might trigger a compiler warning, but it does not prevent the successful compilation and creation of the object module.
    • The actual error (undefined reference to fro) will only be raised by the linker, not during the compilation phase.

Thus, there is no compilation error while creating the object module.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Parsing (LL, LR) questions