in Compiler Design edited by
21,456 views
80 votes
80 votes

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:

  1. No compilation error
  2. Only a lexical error
  3. Only syntactic errors
  4. Both lexical and syntactic errors
in Compiler Design edited by
21.5k views

4 Comments

This is nothing but a Linking error

as because during compilation compiler will think that it is a Function

But during Linking there will be no module named as that so, Linker is failed.
6
6

loop statement is written as fro (I=0, I<N, I++);. This contains both lexical and syntactic errors:

  1. Lexical error: The keyword "for" is misspelled as "fro", which is not recognized by the C compiler. This is a lexical error because it involves incorrect spelling or misuse of language elements.

  2. Syntactic error: The loop statement has three expressions enclosed in parentheses, separated by commas. However, the correct syntax requires semicolons (;) instead of commas (,) to separate the expressions. So the correct form should be for (I=0; I<N; I++).

Therefore, the compiler will report both lexical and syntactic errors in line 3 of the code. The correct option would be D. Both lexical and syntactic errors.

0
0

@Subhasish012 its wrong bro.

0
0

9 Answers

1 vote
1 vote
There is no error in the above code. Actually it is a link error. Here compiler fro is a function which is not declared. Hence, it will not produce any error. It will only throw a warning in C.
0 votes
0 votes

Syntactic error- character or string incorrectly placed in a command or instruction that causes a failure in execution.

Here, for spelling is wrong.

Incorrect use of reserved word .

1 comment

while this is definitely Syntactical error, it's not because of 'fro'. While parsing, it may consider this as a function call until the parser realizes that there is a semicolon separating the argument and not comma. Thus it throws an error.

Please correct me if my understanding is wrong.
0
0
0 votes
0 votes

i think its an LEXICAL ERROR

because lexical analyser stores the LEXEMES in terms of    "PATTERN"

like identifiers are stored with an pattern----------- >  L(L+D)^* where L is an alphabet, D is an numerics.

it also stores QUANTIFIERS,KEYWORDS,... all  PREDEFINED  lexems in terms of PATTERN'S..

 

0 votes
0 votes

answer should be (A) 

I am not sure if this will work in other compilers or not. But my version of GCC doesn’t require an explicit extern in this case.

Answer:

Related questions