help-bison
[Top][All Lists]
Advanced

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

Re: problems with absolute value structure in algebraic grammar


From: Frank Heckenbach
Subject: Re: problems with absolute value structure in algebraic grammar
Date: Sun, 22 Jun 2003 01:45:39 +0200

Samad Lotia wrote:

> The purpose of this grammar file is to produce a
> parser which can parse algebraic expressions. The
> purpose of the enclosed_statements rule is to support
> implicit multiplication. For example, the expression:
> 
> 9acos(0.5)
> 
> Really means:
> 
> 9*acos(0.5)
> 
> Or the expression:
> 
> 8|-2|(2^3)
> 
> Really means:
> 
> 8*abs(-2)*(2^3)
> 
> 
> When bison parses this grammar file, it reports a
> shift/reduce conflict at line 22. It, for some reason,
> cannot accept rules like this:
> enclosed_statement: (a_token) statement (same_token)

Your language is ambiguous:

  2|3|4|5|6

could mean

  2 * abs (3 * abs (4) * 5) * 6

or

  2 * abs (3) * 4 * abs (5) * 6

Since the ambiguity is in the language, not the grammar, no amount
of rearranging the grammar or using precedence will save it, unless
you want to make additional restrictions, such as no nested ||
except in () ...

Frank

-- 
Frank Heckenbach, address@hidden
http://fjf.gnu.de/
GnuPG and PGP keys: http://fjf.gnu.de/plan (7977168E)




reply via email to

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