retagged by
593 views
1 votes
1 votes
What is the diffrence between Lexical error , Syntax error and semantic error..?

Please explain with this example

void main()
{
int total-value, Num=2,sum=5,var1;
5=Num;
var1=2;
sum=num*1;
if(sum=var1)
{
sum=sum+1
}
}
retagged by

1 Answer

0 votes
0 votes

'total-value' is a lexical error. Lexical analyzer won't be able to identify the token.

 

'5=Num;' and 'sum=sum+1' are syntax errors. These tokens don't qualify as valid syntax.

 

'sum=num*1;' is a semantic error as only semantic analyzer will be able to check that 'num' is an undeclared variable.

Related questions

3 votes
3 votes
0 answers
1
Kiran Karwa asked Jan 20, 2018
358 views
what type of error is caused if function name is same as a keyword name?
0 votes
0 votes
3 answers
3
VJ2793 asked Feb 12, 2019
641 views
fro(int I=0; I <5;I++);what kind of compilation error is this ?