mbutterick / brag

Racket DSL for generating parsers from BNF grammars [moved to https://git.matthewbutterick.com/mbutterick/brag]
https://git.matthewbutterick.com/mbutterick/brag
MIT License
61 stars 12 forks source link

Operator precedence #22

Closed thelonious closed 5 years ago

thelonious commented 5 years ago

I noticed this comment in the ragg docs:

ragg doesn’t currently have a good story about operator precedence. Future versions of ragg will support the specification of operator precedence to deal with grammar ambiguity...

I didn't see mention of this in the brag docs. I'm curious if this was addressed. I realize I can define precedence in my grammar's rules, but sometimes that approach negatively effects parse times.

mbutterick commented 5 years ago

The brag story about operator precedence is the same.

brag is basically a front end to cfg-parser, which I use because it handles a wider range of grammars than just parser. Though at the cost of a few features, including operator precedence and debugging (see #19)

In practice, I’ve never found this to be a shortcoming, since you can implement precedence by chaining parser rules (which arguably dovetails more nicely with Racket’s general orientation toward recursive reasoning over imperative reasoning).

That said, I’ve never run an A/B test between cfg-parser and parser to see whether recursion or precedence rules are faster. In general I would expect cfg-parser to be slower primarily because it’s more permissive.

thelonious commented 5 years ago

Thanks for the clarification. Performance is not a requirement for my current experimentation, but its good to know I have options later on down the road, if needed.