raising compiler errors: human coding vs compiler-compiler generated

17 views
Skip to first unread message

dr.mt...@gmail.com

unread,
Dec 31, 2025, 3:01:47 AM (yesterday) 12/31/25
to Shen
Having battled and won the contest with CL I'm sitting back with a glass of Xmas bourbon as part of a present.  The problem with S40 BTW was nothing to do with nested error conditions (that apparently is what ChatGPT believed).  I tracked it down to the CL handling of control characters.  That is another story and also not a pretty one.  But I don't want to go into that.

More interesting is what boringcoder has to say

in shen yacc, I am not sure if introducing this extra information should be in the reader itself just for the s-expr grammar or in the yacc file itself for any grammar.

In other word should diagnostic information reside in the compiler specification or the compiler-compiler?   My answer is both.  Shen YACC supplies the raw materials for compiler to trawl around in the failed parse by providing the unparsed residue of the input.  The leading part of that residue generally gives a fair idea of where the problem lies.

But it is not exact for example.  I deleted the highlighted double quote

(define eval-error?
  {l-formula --> boolean}
   "error!" -> true
   "no match" -> true
   _ -> false)  

And the S40 reader gave

reader error near here: (define eval-error? 

Better than a kick in the pants and certainly better than "39.  But good enough?  

This goes back to boringcoder's question: we can do better but this requires at the moment skilled programmer intervention.  We need to interleave compiler instructions
with grammar rules but understanding when to raise an error message is a delicate and serious matter.   The reason it is serious and delicate is that preemptive error messages can rob us of a successful parse.

The situation here is reminiscent of the problem of annotating a Prolog program with cuts to enhance performance.    These are called green cuts but green cuts can become red cuts very easily.  A red cut eliminates successful solutions.  In fact figuring out when a cut is green or red can be very involved because Prolog is of course non-determinstic.  This also holds for Shen-YACC.

So the answer is that Shen-YACC can provide some automatic support for diagnostic errors and this help is cheap and safe.  Going beyond that requires programmer involvement and is compiler specific, possibly work intensive, and not safe.

Mark
Reply all
Reply to author
Forward
0 new messages