[mercury-users] moose and epsilon reductions

obo at ruk.cuni.cz obo at ruk.cuni.cz
Wed Dec 3 21:29:56 AEDT 2003


Hi.

(I know that currently there is hardly any support for the moose... But
however.)

How do I implement epsilon reductions in moose?

I've tried for instance:

:- rule possibly_empty_list_of_ints(list(int)).
possibly_empty_list_of_ints([]) ---> [].
possibly_empty_list_of_ints([H|T]) --->
  [int(H)],
  [possibly_empty_list_of_ints(T).

I'm really confused with what LALR parsers are able to handle. I expected
moose to analyze all the rules, collect all the epsilon reductions and
augment the rules so they actually check the forthcoming token and reduce
via the epsilon rule if the token is out of their interest already.

However, this doesn't work. The moose either compiles such a grammar with
epsilon reductions, but then issues "parse error" whenever the epsilon
reduction should occur, or the moose dies during compilation:

When I added the production:

factor(Num)     --->    [], { Num = 999 }.

to the alpha.moo in the samples (alpha.moo:line 34), the moose died:

hulot:samples$mmake try_alpha
../moose alpha.moo
constructing grammar...
constructing lr(0) items...
determining lookaheads...
        propagating...
computing the action table...
Uncaught Mercury exception:
Software Error: map__lookup: key not found
        Key Type: grammar.symbol
        Key Functor: terminal/1
        Value Type: list.list(lalr.item)
Stack dump not available in this grade.

Am I expecting too much from an LALR parser, or is moose weaker than LALR,
or is this just a bug in the algorithm of removing epsilon reductions?

I know I can rewrite the rule for possibly_empty_list_of_ints, so that it
requires at least one element. (This works fine.) But I indeed *do* need
to accept a blank list, too.

Thanks, O.

--
Ondrej Bojar (mailto:obo at cuni.cz)
http://www.cuni.cz/~obo


--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list