You are on page 1of 2

%{

static int c[32];


extern FILE *yyin;
extern FILE *yyout;
#define IF 0
#define ELSE 1
#define AUTO 2
#define DOUBLE 3
#define INT 4
#define STRUCT 5
#define BREAK 6
#define LONG 7
#define SWITCH 8
#define CASE 9
#define ENUM 10
#define REGISTER 11
#define TYPEDEF 12
#define CHAR 13
#define EXTERN 14
#define RETURN 15
#define UNION 16
#define CONST 17
#define FLOAT 18
#define SHORT 19
#define UNSIGNED 20
#define CONTINUE 21
#define FOR 22
#define STATIC 23
#define VOID 24
#define DEFAULT 25
#define GOTO 26
#define SIZEOF 27
#define VOLATILE 28
#define DO 29
#define SIGNED 30
#define WHILE 31
%}
delim
ws
letter
digit
id
number

[ \t\n]
{delim}+
[A-Za-z]
[0-9]
{letter}({letter}|{digit})*
{digit}+(\.{digit}+)?(E[+\-]?{digit}+)?

%%
{ws}
if
else
auto
double
int
struct
break
long
switch
case
enum
register
typedef
char

{}
{count(IF);}
{count(ELSE);}
{count(AUTO);}
{count(DOUBLE);}
{count(INT);}
{count(STRUCT);}
{count(BREAK);}
{count(LONG);}
{count(SWITCH);}
{count(CASE);}
{count(ENUM);}
{count(REGISTER);}
{count(TYPEDEF);}
{count(CHAR);}

extern
return
union
const
float
short
unsigned
continue
for
static
void
default
goto
sizeof
volatile
do
signed
while

{count(EXTERN);}
{count(RETURN);}
{count(UNION);}
{count(CONST);}
{count(FLOAT);}
{count(SHORT);}
{count(UNSIGNED);}
{count(CONTINUE);}
{count(FOR);}
{count(STATIC);}
{count(VOID);}
{count(DEFAULT);}
{count(GOTO);}
{count(SIZEOF);}
{count(VOLATILE);}
{count(DO);}
{count(SIGNED);}
{count(WHILE);}

{id}
{number}
"<"
"<="
"="
"<>"
">"
">="
"("
")"
";"
%%

{}
{}
{}
{}
{}
{}
{}
{}
{}
{}
{}

count(int n)
{
c[n]+=1;
}
main(int argc,char **argv){
yyin = fopen("bitmap.c","r");
yyout = fopen("output.txt","w");
yylex();
int i;
for(i = 0;i<32;i++)
{
fprintf(yyout,"%d\n",c[i]);
}
}
yywrap(){
}

You might also like