[libre-riscv-dev] parser precedence, code review / checking needed

Jacob Lifshay programmerjake at gmail.com
Fri Apr 3 21:08:18 BST 2020


On Fri, Apr 3, 2020 at 11:50 AM Luke Kenneth Casson Leighton
<lkcl at lkcl.net> wrote:
>
> On Fri, Apr 3, 2020 at 7:23 PM Jacob Lifshay <programmerjake at gmail.com> wrote:
> >
> > On Fri, Apr 3, 2020, 08:20 Luke Kenneth Casson Leighton <lkcl at lkcl.net>
> > wrote:
> >
> > > if anyone knows how to resolve operator precedence, my logic-dyslexia
> > > is kicking in and i am having difficulty working out which operators
> > > are supposed to be in which order, for bit-wise AND, OR, and
> > > PLUS/MINUS, MUL/DIV.  someone else did the PLUS/MINUS MUL/DIV, i'm
> > > attempting to add AND and OR and am getting it wrong
> > >
> >
> > The way I always did it is by changing the grammar to have one non-terminal
> > symbol per precedence level. Example code from my LR(1) parser generator:
> > https://github.com/programmerjake/parser-generator/blob/master/test.parser#L108-L120
>
> ply has something called "precedence" which is a list-of-tuples that
> helps resolve parser ambiguities.

Just because something has a feature, doesn't mean that it's the best
way to do it.

As far as I can tell, it's working now.

Jacob



More information about the libre-riscv-dev mailing list