Once an operator has been defined using the INFIX.. tokens in the parser.y grammar, how does that grammar handle the parsing of later occurrences of the operator symbol in order to get the precedence right? -- Does Hugs handle that internally (externally to the .y grammar)? Hans Aberg
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, and is no help at all when there are infinitely many precedence levels, like in Prolog (IIRC). Cheers, Sven
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
At 18:43 +0100 1-01-28, Sven Panne wrote:
[Hugs] 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 ... Note that "expanding out" the grammar w.r.t. fixity/precedence would lead to a *huge* parser, and is no help at all when there are infinitely many precedence levels, like in Prolog (IIRC).
Actually, the question came up on the Bison help list, somebody (novice to Bison) wanting to write an extensible grammar. At 12:52 -0500 1-01-28, Lennart Augustsson wrote:
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.
So I guess one can recommend starting with the simple one. Hans Aberg
participants (3)
-
Hans Aberg -
Lennart Augustsson -
Sven Panne