fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. "#include<stdio.h>" { printf("# include<stdio.h> is a preprocessor\n"); }
  7.  
  8. /* Keywords */
  9. "int"|"void"|"main"|"printf" { printf("A keyword: %s\n", yytext); }
  10.  
  11. /* Identifiers */
  12. [a-zA-Z_][a-zA-Z0-9_]* { printf("An identifier: %s\n", yytext); }
  13.  
  14. /* Numbers */
  15. [0-9]+ { printf("An integer: %s\n", yytext); }
  16.  
  17. /* Operators */
  18. [+\-*/=] { printf("An operator : %s\n", yytext); }
  19.  
  20. /* Punctuation */
  21. [(){};,] { printf("%s is a punctuation\n", yytext); }
  22.  
  23. /* String literal */
  24. \".*\" { printf("%s is a literalstring\n", yytext); }
  25.  
  26. /* Ignore spaces */
  27. [ \t\n] ;
  28.  
  29. /* Anything else */
  30. . { printf("Unknown: %s\n", yytext); }
  31.  
  32. %%
  33.  
  34. int main() {
  35. yylex();
  36. return 0;
  37. }
Success #stdin #stdout #stderr 0.03s 6956KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/b9OozS/prog:2:1: Syntax error: Operator expected
ERROR: /home/b9OozS/prog:37:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit