首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PetitParser不是分布式的吗?

PetitParser不是分布式的吗?
EN

Stack Overflow用户
提问于 2013-03-20 22:23:35
回答 1查看 69关注 0票数 2

PetitParser中的规则是分布性的吗?

接下来的规则是:

代码语言:javascript
复制
integerLiteral --> hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral
  hexIntegerLiteral     --> hexNumeral , (integerTypeSuffix optional)
  octalIntegerLiteral   --> octalNumeral , (integerTypeSuffix optional)
  decimalIntegerLiteral --> decimalNumeral , (integerTypeSuffix optional)

如果我将它们更改为:

代码语言:javascript
复制
integerLiteral --> (hexIntegerLiteral / octalIntegerLiteral / decimalIntegerLiteral) , (integerTypeSuffix optional)
  hexIntegerLiteral     --> hexNumeral
  octalIntegerLiteral   --> octalNumeral
  decimalIntegerLiteral --> decimalNumeral

则不再对0777L进行解析。它应该与octalNumeral , (integerTypeSuffix optional)或新版本的octalIntegerLiteral , (integerTypeSuffix optional)匹配,但这并没有发生。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-03-20 23:21:29

是的,PetitParser中的有序选择是分布式的。在您的示例中缺少一些上下文,所以我不知道为什么它不适用于您。

PetitParser优化器会自动执行您建议的更改。重写规则(以更一般的形式)定义为:

代码语言:javascript
复制
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
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15526239

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档