user1070948
user1070948

Reputation: 23

yacc has a shift/reduce conflict

the situation is i wrote a very very simple syntax, but when compile, i got a conflict. I have no idear why a syntax such a simple can get a conflict.

%token SCRIPT_ID
%token STRING
%start functions

%%
functions: SCRIPT_ID '(' STRING ')' {printf("script_id is %s", $3);};
%%

I just want to use yacc to parse my file. In my file there are stuffs like script_id("1232444").

I search on yacc manual, and find when talking about shift/reduce conflict, it raises an example like 'if and else'. And i do understand that why 'if and else' has a conflict if the prioprity is not designate. But i do not know what that if-else-conflict has something to do with the conflict i met.

Can some one tell me what is wrong with my code?

Upvotes: 0

Views: 188

Answers (1)

Perry
Perry

Reputation: 4495

You have not stated what precise error you get. You also almost certainly haven't shown us the entire grammar because you can't get a shift/reduce conflict in a grammar with only one rule.

However, in general, if you want to understand what a shift/reduce conflict is, you probably need to learn a lot more about the theory of LR parsing state machines than you actually want to. Presuming you want to, however, you might start with these wikipedia pages:

The best overall text and reference book on this overall topic is the so-called "Dragon Book", (real name: Compilers: Principles, Techniques and Tools): http://en.wikipedia.org/wiki/Compilers:_Principles,_Techniques,_and_Tools

Upvotes: 1

Related Questions