Errata

to Write Your Own Compiler

In copies of the book purchased before March 2018, the compiler mistakenly interprets the statement

ie (x) if (y) v; else w;

as an IF with an unexpected ELSE. The following patch fixes this bug. The patch affects pages 91 and 98 of the book. Later versions of the book and the source code archive already contain the patch.

--- t.t.old	2017-05-18 10:13:35.000000000 +0200
+++ t.t	2017-05-18 10:14:16.000000000 +0200
@@ -1217,7 +1217,7 @@
 	gen(CG_JMPFALSE, 0);
 	xrparen();
 	stmt();
-	ie (alt) do
+	if (alt) do
 		gen(CG_JUMPFWD, 0);
 		swap();
 		gen(CG_RESOLV, 0);
@@ -1225,9 +1225,6 @@
 		T := scan();
 		stmt();
 	end
-	else if (T = KELSE) do
-		aw("ELSE without IE", 0);
-	end
 	gen(CG_RESOLV, 0);
 end
 
@@ -1370,6 +1367,8 @@
 		if_stmt(1);
 	else ie (T = KIF)
 		if_stmt(0);
+	else ie (T = KELSE)
+		aw("ELSE without IE", 0);
 	else ie (T = KLEAVE)
 		leave_stmt();
 	else ie (T = KLOOP)
 

contact  |  privacy