fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #define KEYWORD1 "int"
  5. #define KEYWORD2 "float"
  6. #define KEYWORD3 "return"
  7. #define KEYWORD4 "if"
  8. #define KEYWORD5 "else"
  9. %}
  10. %option noyywrap
  11. %%
  12. "int" { printf("Keyword: %s\n", yytext); }
  13. "float" { printf("Keyword: %s\n", yytext); }
  14. "return" { printf("Keyword: %s\n", yytext); }
  15. "if" { printf("Keyword: %s\n", yytext); }
  16. "else" { printf("Keyword: %s\n", yytext); }
  17. [a-zA-Z_][a-zA-Z0-9_]* { printf("Identifier: %s\n", yytext); }
  18. [ \t\n]+ ; /* Skip whitespace */
  19. . { printf("Other character: %c\n", *yytext); }
  20. %%
  21.  
  22. int main(int argc, char **argv) {
  23. yylex();
  24. return 0;
  25. }
  26.  
  27. int yywrap() {
  28. return 1;
  29. }
  30.  
Success #stdin #stdout #stderr 0.03s 6856KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/qIu0fk/prog:2:1: Syntax error: Operator expected
ERROR: /home/qIu0fk/prog:29:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit