5

我试图弄清楚如何在 Raku 中重写 NQP 的 Precedence Parser:

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

如果我想改写 Raku 中 EXPR() 中的优先级解析器,那么要使用什么 Raku 语法原语?即什么会cursor_start_cur()翻译成?cursorRaku 语法中有 a吗?如何设置posRaku Match 对象?会 $termcur.MATCH()翻译成什么等等...

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

4

1 回答 1

6

jnthn在 IRC 中写道:

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

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

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

于 2020-07-21T19:49:23.043 回答