[Top][All Lists]

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

Re: 3.3 Grammar Rules Issues

From: Kaz Kylheku
Subject: Re: 3.3 Grammar Rules Issues
Date: Sat, 11 Jun 2022 17:25:49 -0700
User-agent: Roundcube Webmail/1.4.13

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]