%{ int count = 0; int lineno = 1; %} %% [a-zA-Z][a-zA-Z0-9_]* {printf("(T_ident, %s)\n", yytext); count++;} [0-9]+ {printf("(T_num, %s)\n", yytext); count++;} [=] {printf("(T_assign, %s)\n", yytext); count++;} [+] {printf("(T_OP, %s)\n", yytext); count++;} [-] {printf("(T_OP, %s)\n", yytext); count++;} [*] {printf("(T_OP, %s)\n", yytext); count++;} [/] {printf("(T_OP, %s)\n", yytext); count++;} [<] {printf("(T_OP, %s)\n", yytext); count++;} [>] {printf("(T_OP, %s)\n", yytext); count++;} [;] {printf("(T_SemiC, %s)\n", yytext); count++;} [(] {printf("(T_OpenPar, %s)\n", yytext); count++;} [)] {printf("(T_ClosePar, %s)\n", yytext); count++;} [^\n\t] {printf("Invalid character: %s at line %d", yytext, lineno);} [\n] {lineno++;} %% int yywrap(){} int main(){ yylex(); printf("\nNumber of tokens found: %d\n", count); return 0; }