Skip to content

Instantly share code, notes, and snippets.

@khajavi
Created September 8, 2013 10:44
Show Gist options
  • Select an option

  • Save khajavi/6483749 to your computer and use it in GitHub Desktop.

Select an option

Save khajavi/6483749 to your computer and use it in GitHub Desktop.
simple flex example
#include <stdio.h>
#include <stdlib.h>
extern int fee_count, fie_count, foe_count, fum_count;
extern int yylex( void );
int main( int argc, char** argv ) {
yylex();
printf( "%d %d %d %d\n", fee_count, fie_count, foe_count, fum_count );
exit( 0 );
}
int fee_count = 0;
int fie_count = 0;
int foe_count = 0;
int fum_count = 0;
%%
fee fee_count++;
fie fie_count++;
foe foe_count++;
fum fum_count++;
count_words: count_words.o lexer.o -lfl
gcc count_words.o lexer.o -lfl -o count_words
count_words.o: count_words.c
gcc -c count_words.c
lexer.o: lexer.c
gcc -c lexer.c
lexer.c: lexer.l
flex -t lexer.l > lexer.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment