title: Bison - treat expr according to syntax expectations
body: <p>I am developing a syntax where I use constants, variables and arrays. Arrays can be like <code>name[]</code> or just like <code>name</code>.
  Each statement use arguments like <code>expr</code> or arrays.
  At parsing time there is no difference between a variable and an array name without <code>[]</code>.</p>
  
  <pre><code>array_empty:
                          args_variable '[' ']';
  
  args_array:
                          array_empty {
                              //special command to put array on app stack
                          }
                          | args_variable {
                              //special command to put array on app stack
                          }
  args_variable:
                          MYVARIABLE {
                              //Store variable into a variable table
                          }
                          | '(' args_variable ')'
                          ;
  args_Ae:
                          expr ',' args_array
              | '(' args_Ae ')';
  expr:                   ....
  
  ..................
  
  appsomestmt:  APPSOME expr {
                          //do something - one argument
                          }
                          | APPSOME args_Ae {
                          //do something else - two arguments
                          }
                          ;
  </code></pre>
  
  <p>A statement can have multiple syntax like:</p>
  
  <pre><code>APPSOME expr
  APPSOME array, expr
  </code></pre>
  
  <p>But if I use statement <code>APPSOME variable</code> in my application Bison reduce <code>variable</code> to <code>args_variable</code> then to <code>args_array</code> even the fact that there is only one argument.
  I want that program to detect that there is only one argument to this statement and use the first syntax <code>APPSOME expr</code>. Only when statement have 2 arguments like <code>APPSOME array, expr</code> I want to use the second syntax <code>APPSOME array, expr</code></p>
  
  <p>How can I do this? Remember that arrays have some <em>Actions in Mid-Rule</em> to put array on app stack.
  So, how can I force Bison to treat variables as variables/arrays according to syntax expectations?</p>
  
  <p><strong>EDIT</strong></p>
  
  <pre><code>%{
  %}
  
  %token APPSOME1 APPSOME2
  %token &lt;number&gt; APPVARIABLE 
  
  %left '-' '+'
  %left '*' '/'
  %left '^'
  
  %%
  
  program:        programline programnewline program
                  | programline
                  ;
  
  programnewline:
                  '\n' {
                      //some code
                  }
                  ;
  
  programline:    compoundstmt
              | /* empty */
              ;
  
  compoundstmt:
                          compoundstmt ':' statement
                          | statement
              ;
  
  array_empty:
                          args_variable '[' ']';
  
  // Array Variable Data
  args_array:
                          array_empty {
                              //tell interpretor that next is a array
                          }
                          | args_variable {
                              //tell interpretor that next is a array
                          }
                          ;
  
  args_variable:
                          APPVARIABLE {
                                  //put variable into table
                          }
                          | '(' args_variable ')'
                          ;
  
  /* multiple arguments */
  
  args_ee:
                          expr ',' expr
              | '(' args_ee ')';
  args_ae:
                          args_array ',' expr
              |'(' args_ae ')';
  args_aee:
                          args_array ',' expr ',' expr
              |'(' args_ae ')';
  
  /* list of statements */
  
  statement:
              app1stmt
                          | app2stmt
  
              ;
  
  
  app1stmt:  APPSOME1 expr {
                              //code
                          }
                          | APPSOME1 args_ae {
                              //code
                          }
                          ;
  
  app2stmt:  APPSOME2 args_ee {
                              //code
                          }
                          | APPSOME2 args_aee {
                              //code
                          }
                          ;
  
  expr:
              '(' expr ')'
              | expr '+' expr {
                  //code
              }
              | args_variable {
                                  //variable
              }
              | expr '-' expr {
                  //code
              }
              | expr '*' expr {
                  //code
              }
              | expr '/' expr {
                  //code
              }
              | expr '^' expr {
                  //code
              }
              ;
  
  %%
  </code></pre>