.y & precedence

Lennart Augustsson lennart@mail.augustsson.net
Sun, 28 Jan 2001 12:52:15 -0500


Sven Panne wrote:

> Hans Aberg wrote:
> > [...] Does Hugs handle that [ i.e. infix & friends ] internally
> > (externally to the .y grammar)?
>
> That's correct, IIRC. It uses the standard technique here:
>
>    * Remember fixity/precedence declarations in a table, but ignore them
>      during pattern/expression parsing
>
>    * A simple operator precedence parser rearranges the expression/pattern
>      part of the parse tree afterwards, using the collected table
>
> This is only from the top of my head, so I may be wrong, but given the
> inflexibility of yacc & friends in this respect, I doubt there is a
> fundamentally different way of doing this.
>
> Note that "expanding out" the grammar w.r.t. fixity/precedence would
> lead to a *huge* parser,

It's not that bad.  Hbc uses the expanded grammar.  It's very easy to write
with yacc, and the tables are not that big.  (But I doubt you can actually
parse Haskell to the letter of what the report says using this technique.
But nobody does that anyway since it's practically infeasible.)


> and is no help at all when there are
> infinitely many precedence levels, like in Prolog (IIRC).

Prolog has a 1000 levels (IIRC).

    -- Lennart