in Compiler Design
3,179 views
7 votes
7 votes
if there is miss spelling in some keyword in a program then this misspelled keyword will be treated as lexical errors or it will be treated as a new identifier and accepted as a token  ??

 

 ex -   whiel (1) ;      here while is misspelled as whiel
in Compiler Design
by
3.2k views

4 Answers

4 votes
4 votes

No lexical error, because lexeme "whiel" matches with the pattern of "identifier" hence a token will be created and stored in the symbol table.

4 Comments

ok , initialy 'whiel' will be treated as a identifier and a token is created .  but when compiler will proceed furthur it will be caught by syntax analyer      or     by semantic analyser ??      plz also explain if it will declared syntax error then for which reasons     or  if it will be declared as semantic error then for which reason ?

  for example here in case of syntax error the compiler says there is no production of kind 'whiel()'  to parse it .

and in case of semantic error  compiler can say type is not declared for identifer ' whiel'
0
0
whiel(1); there is no syntax error, it's a perfect function call.

I think it will be a static semantic error because we are calling a function which is not defined.   Compiler will catch it at compile time.
7
7
No semantic error also perhaps. An error will be there while linking.
0
0
suppose we have a syntex like this

whiel (1)
{

printf("hello");

}
then is this a syntex error or symantic error ???

can be consider this syntex as a loop??
0
0
0 votes
0 votes
whiel will be treated as a function name ,hence a token is generated.
0 votes
0 votes
Lexical analyzer do not show any error because it just compare the tokens with identifiers it does not check the spelling .
The lexical analyzer matches the tokens with identifiers and stores it into symbol table . spelling checking is done by semantic analyzer.
0 votes
0 votes
No lexical error, since it's syntax errow which will identify by semantic not lexical analyser.
by

Related questions