The Gateway to Computer Science Excellence
+4 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 Junior (831 points) | 786 views

4 Answers

+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.

by Boss (44.1k points)
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'
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.
No semantic error also perhaps. An error will be there while linking.
suppose we have a syntex like this

whiel (1)


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

can be consider this syntex as a loop??
0 votes
whiel will be treated as a function name ,hence a token is generated.
by Active (2.5k points)
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.
by (365 points)
0 votes
No lexical error, since it's syntax errow which will identify by semantic not lexical analyser.
by (229 points)

Related questions

Quick search syntax
tags tag:apple
author user:martin
title title:apple
content content:apple
exclude -tag:apple
force match +apple
views views:100
score score:10
answers answers:2
is accepted isaccepted:true
is closed isclosed:true
50,737 questions
57,313 answers
105,046 users