以前作った整数のオートマトン、文字列"01"を受理するかどうかはさておき、"0"を受理しないのは問題だと思うので修正した。
class IntChecker : Checker { enum IntParsingState { Error, State0, State1, State2, State3, } IntParsingState _state; public IntChecker() { Reset(); } public void Reset() { _state = IntParsingState.State0; } public void Next(char ch) { switch (_state) { case IntParsingState.State0: if (ch == '-' || ch == '+') { _state = IntParsingState.State1; } else if (ch == '1' || ch == '2' || ch == '3' || ch == '4' || ch == '5' || ch == '6' || ch == '7' || ch == '8' || ch == '9') { _state = IntParsingState.State2; } else if (ch == '0') { _state = IntParsingState.State3; } else { _state = IntParsingState.Error; } break; case IntParsingState.State1: if (ch == '1' || ch == '2' || ch == '3' || ch == '4' || ch == '5' || ch == '6' || ch == '7' || ch == '8' || ch == '9') { _state = IntParsingState.State2; } else if (ch == '0') { _state = IntParsingState.State3; } else { _state = IntParsingState.Error; } break; case IntParsingState.State2: if (ch == '0' || ch == '1' || ch == '2' || ch == '3' || ch == '4' || ch == '5' || ch == '6' || ch == '7' || ch == '8' || ch == '9') { _state = IntParsingState.State2; } else { _state = IntParsingState.Error; } break; case IntParsingState.State3: case IntParsingState.Error: _state = IntParsingState.Error; break; } } public bool IsAcceptable() { return _state == IntParsingState.State2 || _state == IntParsingState.State3; } public bool IsError() { return _state == IntParsingState.Error; } }