title: Shift/reduce conflicts in yacc
body: <p>I am learning lex and yacc programming and this yacc program to validate and evaluate arithmetic expression in giving me 10 shift/reduce conflicts. Can you point out whats wrong with this program </p>
  
  <p>This is 611.y</p>
  
  <pre><code>%{
  #include&lt;stdio.h&gt;
  int flag=1;
  %}
  
  %token id num 
  %left '(' ')'
  %left '+' '-'
  %left '/' '*'
  %nonassoc UMINUS
  
  %%
  
  stmt:
      expression { printf("\n valid exprn");}
      ;
  
  expression:
      '(' expression ')' 
      | '(' expression {printf("\n Syntax error: Missing right paranthesis");}
      | expression '+' expression {printf("\nplus recog!");$$=$1+$3;printf("\n %d",$$);}
      | expression '+' { printf ("\n Syntax error: Right operand is missing ");}
      | expression '-' expression {printf("\nminus recog!");$$=$1-$3;printf("\n %d",$$);}
      | expression '-' { printf ("\n Syntax error: Right operand is missing ");}
      | expression '*' expression {printf("\nMul recog!");$$=$1*$3;printf("\n %d",$$);}
      | expression '*' { printf ("\n Syntax error: Right operand is missing ");}
      | expression '/' expression {printf("\ndivision recog!");if($3==0) printf("\ndivision cant be done, as divisor is zero.");else {$$=$1+$3;printf("\n %d",$$);}}
      | expression '/' { printf ("\n Syntax error: Right operand is missing ");}
      | expression '%' expression
      | expression '%' { printf ("\n Syntax error: Right operand is missing ");}
      | id
      | num 
  ;
  
  %%
  
  main()
  {
      printf(" Enter an arithmetic expression\n");
      yyparse();
  }
  
  yyerror()
  {
      printf(" Invalid arithmetic Expression\n");
      exit(1);
  }
  </code></pre>
  
  <p>This is 611.l</p>
  
  <pre><code>%{
  #include "y.tab.h"
  #include&lt;stdio.h&gt;
  #include&lt;ctype.h&gt;
  extern int yylval;
  int val;
  %}
  
  %%
  
  [a-zA-Z][a-zA-Z0-9]* {printf("\n enter the value of variable %s:",yytext);scanf("%d",&amp;val);yylval=val;return id;}
  [0-9]+[.]?[0-9]* {yylval=atoi(yytext);return num;}
  [ \t] ;
  \n {return 0;}
  . {return yytext[0];}
  %%
  
  int yywrap()
  {
      return 1;
  }
  </code></pre>
  
  <p>When I complie the code like this</p>
  
  <pre><code>lex 611.l
  
  yacc -d 611.y
  </code></pre>
  
  <p>It gives me </p>
  
  <pre><code>yacc:10 shift/reduce conflicts.
  </code></pre>
  
  <p>Please help me out here.</p>