views:

172

answers:

2

Here is a piece of my bnf grammer.

//this works
<ter-stmnt>  ::= <rval> '?' <rval> ':' <rval>
//this gets an error
<ter-stmnt>  ::= <bool-val> '?' <rval> ':' <rval>
<bool-val>   ::= <rval>

This seems insane, shouldnt the second be EXACTLY the same as the first? i prefer the second bc when reading i see that i expect a bool value as oppose to the generic rval which can mean anything.

I am using Gold Parser 3.4.4

A: 

What error do you get? Can you include your whole grammar file? I don't get any error if I declare rules like ...

<ter-stmnt>  ::= <bool-val> '?' <rval> ':' <rval>
<bool-val>   ::= <rval>
<rval>  ::= '!'
ChrisW
Its propriety but i the current grammar doesn't have anything thats not in C++ so send me an email(you can find it in my profile) and i'll send you the grammar and some test files.
acidzombie24
+2  A: 

The error that you're getting is:

Reduce-Reduce Conflict
'?' can follow more than one completed rule. A Reduce-Reduce error is a caused when a grammar allows two or more rules to be reduced at the same time, for the same token. The grammar is ambigious. Please see the documentation for more information.

It's saying that after it's evaluated some tokens, it's unable to decide whether it's just read a <bool-val> or whether it read an <rval>.

To make more sense your grammar ought to say what a <bool-val> is, specifically, and then say that an <rval> is a <bool-val> or other things.

Here's another example of a reduce/reduce error, and here's the GOLD documentation. Gold will try to hide (i.e. emit a warning instead of an error) about a shift/reduce, but it treats reduce/reduce as an error.

I don't entirely understand this; I'm new to parsing. Maybe you're right about this being unexpected behaviour? However the GOLD mailing list seems to be down at the moment, perhaps because it's moderated and Devin has been offline for months.

ChrisW
that actually does make sense. I expect it would not care if it goes down the same code path but i now can see that being ambiguous/a problem
acidzombie24