fork download
  1. %{
  2. int n = 0 ;
  3. %}
  4.  
  5. // rule section
  6. %%
  7. //count number of keywords
  8. "while" | "if" | "else" { n++;
  9. printf("\t keywords : %s", yytext);}
  10. // count number of keywords
  11. "int" | "float" { n++;
  12. printf("\t keywords : %s", yytext);}
  13. // count number of identifiers
  14. [a-zA-Z_] [a-zA-Z0-9_]* { n++;
  15. printf("\t identifier : %s", yytext);}
  16. // count number of operators
  17. "<=" | "==" | "=" | "++" | "-" | "*" | "+" { n++;
  18. printf("\t operator : %s", yytext);}
  19. // count number of separators
  20. [ () {} | , ; ] { n++;
  21. printf("\t separator : %s", yytext);}
  22. // count number of floats
  23. [0-9]* "." [0-9]+ { n++;
  24. printf("\t float : %s", yytext);}
  25. // count number of integers
  26. [0-9]+ {n++;
  27. printf("\t integer : %s", yytext);}
  28. . ;
  29. %%
  30. int main()
  31. {
  32. yylex();
  33. printf("\n total no. of token = %d\n", n);
  34. }
  35.  
Success #stdin #stdout #stderr 0.02s 6844KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/44Si6c/prog:2:4: Syntax error: Operator expected
ERROR: /home/44Si6c/prog:34:2: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit