


















<p>When I was a teenager, I wrote a <a href="https://hachyderm.io/tags/Forth" class="mention hashtag" rel="tag">#<span>Forth</span></a> compiler, running on the BBC Micros we had at school. It had a code generation bug, which I didn't find until 20 years later.</p><p>It was very much in "Baby's First Compiler" style: completely trivial unoptimised code generation, as close as possible to just reading the source file and emitting a fixed fragment of machine code per word, with only control structures like IF/THEN and function definitions requiring anything more complicated.</p><p>I'd chosen Forth in the first place, of course, for the same reason: it requires the least complicated parsing, so it's suitable for a first compiler. I had _read_ about LR and recursive descent parsing, but didn't fancy attempting either one in 6502 machine code. (Not even if I used lex and yacc on some other machine to generate automata and imported them on to the Beeb.)</p><p>So how did a compiler that simple manage to have a bug?</p><p>(1/2)</p>
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。