jwp@larry.sal.wisc.edu (Jeffrey W Percival) (09/05/89)
I am using yacc (for the first time) to parse a special purpose language, and am doing pretty good, so far. I am confused on something, though, and much pondering has failed to illuminate me. I hope the following yacc output fragment is enough to sketch the problem: 279: reduce/reduce conflict (red'ns 128 and 151 ) on INCLUDE state 279 cmd_parameter : MNEMONIC = MNEMONIC_ (128) arg : MNEMONIC_ (151) . reduce 128 Now, why is there a reduction ambiguity at the indicated spot? I mean, one rule has an equal sign, and the other doesn't. Surely yacc knows whether two things separated by '=' or a single thing has been read. What is the problem here (or what could be my next step in reasoning it out)? -- Jeff Percival (jwp@larry.sal.wisc.edu)
tsaim@eecs.nwu.edu (Ming-Hsiun Tsai) (09/06/89)
Dear friend:
After reading the news you posted, I don't believe that YACC gave
you that error-msg just coz of those two lines. I wonder there should be
some other production rules that cause the conflict happen.
In fact, I typein these lines (below the dash-line) and use YACC
to process it. But no error. So, there should be something in your rules.
How do you define the nonterminals cmd_parameter & arg? Maybe that is the
key!
M.S.Tsai /09/05/1989/
----------------------------------------------------------------------------
%token MNEMONIC MNEMONIC_
%start all
%%
all : cmd_parameter
| arg
;
cmd_parameter : MNEMONIC = MNEMONIC_
;
arg : MNEMONIC_
;
%%
djones@megatest.UUCP (Dave Jones) (09/06/89)
From article <718@larry.sal.wisc.edu>, by jwp@larry.sal.wisc.edu (Jeffrey W Percival): > I am using yacc (for the first time) to parse a special purpose > language, and am doing pretty good, so far. I am confused on > something, though, and much pondering has failed to illuminate me. > > I hope the following yacc output fragment is enough to sketch the problem: > > [ yacc output fragment omited. ] The fragment you posted is not enough. Try removing as much as you can from the grammar while still keeping the reduce/reduce message. If it's not obvious at that point, you might try posting the smaller grammar here. I would recommmend that you study up on LR parsing. The "dragon book" by Aho and Ullman is an old favorite. Good luck, Dave Jones
tsaim@eecs.nwu.edu (Ming-Hsiun Tsai) (09/07/89)
Dear Jeff: The error message on our system is not the same as on your system. So, I mis-understand that MNEMONIC_ is a (non-)terminal sysbol. I do the two tests below. The first one is the one like yours (I hope I do not make any mistake this time). Also I append the error message I get from my system. The second one is a correct one (YACC does not say anything wrong). Comparing the two. I think the problem is the "=" symbol in the rules. I don't know if "=" has special meaning translated by yacc. I have no yacc manual on hand. If you have, check it out. Conclusion: add "'" on both sides of "=". Try it. Hope it work for you. Good luck. Ming-Hsiun Tsai (Sep. 6, 1989) ---------------------- Example 1. An error demo ------------------------------ %token MNEMONIC %start all %% all : cmd_parameter | arg ; cmd_parameter : MNEMONIC = MNEMONIC ; arg : MNEMONIC ; %% ------------------------------------------------------------------------------- 1 rules never reduced conflicts: 1 reduce/reduce --------------- Example 2. This one may give you some ideas ------------------ %token MNEMONIC %start all %% all : cmd_parameter | arg ; cmd_parameter : MNEMONIC '=' MNEMONIC ; arg : MNEMONIC ; %% -------------------------------------------------------------------------------
itwaf@dcatla.UUCP (Bill Fulton [Sys Admin]) (09/09/89)
To recap; erroneous yacc input was: cmd : MNEMONIC = MNEMONIC ; ^ Note missing quotes I also sent the original poster this fix; but I was very surprised at the way yacc handled the unquoted equals sign. Apparantly, when the '=' was not quoted, yacc just *ignored* everything from the '=' to the end of the line! This explains the conflict, but can anyone explain why yacc (apparantly) ignores the part of a rule from an unquoted '=' to the end of line??? Does it do this with other unquoted characters? Is an unquoted '=' special? That's scary (e.g. silently dropping the end of a rule). I tried different unquoted characters than a '=', and I got yacc errors, but NO error with the unquoted '='! Also, looking at the output of 'yacc -v', I noted that the rule for the input line with the unquoted '=' had, indeed, just truncated the rule, starting at the '='. waf (Saving the net millions of dollars by not having a .sig) (Oops - does this count?)