fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5. DIGIT [0-9]
  6. ID [a-zA-Z_][a-zA-Z0-9_]*
  7. %%
  8. if|then|else|int|while|char { printf("%s is a keyword\n", yytext); }
  9. {DIGIT}+ { printf("%s is a number\n", yytext); }
  10. {DIGIT}+"."{DIGIT}+ { printf("%s is a floating point number\n", yytext); }
  11. {ID} { printf("%s is an identifier\n", yytext); }
  12. [ \t\n]+ { /* ignore whitespace */ }
  13. [();{}] { printf("%s is a separator\n", yytext); }
  14. [,] { printf("%s is a delimiter\n", yytext); }
  15. %%
  16. int main()
  17. {
  18. printf("Enter input:\n");
  19. yylex();
  20. return 0;
  21. }
  22. int yywrap(void)
  23. {
  24. return 1;
  25. }
Success #stdin #stdout #stderr 0.02s 6952KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/66CfHG/prog:25:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit