fork download
  1. #@title Writing Lex program
  2. %%writefile program.l
  3.  
  4. %{
  5. #include <stdio.h>
  6. int ctChar=0;
  7. int ctSpace=0;
  8. int ctWord=0;
  9. int ctLine=0;
  10. %}
  11. WORD [^ \t\n,\.:]+
  12. EOL [\n]
  13. BLANK [ ]
  14. %%
  15.  
  16. {WORD} {ctWord++; ctChar+=yyleng;}
  17. {BLANK} {ctSpace++;}
  18. {EOL} {ctLine++;}
  19. . {ctChar++;}
  20. %%
  21.  
  22. void main(int argc, char *argv[]){
  23. if(argc!=2){
  24. printf("Usage:\n\t./a.out <FILENAME>\n");
  25. exit(0);
  26. }
  27.  
  28. yyin=fopen(argv[1],"r");
  29. yylex();
  30.  
  31. printf("Word Count: %d\n",ctWord);
  32. printf("Character Count: %d\n",ctChar);
  33. printf("Space Count: %d\n",ctSpace);
  34. printf("Line Count: %d\n",ctLine);
  35. fclose(yyin);
  36.  
  37. }
  38.  
  39. int yywrap(){
  40. return 1;
  41. }
Success #stdin #stdout #stderr 0.02s 6872KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/MTcVB4/prog:5:5: Syntax error: Operator expected
ERROR: /home/MTcVB4/prog:41:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit