的Wikipedia文章PEG解析器定義了以下組合子:真正需要PEG解析器:是「必選」還是「一個或多個」規則?
2.Given any existing parsing expressions e, e1, and e2,
a new parsing expression can be constructed using the following operators:
Sequence: e1 e2
Ordered choice: e1/e2
Zero-or-more: e*
One-or-more: e+
Optional: e?
And-predicate: &e
Not-predicate: !e
是否所有這些組合子?這在我看來,可選和一個或更多的可以很容易地爲
e+ = e* & e
e? = e/""
難道我說錯此實現,還是有一些基本的東西,需要在這兩種形式是單獨的原子?我正在構建自己的PEG解析器,並且跳過這兩個(或者以其他組合器的形式定義它們)會很方便,但我想確保我不會錯過任何重要的東西。
對我來說很有意義。我認爲他們真的只是爲了方便,因爲他們很常見。 – 2013-04-27 02:01:41