Created
September 8, 2013 10:44
-
-
Save khajavi/6483749 to your computer and use it in GitHub Desktop.
simple flex example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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 ); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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++; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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