[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: 3.3 Grammar Rules Issues

From: Domingo Alvarez Duarte
Subject: Re: 3.3 Grammar Rules Issues
Date: Sun, 12 Jun 2022 07:23:47 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1

Hello Kaz !

There is this tool https://www.bottlecaps.de/convert/ where we can paste the bison/yacc grammar and then click/press the "Convert" button and then click/press ""View Diagram" to see a navigable railroad diagram (https://en.wikipedia.org/wiki/Syntax_diagram).

I just tested it with the grammar from bison 3.8.2 and we need to remove everything from the top till "%token" for it to work.

I'm adding the author of that tool too so probably he can fix it to properly parse the full grammar (that evolves from version to version).

Cheers !

On 12/6/22 2:25, Kaz Kylheku wrote:
On 2022-06-11 13:38, slipbits wrote:
You nowhere define the syntax and grammar of Bison in one place.
Ah, but that is only the case if we are talking strictly about
documentation. There is a grammar of Bison given in Bison
in the source tree:


So the good news is that the grammar is formally specified
as a grammar.

Maybe a document version of this could be automatically extracted
from the source via some text processing or something.

How about: add a grammar pretty-printing facility into Bison itself,
and that can then be applied to the file to geenrate a version that
is pulled into the document.

Now there is a form of pretty-printing in Bison: it can produce
a report file ("y.output" in Yacc mode).

This y.output contains a listing of all the rules, without the
actions, reformatted.  The grammar could perhaps be text-scraped
out of that file, or some additional knobs could be implemented to
bend that reporting feature into pretty-printing.

There might be hacks in the grammar though to resolve ambiguities.
There is a famous ambiguity in the Yacc grammar involving the
terminating semicolon of a rule, which is actually optional.

So that is to say, this is a valid grammar fragment, without
the semicolon terminating either rule:

   a : b
     | c

   d : e

The "d" is interpreted as the left nonterminal of a new rule, rather
than a continuation of the a : c rule.

That sort of thing needs explaining, if it happens not to follow
from the grammar alone, but some tricks are used.

It is very important that all syntax and grammar rules be defined,
and equally important that definition be aggregated and complete,
and put into an accessible location. The scatter-shot revelation of
grammar and syntax should be avoided.
A subset of Bison conforms to the POSIX Yacc specification. POSIX does
have a Yacc grammar all in one place, expressed in Yacc.

See the "Input Grammar" section here:


But of course that grammar has no actions and other clutter.

Cheers ...

reply via email to

[Prev in Thread] Current Thread [Next in Thread]