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