Re: syntax errors

jmccarty@spd.dsccc.com (Mike McCarty)
Thu, 23 Feb 1995 21:56:09 GMT

          From comp.compilers

Related articles
syntax errors miles@minster.york.ac.uk (1995-02-20)
Re: syntax errors gvcormac@plg.uwaterloo.ca (1995-02-22)
Re: syntax errors jmccarty@spd.dsccc.com (1995-02-23)
Re: syntax errors epklell@kaepk1.ericsson.se (1995-02-27)
Re: syntax errors mikey@ontek.com (1995-02-28)
| List of all articles for this month |

Newsgroups: comp.compilers
From: jmccarty@spd.dsccc.com (Mike McCarty)
Keywords: errors, design
Organization: DSC Communications Corporation, Plano, Texas USA
References: 95-02-151
Date: Thu, 23 Feb 1995 21:56:09 GMT

<miles@minster.york.ac.uk> wrote:
)Hello. Could anyone point me to work done on locating (and presenting)
)syntax errors? ...


Some time back our company was looking for a compiler. We were
considering requirements, and I wrote a brief memo to a fellow
concerning -my- thoughts on this subject. I have written a compiler,
and a couple of assemblers, along with interactive expression
evaluators. Those who have used them have expressed satisfaction with
the error reporting.


-------------------------------------------------------------------
Benjamin,


At one time I mentioned in a meeting that I had some concerns over
error reporting by compilers. At that time I informed you that I had a
definite, concrete criterion in mind, but did not convey the criterion
to you. Since you (as a group) are considering a new (GNU) compiler, I
would like to present to you my view on error reporting.


As a minimum, each error report presented by a compiler should contain
four (4) pieces of information.


1. The precise location in the source where the error was
detected.
a. The name of the source file in which the error was
detected
b. The line number in the source file of the line on
which the error was detected
c. The actual line in which the error was detected
d. An indicator of the location in the line where the
error was detected
2. The severity of the error
3. An indication of the nature of the error
4. What fixup/action was taken to recover from the error


Examples of acceptable error reports:


fred.c[127]:
x = 2*(3+4;
^
Error: Expected ')' in expression, object generation suppressed.


-------


fred.c[127]:
x = 2*(3+4;
^
Warning: Missing ')' in expression, parenthesis supplied.




-------
(declarations:
char *x;
int *y;
)


fred.c[127]:
x = y;
^
Warning: Assignment of pointer to different type, conversion supplied.


---------
(declarations


int fred(long,long);
int x, y, z;
)


fred.c[127]:
x = fred(y,z);
^
Warning: Prototype specifies longer form, conversion supplied.


fred.c[127]:
x = fred(y,z);
^
Warning: Prototype specifies longer form, conversion supplied.


---------------------


Example of an unacceptable error report


(source
for (x = (y+z*m;; x != (y+mm; x++)
)
fred.c[127]: missing ')' before ';'
fred.c[127]: missing ')' before ';'
fred.c[127]: missing ')' before ';'
fred.c[127]: missing ';' before ')'
fred.c[127]: syntax error ')'


(This is typical of what the MicroSoft C compiler generates! Now how
does one figure out what is wrong from an error report like this? No
source is listed, the location in the file is ambiguous, and seemingly
contradictory information is presented.)


------------------------------


Corrected error report


fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Error: Missing ')' in expression, object generation suppressed.


fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Error: Missing ')' in expression, object generation suppressed.


fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Warning: Missing ')' in for loop, ')' supplied.


fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Warning: Missing ';' in expression statement, ';' supplied.


fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Error: Statements may not begin with ')', ignoring source to next ';',
              object generation suppressed.


--------------------------


Additionally, error reports should appear in both the job output file
(may be a terminal) and in any listing generated. In the listing, the
line number and file name may be omitted, and the line on which the
error is detected should not be repeated (unless the error is detected
in an include file, in which case these pieces of information should
appear).


In the case where multiple errors are reported on a single line, an
abbreviated error report is acceptable (even preferable).


-----------------------------------------------
Example of abbreviated error report


fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Error: Missing ')' in expression, object generation suppressed.
^
Error: Missing ')' in expression, object generation suppressed.
^
Warning: Missing ')' in for loop, ')' supplied.
^
Warning: Missing ';' in expression statement, ';' supplied.
^
Error: Statements may not begin with ')', ignoring source to next ';',
              object generation suppressed.


-----------------------------------------


Or even this




fred.c[127]:
for (x = (y+z*m;; x != (y+mm; x++)
^
Error: Missing ')' in expression, object generation suppressed.
^
Error: Missing ')' in expression, object generation suppressed.
Warning: Missing ')' in for loop, ')' supplied.
^
Warning: Missing ';' in expression statement, ';' supplied.
Error: Statements may not begin with ')', ignoring source to next ';',
              object generation suppressed.


--------------------------------------------------


The precise wording of things is not the intent of this memo, but rather
the completeness of the report. Layout is also not really under
discussion.


The point is that the compiler should generate error reports which aid
the user in diagnosing the problem with his source and which indicate
what action the compiler decided to take as a result of detecting the
error. At the end there should be a summary of errors recorded,
including any overall action taken.


------------------------------------
5 Errors, 6 Warnings, 2 Information
No object file produced.
------------------------------------


In the case that no errors were detected, the summary is optional.


I hope you find this information helpful, even useful.


Mike
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.