edited by
1,035 views
4 votes
4 votes

Even though Semantic analysis is one of the important phase of compiler design.But recently i came across a line that said "The compiler does not detect semantic errors, because they don't violate C rules" .Can someone explain in detail if Compiler does not detect the semantic errors then who Does ? What is the point of having it if it does not detect errors.

edited by

1 Answer

Best answer
14 votes
14 votes

i will try

suppose you want to travel by train, you want to go delhi junction from some location assume bareilly junction, but you purchased a ticket for pilibhit junction.

when you enter the train there is one machine which checks your ticket 

machine has some rules:

1) ticket is valid means it checks itz time and date////it should not be of old date

2) ticket is of train /////it should not be platform ticket

....etc

now you inserted your ticket in machine  the machine  verified it and found correct..and let you enter inside the train..machine doesn't know your intention i.e  you want go to different location but you purchased a ticket for different location .

let it refer to our question

consider you a wrote function that calculates the number of hours you study daily for (assume for 1 week analysis only ) gate exam:

your formula was  

   gate17=(m*t*we*th*fri*sat*sun)///m , t ...sun represents daily hours 

after running program u got wrong output becoz ur formula was wrong instead of adding daily hours u just multiplied the hours. but compiler wont produce error becoz it does'nt voilate any semantic rules...and it don't know ur intention ..but still the meaning of program is wrong then who will detect error. 

now consider by purchasing wrong ticket u are going to right destination that actually u want to go..here machine cannot check than who will check ...the ministry of railways has posted a ticket checker who will check your ticket and can catch u and even insert u inside the jail.

like wise here also programmer has to himself detect error as the ticket checker did it explicitly.

now what is need of having it ....if it does not detect errors.

answer is the line  "The compiler does not detect semantic errors, because they don't violate C rules"  does not mean that it will not detect all the semantic errors....there are various semantic errors which are detected..becoz they violate various rules...- say using float numbers for % operator produces semantic error in C. 

as a machine checks the ticket and if it finds that a ticket is of platform it won't enter u inside the train.....as we cannot remove machine we cannot also remove semantic phase..

 
selected by

Related questions

0 votes
0 votes
1 answer
1
Amit Sharma asked Jun 7, 2016
1,582 views
What exactly a translation Process is ? in compiler Design .Can someone explain Briefly .
0 votes
0 votes
1 answer
2
goluabhinan asked Sep 16, 2018
1,537 views
Any transcription error can be repaired by(a) insertion alone (b) deletion alone(c) insertion and deletion alone (d) replacement alone