fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. /* ----- RÈGLES ----- */
  6. %%
  7. "if" { printf("KW_IF\n"); }
  8. "else" { printf("KW_ELSE\n"); }
  9. "while" { printf("KW_WHILE\n"); }
  10.  
  11. /* Operateurs de comparaison */
  12. "==" { printf("EQ\n"); }
  13. "!=" { printf("NEQ\n"); }
  14. "<=" { printf("LE\n"); }
  15. ">=" { printf("GE\n"); }
  16. "<" { printf("LT\n"); }
  17. ">" { printf("GT\n"); }
  18.  
  19. /* Operateurs arithmétiques */
  20. "=" { printf("ASSIGN\n"); }
  21. "+" { printf("PLUS\n"); }
  22. "-" { printf("MINUS\n"); }
  23. "*" { printf("MULT\n"); }
  24. "/" { printf("DIV\n"); }
  25.  
  26. /* Délimiteurs */
  27. "(" { printf("LPAREN\n"); }
  28. ")" { printf("RPAREN\n"); }
  29. "{" { printf("LBRACE\n"); }
  30. "}" { printf("RBRACE\n"); }
  31.  
  32. /* Identifiant */
  33. [a-zA-Z_][a-zA-Z0-9_]* { printf("IDENT(%s)\n", yytext); }
  34.  
  35. /* Nombre entier */
  36. [0-9]+ { printf("INT(%s)\n", yytext); }
  37.  
  38. /* Commentaires */
  39. "//"[^\n]* ;
  40.  
  41. /* Espaces : ignorés */
  42. [ \t\n]+ ;
  43.  
  44. /* Tout le reste = erreur */
  45. . { printf("ERROR(%s)\n", yytext); }
  46. %%
  47. int main() {
  48. yylex();
  49. return 0;
  50. }
  51.  
Success #stdin #stdout #stderr 0.03s 6916KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/m8EZUW/prog:2:1: Syntax error: Operator expected
ERROR: /home/m8EZUW/prog:50:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit