fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. /* Définition des tokens */
  7. [ \t\n]+ ; /* Ignorer les espaces, tabulations et nouvelles lignes */
  8. "//".* ; /* Ignorer les commentaires monolignes */
  9. /\*([^*]|\*+[^*/])*\*+/ ; /* Ignorer les commentaires multilignes */
  10. if|else|while|return { printf("KEYWORD: %s\n", yytext); }
  11. [a-zA-Z_][a-zA-Z0-9_]* { printf("IDENTIFIER: %s\n", yytext); }
  12. [0-9]+ { printf("NUMBER: %s\n", yytext); }
  13. \+|\-|\*|\/|= { printf("OPERATOR: %s\n", yytext); }
  14. \(|\)|\{|\}|;|, { printf("SYMBOL: %s\n", yytext); }
  15. . { printf("UNKNOWN: %s\n", yytext); }
  16. %%
  17.  
  18. int main() {
  19. yylex();
  20. return 0;
  21. }
  22.  
  23. int yywrap() {
  24. return 1;
  25. }
  26.  
Success #stdin #stdout #stderr 0.03s 6840KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/X4JED2/prog:2:1: Syntax error: Operator expected
ERROR: /home/X4JED2/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit