“Flex is a tool for generating scanners: programs which recognized lexical patterns in text. flex reads the given input files, or its standard input if no file names are given, for a description of a scanner to generate. The description is in the form of pairs of regular expressions and C code, called rules. flex generates as output a C source file, lex.yy.c’, which defines a routine yylex()’. This file is compiled and linked with the -lfl’ library to produce an executable. When the executable is run, it analyzes its input for occurrences of the regular expressions. Whenever it finds one, it executes the corresponding C code.” — Vern Paxson
%% int yywrap(){return 1;} void main(){ yylex(); printf("Total number proper identifier is %d\n", count); }
测试输入find.l
1 2 3 4
unsigned int rand_code(unsigned int* rand_seed, unsigned int generator) { return *rand_seed = ((*_rand_seed * 234generator + 1)>>16)&65535; }
运行结果:
1
./a.out < test.in
1 2 3 4 5 6
Good identifier: rand_code Good identifier: rand_seed Good identifier: generator Good identifier: rand_seed Good identifier: _rand_seed Total number proper identifier is 5