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 } } Compiler Design compiler-design lexical-analysis descriptive + – Sahil1994 asked Dec 12, 2017 retagged Jun 23, 2022 by Lakshman Bhaiya Sahil1994 593 views answer comment Share Follow See all 9 Comments See all 9 9 Comments reply Show 6 previous comments Sahil1994 commented Dec 12, 2017 reply Follow Share @Anu total−value since we cannot use hyphen in variable declaration i think so thatz y iot will be lexical error...we need to use underscore _ 0 votes 0 votes Sahil1994 commented Dec 12, 2017 reply Follow Share @Anu007 @Nitish but the solution which i have saying 5=Num; // semantic error not syntax error..please confirm on this....? void main() { int total-value, Num=2,sum=5,var1; // total-value Lexical error as hyphen is not allowed 5=Num; // semantic error var1=2; sum=num*1; // num is undeclared variable as C is case sensitive, so Num and num is different (semantic error) if(sum=var1) // no error { sum=sum+1 // semicolon missing syntax error } 0 votes 0 votes joshi_nitish commented Dec 12, 2017 reply Follow Share 5=var; is syntax error, which is known as L-value error. 0 votes 0 votes Please log in or register to add a comment.
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. gmrishikumar answered Jan 7, 2019 gmrishikumar comment Share Follow See all 0 reply Please log in or register to add a comment.