Counting variables, arrays in lex/flex
<p>I have started learning lex recently and tried a few examples.
I am trying to count the number of variables starting with 'a' and ending with a digit and the number of 1D arrays.</p>

<pre><code>%{
#undef yywrap
#define yywrap() 1
#include&lt;stdio.h&gt;
int count1;
int count2;
%}
%option noyywrap
%%

int|char|bool|float" "a[a-z,A-Z,0-9]*[0-9] {count1++;}
int|char|float|bool" "[a-z,A-Z]+[0-9,a-z,A-Z]*"["[0-9]+"]" {count2++;}

%%

void main(int argc,char** argv){
FILE *fh;
    if (argc == 2 &amp;&amp; (fh = fopen(argv[1], "r")))
        yyin = fh;
printf("%d %d",count1,count2);
yylex();
}
</code></pre>

<p>I am trying to count (1) the number of variables starting with 'a' and ending with a digit and (2) the number of 1D arrays. The input is from a "f.c" file.</p>

<pre><code>//f.c

#include&lt;stdio.h&gt;
void main(){
    char a;
    char b;
    char c;
    int ab[5];
    int bc[2];
    int ca[7];
    int ds[4];

}
</code></pre>

<p>Both the counts are showing zero and the output is: </p>

<pre><code>0 0#include&lt;stdio.h&gt;
void main(){
         a;
         b;
         c;
         ab[5];
         bc[2];
         ca[7];
         ds[4];

}
</code></pre>

<p>Also, how do I count those variables which fall in both of the categories?</p>