From: Eric S. Raymond Date: Sat, 26 Feb 2000 00:36:00 +0000 (-0500) Subject: Jonathan Nieder's spark-precedence fix. X-Git-Tag: 0.21~24 X-Git-Url: http://thyrsus.com/gitweb/?a=commitdiff_plain;h=983236c6530f92b21d266216c0df7ab52f220310;p=intercal.git Jonathan Nieder's spark-precedence fix. From jrnieder@hotmail.com Fri Feb 25 11:00:42 2000 Date: Fri, 25 Feb 2000 21:21:03 -0800 From: Jonathan Nieder X-Mailer: Mozilla 4.7 [en] (Win95; I) To: esr@thyrsus.com Subject: Intercal Bugfix can be fixed quite easily (in code changes; not in that search for the problem, though). I'm not sure about side effects of my solution. It's not very well-tested. But, the following program compiles and does the right thing: PLEASE ,1 <- #1 BY #1 DO ,1 SUB #1 #1 <- #0 DO WRITE OUT ,1 SUB #1 '#1' So, it must fix the bug. Here's the deal. As bison parses that third line, it eventually ends up with an unambig on the stack and a spark in look-ahead. It wants to know whether it should "reduce" the unambig to a sublist1 or to continue parsing and hope for a unambig followed by a new sublist1. This particular reduction has the prescedence of the (fake) token HIGHPREC. HIGHPREC, in this particular grammar, has the highest prescedence possible. Since it has higher prescedence than the look-ahead token, bison reduces, and it is straightforward from there to parse the DO WRITE OUT ,1 SUB #1 as a command. It then goes on the parse the new "command" after it, and it can't even find a DO to make into a "please". Since programs can only be lists of commands, it of course signals an error. So, to fix it, simply switch the command (on line 103 of ick.y) %nonassoc HIGHPREC with the command (on line 102) %nonassoc EARS SPARK So, change %nonassoc EARS SPARK %nonassoc HIGHPREC to %nonassoc HIGHPREC %nonassoc EARS SPARK Then recompile and enjoy a new ick that has THAT problem fixed... It's such a trivial change that I decided not to include a contextual diff. Hope this helps INTERCAL to suck in even more programmers' time... --- diff --git a/src/BUGS b/src/BUGS index a420d32..bc3f194 100644 --- a/src/BUGS +++ b/src/BUGS @@ -72,18 +72,6 @@ BLR = Brian Raiter the modified behavior of select's return type depends on this, so there's not much we can do about it as things stand. -5) (BLR) An array can't have sparks or ears in its subscript list after the - first dimension. That is to say, this: - - DO ,1SUB'#1'#1 <- #0 - - works fine, but this: - - DO ,1SUB#1'#1' <- #0 - - doesn't parse, and gets treated as a syntax error (thus it is likely - to be a problem with the grammar). - TO DO 1. (ESR) Add more optimization templates, esp. idioms for +, -, *, /. diff --git a/src/ick.y b/src/ick.y index 9bb6bbe..9f74a6b 100644 --- a/src/ick.y +++ b/src/ick.y @@ -100,8 +100,8 @@ static tuple *splat(void); %type perform %type please preftype -%nonassoc EARS SPARK %nonassoc HIGHPREC +%nonassoc EARS SPARK %% /* beginning of rules section */