fork download
  1. %{
  2. #include <stdio.h>
  3. int com = 0;
  4. %}
  5.  
  6. %%
  7. "/*"[a-zA-Z0-9 \t\n]*"*/" { com++; } /* block comments */
  8. "//".* { com++; } /* single-line comments */
  9. .|\n { /* ignore others */ }
  10. %%
  11.  
  12. int main() {
  13. printf("Enter code press ctrl+d to end \n");
  14. yylex();
  15. printf("\ncomments are: %d", com);
  16. return 0;
  17. }
  18.  
  19. int yywrap(void) {
  20. return 1;
  21. }
Success #stdin #stdout #stderr 0.02s 6944KB
stdin
/*rhjgd*/
//fghgf
stdout
Standard output is empty
stderr
ERROR: /home/ZHRPjG/prog:21:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? [Illegal port specification]
   Exception: (3) program ? EOF: exit