fool2fish / dragon-book-exercise-answers

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Solution for 3.3.5-(4) is wrong

sivaraam opened this issue · comments

One could easily see that it accepts the strings like 1010 which has 1 and 0 repeated. The given solution seems to be accepting the language of strings of {0,1,2} that do not have consecutively the same digit.

Note : In general a solution that has Kleene closure or positive closure cannot be an answer to the question.

So, I guess #111 is also wrong as a result of this.

Thanks, I was wondering the same thing. I am not sure of any other solution besides enumeration. To make it less verbose, I have the following:

Define '{}' to indicate a set, 'Nonrepeat' to be a function that takes a set of digits and returns a regular expression, 'digits' to be a set of subset of digits (e.g. { 1, 2, 3}), 'U' to be the union operation, '||' to be cardinality, 'e' to be the empty set, and '\' to be the set complement operator.

Then have the following rules to express all strings of nonrepeating digits:


Nonrepeat(digits) -> e when |digits|=0

else

Nonrepeat(digits) -> U[d in digits] d ( Nonrepeat(digits \ {d}))