fool2fish / dragon-book-exercise-answers

Compilers Principles, Techniques, & Tools (purple dragon book) second edition exercise answers. 编译原理(紫龙书)第2版习题答案。
6.37k stars 1.77k forks source link

Solution Not Correct Exercise 6.4.1 #86

Open sammyrocz opened 8 years ago

sammyrocz commented 8 years ago

The solution of 6.4.1 part b) given in the repo is wrong

Your Answer E -> E1 * E2 { E.addr = new Temp(); E.code = E1.code || E2.code || gen(E.addr '=' E1.addr '*' E2.addr); }

| +E1 { E.addr = E1.addr; E.code = E1.code; }

But if you refer the book ( pg 381) The translation should be

E -> E1 * E2 { E.addr = new Temp(); E.code = E1.code || E2.code || gen(E.addr '=' E1.addr '*' E2.addr); }

| +E1 { E.addr = new Temp(); E.code = E1.code || gen(E.addr '=''plus'E1.addr) ; }

The same goes for 6.4.2 (the incremental one)