我不明白拉格尔认为什么是“最终”状态。IIRC,用户指南说,在机器简化之前是最终的状态在之后仍然是最终的。什么时候是州决赛,人们如何认识到这一点?
应用程序:
我使用状态机语法来实现字符串查找器--查找长度大于n的ASCII字符串,并打印它们。这意味着实现最大长度匹配器,如下所示。
尽管点输出没有显示最终状态,但依使用{$%@}eof的口味而定,EOF转换的行为有所不同。我不明白为何要这样做。例如,在下面的has_string状态中,使用%eof而不是@eof将从终止匹配状态的生成/合成状态之一调用commit_nonstring_eof和commit_string_eof操作。
这是一个工作状态机。注意,最右边的节点退出操作正好有一个操作:commit_nonstring_eof。

这是一台故障状态机。注意,最右边的节点退出操作同时调用commit_string_eof和commit_nonstring_eof。

action commit_string { }
action commit_string_eof { }
action commit_nonstring_eof { }
action set_mark { }
action reset {
/* Force the machine back into state 1. This happens after
* an incomplete match when some graphical characters are
* consumed, but not enough for use to keep the string. */
fgoto start;
}
# Matching classes union to 0x00 .. 0xFF
graphic = (0x09 | 0x20 .. 0x7E);
non_graphic = (0x00 .. 0x08 | 0x0A .. 0x1F | 0x7F .. 0xFF);
collector = (
start: (
# Set the mark if we have a graphic character,
# otherwise go to non_graphic state and consume input
graphic @set_mark -> has_glyph |
non_graphic -> no_glyph
) $eof(commit_nonstring_eof),
no_glyph: (
# Consume input until a graphic character is encountered
non_graphic -> no_glyph |
graphic @set_mark -> has_glyph
) $eof(commit_nonstring_eof),
has_glyph: (
# We already matched one graphic character to get here
# from start or no_glyph. Try to match N-1 before allowing
# the string to be committed. If we don't get to N-1,
# drop back to the start state
graphic{3} $lerr(reset) -> has_string
) @eof(commit_nonstring_eof),
has_string: (
# Already consumed our quota of N graphic characters;
# consume input until we run out of graphic characters
# then reset the machine. All exiting edges should commit
# the string. We differentiate between exiting on a non-graphic
# input that shouldn't be added to the string and exiting
# on a (graphic) EOF that should be added.
graphic* non_graphic -> start
) %from(commit_string) @eof(commit_string_eof) // okay
#) %from(commit_string) %eof(commit_string_eof) // bad
); #$debug;
main := (collector)+;发布于 2013-10-22 23:37:41
我认为,对于连接的机器a.b,当从a过渡到b的第一个字符时,a会发生最后的状态。(请参阅手册中的“常规语言运算符/连接”)。
尽管点输出没有显示最终状态
点输出显示了许多最终状态。例如,从7到6的过渡使7最终。从6到1的过渡使6最终,依此类推。
https://stackoverflow.com/questions/17848941
复制相似问题