2

PetitParser のルールは分散型ですか?

次のルールがありました。

integerLiteral --> hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral
  hexIntegerLiteral     --> hexNumeral , (integerTypeSuffix optional)
  octalIntegerLiteral   --> octalNumeral , (integerTypeSuffix optional)
  decimalIntegerLiteral --> decimalNumeral , (integerTypeSuffix optional)

それらを次のように変更した場合:

integerLiteral --> (hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral) , (integerTypeSuffix optional)
  hexIntegerLiteral     --> hexNumeral
  octalIntegerLiteral   --> octalNumeral
  decimalIntegerLiteral --> decimalNumeral

その後0777Lは解析されません。一致octalNumeral , (integerTypeSuffix optional)するか、新しいバージョンである必要octalIntegerLiteral , (integerTypeSuffix optional)がありますが、それは起こっていません。

4

1 に答える 1

3

はい、PetitParser の順序選択は分配的です。あなたの例では、いくつかのコンテキストが欠落しているため、なぜうまくいかないのかわかりません。

PetitParser オプティマイザは、提案された変更を自動的に行います。書き換え規則 (もう少し一般的な形で) は次のように定義されます。

PPOptimizer>>#postfixChoice
    <optimize>

    | before prefix body1 body2 postfix after |
    before := PPListPattern any.
    prefix := PPPattern any.
    body1 := PPListPattern any.
    body2 := PPListPattern any.
    postfix := PPPattern any.
    after := PPListPattern any.
    rewriter
        replace: before / (prefix , body1) / (prefix , body2) / after
        with: before / (prefix , (body1 / body2)) / after.
    rewriter
        replace: before / (body1 , postfix) / (body2 , postfix) / after
        with: before / ((body1 / body2) , postfix) / after
于 2013-03-20T15:21:28.643 に答える