%{ #include #include int fdefn = 0, fcall = 0, lineno = 1; %} whitespace [ \t]+ optwhitespace [ \t]* validname [a-zA-Z_][a-zA-Z0-9_]* invalidname (if|for|while|switch|return) invalidtype (else|do) leftparen {optwhitespace}\( ftypename {validname}{whitespace}\*?{optwhitespace}{validname} %% {invalidtype}{whitespace}{invalidname}/{leftparen} { } {invalidtype}{whitespace}{validname}/{leftparen} { char *p; p = yytext; while ((*p != ' ') && (*p != '\t')) ++p; while ((*p == ' ') || (*p == '\t')) ++p; printf("\t\tFunction call at line %d: \"%s\"\n", lineno, p); ++fcall; } {ftypename}/{leftparen} { printf("\tFunction definition at line %d: \"%s\"\n", lineno, yytext); ++fdefn; } {invalidname}/{leftparen} { } {validname}/{leftparen} { printf("\t\tFunction call at line %d: \"%s\"\n", lineno, yytext); ++fcall; } \n { ++lineno; } . { } %% int yywrap () { return 1; } int main () { yylex(); printf("+++ %d function definitions found\n", fdefn); printf("+++ %d function calls found\n", fcall); exit(0); }