[comp.lang.c] pcc misfeature

schwartz@gondor.psu.edu (Scott E. Schwartz) (11/23/87)

If you compile the following program with 4.3BSD cc or lint

	main()
	{
		while aaa()) {
			bbb("\n");
		}
	}

you get

	"snoob.c", line 4: syntax error
	"snoob.c", line 5: illegal character: 134 (octal)
	"snoob.c", line 5: cannot recover from earlier errors: goodbye!

The first error is correct.  The others... you decide. :-)


-- Scott Schwartz            schwartz@gondor.psu.edu

gandalf@russell.STANFORD.EDU (Juergen Wagner) (11/24/87)

>....
>	"snoob.c", line 4: syntax error
>	"snoob.c", line 5: illegal character: 134 (octal)
>	"snoob.c", line 5: cannot recover from earlier errors: goodbye!
>
>The first error is correct.  The others... you decide. :-)
>....
>-- Scott Schwartz            schwartz@gondor.psu.edu

Of course, the subsequent errors are rubbish (from the point of view of a
human reader). Since error recovery still is a major problem for parsers,
they use certain strategies. In this case, lint wasn't very successful...
Anytime I get errors from cc or lint or whatever, I usually don't care too
much about subsequent errors in the lines following a syntx eror.

--Juergen Wagner (gandalf@Russell.stanford.edu)

meissner@xyzzy.UUCP (Michael Meissner) (12/03/87)

In article <3125@psuvax1.psu.edu> schwartz@gondor.psu.edu (Scott E. Schwartz) writes:
| 
| If you compile the following program with 4.3BSD cc or lint
| 
| 	main()
| 	{
| 		while aaa()) {
| 			bbb("\n");
| 		}
| 	}
| 
| you get
| 
| 	"snoob.c", line 4: syntax error
| 	"snoob.c", line 5: illegal character: 134 (octal)
| 	"snoob.c", line 5: cannot recover from earlier errors: goodbye!

    In general, error recovery is hard for LALR passed compilers.  Yacc in
general, barely tries.  In the Data General C compiler (which does not use
Yacc or pcc) I put in code that tries local error recovery, by checking
what the effect of adding, deleting, or changing a single token in case
of an error, and correcting it on the spot.  Before accepting the change,
the compiler checks the next two tokens to make sure the parse won't run
into more errors down the pike.  In general, this works well for single
token errors, but doesn't handle real badly formed programs.

    For example, heres the output of the Data General compiler with the
same program:

	Error 502 severity 2 beginning on line 2 (Line 2 of file test_error.c) 
		while aaa()) {
		      ^
	Syntax Error.
	A symbol of type "(" has been inserted before this symbol.
-- 
Michael Meissner, Data General.		Uucp: ...!mcnc!rti!xyzzy!meissner
					Arpa/Csnet:  meissner@dg-rtp.DG.COM