dangling if else problem

I know to eliminate the shift reduce conflict is by using the %prec operator, I did already but still got this:

179: shift/reduce conflict (shift 190, reduce 36) on TELSE
state 179
      stmt : TIF '(' boolexp ')' stmt .  (36)
      stmt : TIF '(' boolexp ')' stmt . TELSE stmt  (37)

      TELSE  shift 190
      TID  reduce 36
      TINTCON  reduce 36
      TCHARCON  reduce 36
      TSTRCON  reduce 36
      TIF  reduce 36
      TWHILE  reduce 36
      TFOR  reduce 36
      TRETURN  reduce 36
      ';'  reduce 36
      '}'  reduce 36
      '{'  reduce 36

My rule is below:
%right ELSE
stmt			: 	TIF '(' boolexp ')' stmt %prec ELSE
					/* tree */
					$$.node = MakeTreeStmt($3.node,	$5.node,	NULL,	NULL,	T_STMT_IFELSE,	NULL);
				| TIF '(' boolexp ')' stmt TELSE stmt  
					/* tree */
					$$.node = MakeTreeStmt($3.node,	$5.node,	$7.node,	NULL,	T_STMT_IFELSE,	NULL);
				| TIF '(' expr %prec ELSE
					fprintf(stderr,"Illegal if statement\n");
					fprintf(stderr,"...at Line number %d \n",linenumber );

Open in new window

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

if/then/else is a common shift reduce problem...

      stmt : TIF '(' boolexp ')' stmt .  (36)
      stmt : TIF '(' boolexp ')' stmt . TELSE stmt  (37)

and by default yacc does what you want, ie a shift operation. You can try using %expect to do the same as the default without the warning message.

http://everything2.com/e2node/Shift%252FReduce%2520Conflict for a clear explanation.
The if-else shift/reduce conflict can be resolved like this :
%nonassoc TELSE
stmt : TIF '(' boolexp ')' stmt %prec LOWER_THAN_TELSE
     | TIF '(' boolexp ')' stmt TELSE stmt

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kuntilanakAuthor Commented:
thanks infinity it works
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.