Florian Obser([email protected]) on 2021.09.03 11:32:42 +0200:
> On 2021-09-03 10:38 +02, Claudio Jeker <[email protected]> wrote:
> > On Fri, Sep 03, 2021 at 10:12:57AM +0200, Sebastian Benoit wrote:
> >> Tobias Heider([email protected]) on 2021.09.02 15:39:46 +0200:
> >> > +                ;
> >> > +
> >> > +proto_list      : protoval                      { $$ = $1; }
> >> > +                | proto_list comma protoval     {
> >> > +                        if ($3 == NULL)
> >> > +                                $$ = $1;
> >> > +                        else if ($1 == NULL)
> >> > +                                $$ = $3;
> >> > +                        else {
> >> > +                                $1->tail->next = $3;
> >> > +                                $1->tail = $3->tail;
> >> > +                                $$ = $1;
> >> > +                        }
> >> > +                }
> >> 
> >> why dont you make it 
> >> 
> >>            | protoval comma proto_list     {
> >> 
> >> then you dont need the conditional.
> >
> > AFAIK yacc rules should be left expand. I don't fully remember the reason
> > but your example is not the common way.
> 
> because the parser itself is left recursive. If you make your grammar
> right recursive the parser needs to build a stack. Which is slower and
> possibly can overflow.

yes, but that does not really matter in such a short case. If the parser is
able to help you put your data structure together, why not let it help.

Reply via email to