[comp.bugs.4bsd] yacc grammar for LINT.

rbutterworth@watmath.UUCP (Ray Butterworth) (11/20/86)

Consider the following contrived example:
                                              func(x)
                                              {
                                                  if (x) return 0;
                                                  if (!x) exit(1);
                                                  /*NOTREACHED*/
                                                  return;
                                              }

Even if LINT doesn't know that exit() never returns, the NOTREACHED
should tell it.  It should complain that the second return is never
executed.  In fact the NOTREACHED is totally ignored.  Putting a ";"
before the NOTREACHED makes LINT behave correctly though.

What is happening is that in parsing the "if (!x) exit(1);", yacc
has to read ahead to make sure there isn't an "else" to go with the
"if".  It processes the /*NOTREACHED*/ at this point and zeros the
"reached" flag, but there isn't an "else" so the statement is
considered to be complete at the semicolon after the exit and
everything is cleaned up for the end of a statement and the "reached"
flag is set to 1 again.  Now it tries to parse the next line, but the
/*NOTREACHED*/ has already gone, so the next thing it sees is the
"return" and since "reached" is set it doesn't realize that this
code is never executed.

Anyone know how to fix this?
(The yacc source that is, not my stupid example.)