fork download
  1.  
  2. %{
  3. #include<stdio.h>
  4. %}
  5.  
  6. %%
  7. "bool"|"int"|"float"|"char"|"if"|"else"|"while"|"for"|"do"|"continue"|"break"|"return"|"void"
  8. { printf("Keyword\n"); }
  9.  
  10. \/\/[^\n]* { /* Ignore single line comment */ }
  11.  
  12. \/\*([^*]|\*+[^*/])*\*+\/
  13. { /* Ignore multi line comment */ }
  14.  
  15. [ \t\n]+ { /* Ignore spaces, tabs and newlines */ }
  16.  
  17. [0-9]+(\.[0-9]+)?
  18. { printf("Constant\n"); }
  19.  
  20. [A-Za-z_][A-Za-z0-9_]*
  21. { printf("Identifier\n"); }
  22.  
  23. "=="|"!="|"<="|">="|"++"|"--"|"&&"|"||"|[+\-*/%=<>!]
  24. { printf("Operator\n"); }
  25.  
  26. [(){};,] { /* Ignore punctuation */ }
  27.  
  28. . { /* Ignore other characters */ }
  29.  
  30. %%
  31.  
  32. int main()
  33. {
  34. printf("Enter the input:\n");
  35. yylex();
  36. return 0;
  37. }
  38.  
Success #stdin #stdout #stderr 0.02s 4944KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/run-20128/prog:3:1: Syntax error: Operator expected
ERROR: /home/run-20128/prog:37:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit