help-bison
[Top][All Lists]
Advanced

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

Reducing conflict: Was: Exceeded limits of %dprec/%merge?


From: Derek M Jones
Subject: Reducing conflict: Was: Exceeded limits of %dprec/%merge?
Date: Fri, 19 May 2006 15:50:24 +0100
User-agent: Thunderbird 1.5 (Windows/20051201)

Joel,

> In the meantime, it might be worthwhile to work out the exact
> functionality you envision by discussing it on this list.  Once you (or
> someone else who gets interested) is ready to write it, it will then stand
> a better chance of being accepted -- and being accepted without an
> extensive rewrite.

The following discussion is C (and C++) syntax specific.

Most of the conflicts occur because it is not known whether an
identifier is an identifier or a typedef-name.  Grammars that
treat these as two separate tokens (all except mine as far as
I know) use a symbol table to make this decision.

In some contexts the semantics tell us that an identifier
must be an identifier, even though the syntax permits it
to be a typedef-name.  For instance, given the input:

id1 id2;

then semantically id2 can only be an identifier, id1 must
be a typedef-name or we have a syntax error.  The grammar
allows both to be a typedef-name.

In other contexts it is often possible to make a judgment
based on probabilities (inside a function prototype a
typedef-name is more likely, outside an identifier is more
likely; as least I think so until my figures show otherwise;
which they cannot until I have have access to both parse
trees when an ambiguity occurs).

One possible solution would be to allow the grammar writer to
specify weights for a particular reduction.  When a conflict
occurred the one with the greatest weight would be chosen.

Preferably these weights could change as the parse progressed.
Using the above example, both id1 and id2 would both initially
be given the same is_identifier weight.  However, when reduced
thorough declaration_specifier_list the weights would be changed
to reflect the fact that the extra information (two ids in sequence)
indicates that one is a typedef-name and the other an identifier.

I'm not sure how practical this might be in practice.  I think I
prefer the ability to resolve the conflict with a
my_reportAmbiguity function.

--
Derek M. Jones                              tel: +44 (0) 1252 520 667
Knowledge Software Ltd                      mailto:address@hidden
Applications Standards Conformance Testing    http://www.knosof.co.uk




reply via email to

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