On 07/31/2012 05:54 PM, Grzegorz Milka wrote:
> I decided to use ply to implement assembler from "Elements of computer
> systems" and in the process I noticed an unexpected behaviour (error
> on someone's part) on something that in my opinion looks ok.
The example code has a shift/reduce error which means your grammr is too complicted for the LALR(1)
algroithm to handle. It does the best it can, but some paths in the grammar are dropped. When you
try to use those paths, the input is not recognized.
This is not a bug. It is a trade-off between simplicity and speed of the implementation versus
acceptable expression power in the grammar (the algorithm is around 20-25 years old).
(It may also be the case that the dropped paths never happens in actual input. In such cases the
generated parser is still usable. this is why you do get a parser even with a grammar that falls
outside the limits of the LALR(1) algorithm. You should however verify that the shift/reduce
conflict does not drop paths that can occur in actual input.)
You have to eliminate the shift/recude conflict first (ie make the grammar fit within the limits of
the LALR(1) algorithm) before you can be sure every path in the grammar is considered.