Master

Debugging a compiler that is wrong

A compiler that is wrong is wrong at one pass. The passes are the places, and the places are the reason a wrong answer is a question rather than a hunt.

What you will see

fix refused. One case fixed is not the whole suite, which is the gate.

About 1 min of reading

Try It

Find the first wrong pass

1

Print after three passes

printf 'parse ok\ncheck ok\nfold wrong\n' > /tmp/w.txt; grep -n wrong /tmp/w.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
3:fold wrong. The first wrong print names the pass, which is the place.
2

Name the rule

printf 'pass=fold rule=add-num-num fix=shape-order\n' > /tmp/f.txt; cat /tmp/f.txt

Before you run it, say out loud what it will print. Then open the answer.

What it prints
One line with a rule. The rule is the file, which is the fix.
3

Refuse a one-case fix

printf 'suite pass=11 fail=1\n' | awk '{print ($2=="fail=0") ? "fix accepted" : "fix refused"}'

Before you run it, say out loud what it will print. Then open the answer.

What it prints
fix refused. One case fixed is not the whole suite, which is the gate.

Data Flow

A wrong answer to one place
1 The tree is printed after each pass
↓
2 The first wrong print names a pass
↓
3 The pass names a rule or an instruction
↓
4 The fix must pass the whole suite
Why this works
Why the prints are kept in a run

The prints are the record. A record with every pass is a record that names one place rather than a guess.

The suite is the last question

A fix must pass every pair. The pairs include the bad ones, so a fix that fixes one case is refused.

Examples

The first question is which pass

The tree is printed after each pass. A print after each pass is a list of answers, and one of them is the first wrong one.

The rule is the second question

A wrong tree names a rule. The rule is the file, and the file is the fix rather than the code.

The instruction is the third

A wrong run names an instruction. The instruction is a line, and the line is where the generator is wrong.

Words this lesson uses

Each one is defined here on this site. Open the entry for the full definition and the other words it points at.

← Generating code instead of answering
Previous Lesson
Generating code instead of answering
Next Lesson
Shipping a compiler that is bounded
Shipping a compiler that is bounded →