fork download
  1. %{
  2. #include <stdio.h>
  3. int word_count = 0;
  4. %}
  5.  
  6. /* Reguły leksykalne */
  7. %%
  8. [ \t\n]+ ; /* Pomijamy białe znaki */
  9. [a-zA-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ]+ { word_count++; } /* Rozpoznajemy słowo jako ciąg liter */
  10. . ; /* Pomijamy wszystkie inne znaki */
  11. %%
  12.  
  13. int main(int argc, char **argv) {
  14. /* Jeśli przekazano nazwę pliku jako argument, przekierowujemy stdin */
  15. if(argc > 1) {
  16. FILE *file = fopen(argv[1], "r");
  17. if(file == NULL) {
  18. perror("Nie można otworzyć pliku");
  19. return 1;
  20. }
  21. yyin = file;
  22. }
  23. yylex();
  24. printf("Liczba słów: %d\n", word_count);
  25. return 0;
  26. }
  27.  
Success #stdin #stdout #stderr 0.03s 6860KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/U69add/prog:2:1: Syntax error: Operator expected
ERROR: /home/U69add/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit