It is possible to write NQP's precedence parser in Raku
Asked Answered
C

1

5

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.

Colorist answered 19/7, 2020 at 15:26 Comment(0)
C
6

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.

Colorist answered 21/7, 2020 at 19:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.