Skip to content

Instantly share code, notes, and snippets.

@JALsnipe
Created March 2, 2014 03:43
Show Gist options
  • Save JALsnipe/10b1d1270f590412768a to your computer and use it in GitHub Desktop.
Save JALsnipe/10b1d1270f590412768a to your computer and use it in GitHub Desktop.
%{
#include<stdio.h>
int nums = 0;
%}
number [0-9]
%%
{number} {nums++; printf("%s", yytext);}
%%
int yywrap()
{
return 1;
}
int main(int argc, char *argv[])
{
if(argc!=2)
{
printf("Usage: <./a.out> <sourcefile>\n");
exit(0);
}
yyin=fopen(argv[1],"r");
yylex();
printf("\nNumbers = %d\n",nums);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment