Re: [dev] miniyacc

From: Daniel Cegiełka <daniel.cegielka_AT_gmail.com>
Date: Wed, 8 May 2019 18:14:11 +0200

Michael,

Thx a lot for your research!

My summary:
OpenBSD's yacc
* works correctly
* based on byacc: https://invisible-island.net/byacc/byacc.html

Plan 9's yacc
* utf
* should be used with -S flag (for unix like)
* usually works, but has some problems:
https://github.com/gittup/binutils/blob/gittup/ld/ldgram.y#L1120

miniyacc
* output code is optimized for low memory usage and small binary size
* a piece of beautiful code, but it doesn't work very often:
  • "={"
  • missing semicolon
  • lack of {% and %} which is quite common (license):
https://github.com/openbsd/src/blob/master/usr.bin/awk/awkgram.y
  • doesn't seem to handle escape sequences in literals ('\n')
  • I don't even know what else:
https://github.com/9fans/plan9port/blob/master/src/cmd/hoc/hoc.y#L32

miniyacc looks really very promising, unfortunately since 2015 isn't
actively developed:
https://c9x.me/git/miniyacc.git/log/

mpu devotes most of his time to developing qbe.

Daniel


śr., 8 maj 2019 o 10:36 Michael Forney
>
> On 2019-05-07, Daniel Cegiełka
> > Hi,
> >
> > I'm going to use Quentin's miniyacc with (for example) bc.y from Plan 9:
> > https://github.com/9fans/plan9port/blob/master/src/cmd/bc.y
> >
> > Of course, I had to modify the code (a bit), but unfortunately I still
> > get an error when using miniyacc - works correctly with yacc from
> > OpenBSD and Plan 9.
> >
> > I'm getting a message from this place ("production rule too long"):
> > https://c9x.me/git/miniyacc.git/tree/yacc.c#n1110
> >
> > I tried to increase the value of IdntSz and MaxRhs, but it didn't help
> > in any way.
>
> It looks like this error is caused when miniyacc encounters a
> character that it doesn't recognize as a token. nexttk() returns a
> zero-length TIdnt token, causing an infinite loop, filling up r->rhs.
>
> Try the attached patch, which makes it fail on invalid tokens.
>
> In the example bc.y you linked, I think the '={' is causing problems,
> and is from an obsolete yacc syntax:
>
> Some implementations recognize "={" as equivalent to '{' because it
> appears in historical documentation. This construction was recognized
> and documented as obsolete as long ago as 1978, in the referenced
> Yacc: Yet Another Compiler-Compiler. This volume of POSIX.1-2017 chose
> to leave it as obsolete and omit it.
>
> I also ran into this problem on some other grammar files containing
> comments. One other issue I noticed is miniyacc doesn't seem to handle
> escape sequences in literals (i.e. '\n').
>
> After working around those issues, I get a different error
>
> $n has no type (on line 171)
>
> I think this is due to the usage of $2 referring to a token (EQOP in
> this case) rather than a non-terminal. I haven't investigated this
> further.
Received on Wed May 08 2019 - 18:14:11 CEST

This archive was generated by hypermail 2.3.0 : Wed May 08 2019 - 18:24:08 CEST