【问题标题】:It is possible to write NQP's precedence parser in Raku可以在 Raku 中编写 NQP 的优先级解析器
【发布时间】:2020-07-19 15:26:51
【问题描述】:

我正在尝试弄清楚如何在 Raku 中重写 NQP 的优先级解析器:

优先级解析器在这里实现:https://github.com/Raku/nqp/blob/master/src/HLL/Grammar.nqp#L384 NQP 应该是 Raku 的一个子集,但语法部分似乎是专门的。

如果我想改写 Raku 中 EXPR() 中的优先级解析器, Raku 语法原语是什么? IE。 cursor_start_cur() 会翻译成什么? Raku 语法中有cursor 吗?如何设置 Raku Match 对象的pos$termcur.MATCH() 会翻译成什么等等...

我不是在寻找编写优先解析器的不同方法, 而是想知道在 Raku 中是否可以像 NQP 那样做。

【问题讨论】:

    标签: grammar raku nqp


    【解决方案1】:

    jnthn 在 IRC 中写道:

    rule EXPR { <termish> [<infix> <termish>]* } 
    token termish { <prefix>* <term> <postfix>* }
    

    然后在 action 方法中进行优先排序。

    https://www.apress.com/us/book/9781484232279 一书中有一个示例https://github.com/Apress/perl-6-regexes-and-grammars/blob/master/chapter-13-case-studies/operator-precedence-parser-class.p6 实现了相同的结构。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-16
      • 2018-04-12
      • 1970-01-01
      • 1970-01-01
      • 2014-09-25
      • 2015-07-09
      • 1970-01-01
      相关资源
      最近更新 更多