fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. // Match integers
  8. [0-9]+ { printf("%s\n", yytext); }
  9.  
  10. // Ignore everything else
  11. . ;
  12.  
  13. %%
  14.  
  15. // Main function
  16. int main(int argc, char **argv) {
  17. if (argc > 1) {
  18. FILE *file = fopen(argv[1], "r");
  19. if (file) {
  20. yyin = file;
  21. yylex();
  22. fclose(file);
  23. } else {
  24. perror("Error opening file");
  25. return 1;
  26. }
  27. } else {
  28. fprintf(stderr, "Usage: %s <filename>\n", argv[0]);
  29. return 1;
  30. }
  31. return 0;
  32. }
  33.  
Success #stdin #stdout #stderr 0.02s 6856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/hCpfrd/prog:2:1: Syntax error: Operator expected
ERROR: /home/hCpfrd/prog:32:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit