I'm trying to figure out how I can rewrite NQP's Precedence Parser in Raku :
The Precedence Parser is implemented here: https://github.com/Raku/nqp/blob/master/src/HLL/Grammar.nqp#L384 NQP should be a subset of Raku but the Grammar part seems to be specialized.
If I want to rewrite the Precedence Parser in EXPR() in Raku instead,
what would be the Raku Grammar primitives to use?
I.e. What would cursor_start_cur()
translate to? is there a cursor
in a Raku Grammar? How can I set pos
of a Raku Match object ? What would $termcur.MATCH()
translate to, etc...
I am not searching for different ways of writing a Precedence Parser, but rather want to know whether it can be done in Raku in the same way that NQP does it.
Operator precedence parsers use precedence functions that map terminal symbols to integers, and the precedence relations between the symbols are implemented by numerical comparison. The parsing table can be encoded by two precedence functions f and g that map terminal symbols to integers.
A grammar is said to be operator precedence grammar if it has two properties: No R.H.S. of any production has a∈. No two non-terminals are adjacent.
jnthn
wrote in IRC:
rule EXPR { <termish> [<infix> <termish>]* }
token termish { <prefix>* <term> <postfix>* }
and then done the precedence sorting in an action method.
There is an example https://github.com/Apress/perl-6-regexes-and-grammars/blob/master/chapter-13-case-studies/operator-precedence-parser-class.p6 from the book https://www.apress.com/us/book/9781484232279 that implement the same structure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With