[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
x + (y) + z
From: |
Derek M Jones |
Subject: |
x + (y) + z |
Date: |
Thu, 03 Mar 2005 20:41:36 +0000 |
All,
The statement (y)+z can be parsed as casting
+z to the type y, or as adding y to z. A couple of
%dprecs solve this problem (I think the cast is the
common case for - and a binary expression for +).
However, things are more complicated for x + (y) + z,
whose parse tree can be either
+
/ \
x ( )
/ \
y +
|
z
or
+
/ \
+ z
/ \
x (y)
As currently implemented the %dprec functionality does
not appear to be any help here. Effectively, it will only
select between two productions that consume the same
number of input tokens.
At the moment the only solution I can think of is to change
the grammar for additive-expressions from left recursive to
right recursive, ie from
add-expr:
mul-expr |
add-expr '+' mult-expr |
add-expr '-' mult-expr ;
to
add-expr:
mul-expr |
mult-expr '+' add-expr |
mult-expr '-' add-expr ;
I don't like rewriting grammar like this and I'm sure
more complicated cases will arise (I know there are
other operators that need to be handled for this example).
What is needed is a get-out-of-ambiguity option.
The %gooa option would take a single argument which
specified the weight of a production. When two or
more ambiguous parses are encountered the weights
of the various productions involved would be added
up and the one with the greatest weight selected.
derek
--
Derek M Jones tel: +44 (0) 1252 520
667
Knowledge Software Ltd mailto:address@hidden
Applications Standards Conformance Testing http://www.knosof.co.uk
- Re: Forcing multiple parse stacks to 'reduce', Laurence Finston, 2005/03/01
- Re: Forcing multiple parse stacks to 'reduce', Derek M Jones, 2005/03/01
- Re: Forcing multiple parse stacks to 'reduce', Hans Aberg, 2005/03/01
- Re: Forcing multiple parse stacks to 'reduce', Hans Aberg, 2005/03/01
- Re: Forcing multiple parse stacks to 'reduce', Derek M Jones, 2005/03/02
- Re: x + (y) + z, Frank Heckenbach, 2005/03/03
- Re: x + (y) + z, Derek M Jones, 2005/03/04
- Re: x + (y) + z, Frank Heckenbach, 2005/03/04
- Message not available
- Re: x + (y) + z, Frank Heckenbach, 2005/03/06
- Re: x + (y) + z, Derek M Jones, 2005/03/06
- Re: x + (y) + z, Kelly Leahy, 2005/03/04