Reputation:
Consider line number 3 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:
My attempt :
Line 3
has fro
instead of for
keyword of C. Since, lexical analyzer doesn't bother about wrong keyword, that job of syntax analyzer to ensure correct syntax or keyword (i.e. for()
instead of fro()
). Lexical analyzer does tokenization of of program.
Can you explain in formal way please?
Upvotes: 3
Views: 4183
Reputation: 43548
fro
will not match a keyword, but the lexing will go OK and fro
will be classified as an identifier.
At the parsing stage, fro (I=0, I<N, I++)
will be transformed to a function call with three arguments. Note that modifying and reading the I
variable within the same sequence point is undefined behaviour.
During the scope analysis the compiler will complain that no such function exists, or, in case the compiler treats unseen functions as implicitly declared, the linker will complain that there is an undefined reference to a function.
Upvotes: 6