help-bison
[Top][All Lists]
Advanced

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

Re: How to change default outcome of shift/reduce conflict?


From: Hans Aberg
Subject: Re: How to change default outcome of shift/reduce conflict?
Date: Sun, 13 Jan 2002 13:46:52 +0100

At 09:22 +0100 2002/01/13, Akim Demaille wrote:
>There's a guy on this list named Hans that suggested to transform the
>grammar.  I agree he didn't use the word, but for his information, his
>suggestion named `grammar transformation' by people working on grammars.

The grammars I suggested generates different languages. -- I think one
should look into the question why the grammar is ambigous and what the
correct semantics should be before charging ahead with quick fixes.

>>> and you will even loose performances.
>
>Hans> What performance loss do you have in your mind?
>
>The size of the automaton.  Using precedence directives is more
>efficient than additional rules and nonterminals.  But see the books,
>or simply what I already posted several times, I'm not here to give a
>lecture.

Provided one introduces more rules with more actions to execute, even
though that probably does not make much difference in practise.

>>> Just as nobody would ever program a expr/term/factor grammar for
>>> arithmetics in LR,
...
>Hans> Of, course, the question is why?
>
>Err, are you kidding?  Have you ever implemented the idea you just
>suggested?  Do you really enjoy having additional nonterminals,
>artificial rules, just to see Bison accept your grammar?  Are you
>giving advice on something you don't practice?  Your suggestion is the
>_last_ resort, that's why the documentation shows it: sometimes you
>_have_ to.
>
>_And_ it produces a less efficient parser, as was written right above.

I think that one first should try to find a correct solution. Then the pro,
after doing some profiling, can go in optimizing the parts where it is
needed.

Usually, not much time is spent in the parser, so the extra time for
default rules should not make much difference. Nor, is space typically very
critical in modern computers.

By contrast, using a Bison/Flex combination allows one to do
experimentation with the grammar, which is great benefit also in simple
programs, like calculators and such. Then, when the grammar has been
properly fixed and pinned down, one can spend time on doing optimizations.

  Hans Aberg





reply via email to

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