単純なマーク付けがなされた文字列の解析 #1
語を括弧で括ってマーク付けした英文を解析することを考える。
例えば、次の例では、
The quick brown (fox) jumps over the lazy (dog).
foxとdogがマーク付けされている。
問題をほんの少し厳密にするためにBNFで記述する。
<text> ::= <string-headed> | <marked-string-headed> <string-headed> ::= <string> | <string> <marked-string-headed> <marked-string-headed> ::= <marked-string> | <marked-string> <marked-string-headed> | <marked-string> <string-headed> <marked-string> ::= "(" <marked-string-body> ")" <string> ::= <char-except-parenthesis> | <string> <char-except-parenthesis> <marked-string-body> ::= <char-except-parenthesis> | <marked-string-body> <char-except-parenthesis>
"("は左括弧、")"は右括弧、<char-except-parenthesis>
は括弧以外の文字をそれぞれ表す終端記号である。
それ以外は非終端記号であり、このうち、<text>
が開始記号である。
これを解析するとは、<text>
として受容されるものを入力として、<string>
と<marked-string-body>
を区別してこれを出力することとする。
おまけにすごく雑把で適当な遷移図。