EBNFを使用して形式文法、特にスペースで区切られた一連の単語を定義する方法を理解しようとしています。
<non-terminal> [<word>[ <word>[ <word>[ ...]]] <non-terminal>
- ワードターミナルを定義する正しい方法は何ですか?
- 必要な空白を表す正しい方法は何ですか?
- オプションの反復リストはどのように表されますか?
- EBNFに関する実例を示すチュートリアルはどこかにありますか?
よろしくお願いします!
You have to decide whether your lexical analyzer is going to return a token (terminal) for the spaces. You also have to decide how it (the lexical analyzer) is going to define words, or whether your grammar is going to do that (in which case, what is the lexical analyzer going to return as terminals?).
For the rest, it is mostly a question of understanding the niceties of EBNF notation, which is an ISO standard (ISO 14977:1996 — and it is available as a free download from Freely Available Standards, which you can also get to from ISO), but it is a standard that is largely ignored in practice. (The languages I deal with — C, C++, SQL — use a BNF notation in the defining documents, but it is not EBNF in any of them.)
P. J. O'Neill
, for example. What tokens will the lexical analyzer return for that?{
and }
braces, or you can use the Kleene Star notation.I think that a non-empty, space-separated word list might be defined using:
non_empty_word_list = word { space word }
where all the names there are non-terminals. You'd need to define those in terms of the relevant terminals of your system.