fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6.  
  7. "int" { printf("Keyword: int\n"); }
  8. "float" { printf("Keyword: float\n"); }
  9. "return" { printf("Keyword: return\n"); }
  10.  
  11. [0-9]+ { printf("Number: %s\n", yytext); }
  12. [A-Za-z_][A-Za-z0-9_]* { printf("Identifier: %s\n", yytext); }
  13.  
  14. . { /* Ignore other characters */ }
  15.  
  16. %%
  17.  
  18. int main() {
  19. printf("Enter a string: ");
  20. yylex();
  21. return 0;
  22. }
  23.  
Success #stdin #stdout #stderr 0.03s 6976KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/4N17zW/prog:2:1: Syntax error: Operator expected
ERROR: /home/4N17zW/prog:22:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit