Skip to content

Instantly share code, notes, and snippets.

@makunomark
Created January 16, 2018 11:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makunomark/0157078010185a2b3092258bb5c9f9d5 to your computer and use it in GitHub Desktop.
Save makunomark/0157078010185a2b3092258bb5c9f9d5 to your computer and use it in GitHub Desktop.
%{
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int num_string = 0;
int num_char = 0;
%}
string [^\n\t ]+
%%
{string} {++num_string; num_char+=yyleng;}
%%
int main(int argc, char *argv[]){
struct stat st;
yyin = fopen(argv[1], "r");
stat(argv[1], &st);
yylex();
printf("Number of strings: %d\n", num_string);
printf("Number of characters: %d\n", num_char);
printf("File size: %d bytes\n", st.st_size);
fclose(yyin);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment