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

There is a bug in ch03/3.4/src/failure-function.js

vskyman opened this issue · comments

Thanks for your sharing!

Look at the corner case:
input the string: "a a a b"
output "0 1 2 1"
should be "0 1 2 0"
----original------
if(str[j] == str[i]){
j++
}
failure[i] = j
-----change to-------
if(str[j] == str[i]){
j++
failure[i] = j
} else {
failure[i] = 0
}

Your codes are right.