fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. %}
  5.  
  6. /* Definitions (Regex for tokens) */
  7. DIGIT [0-9]
  8. ID [a-zA-Z_][a-zA-Z0-9_]*
  9. WS [ \t\n]+
  10.  
  11. %%
  12. "if" { printf("KEYWORD : %s\n", yytext); }
  13. "else" { printf("KEYWORD : %s\n", yytext); }
  14. "while" { printf("KEYWORD : %s\n", yytext); }
  15. "int"|"float"|"char" { printf("DATATYPE : %s\n", yytext); }
  16.  
  17. {ID} { printf("IDENTIFIER : %s\n", yytext); }
  18. {DIGIT}+ { printf("NUMBER : %s\n", yytext); }
  19. "=="|"=" { printf("ASSIGN/COMPARE OPERATOR : %s\n", yytext); }
  20. "+"|"-"|"*"|"/" { printf("ARITHMETIC OPERATOR : %s\n", yytext); }
  21. ";" { printf("SEMICOLON\n"); }
  22. {WS} { /* Ignore whitespace */ }
  23. . { printf("UNKNOWN : %s\n", yytext); }
  24. %%
  25.  
  26. int main() {
  27. printf("Enter the input:\n");
  28. yylex();
  29. return 0;
  30. }
  31.  
  32. int yywrap() {
  33. return 1;
  34. }
  35.  
Success #stdin #stdout #stderr 0.04s 6864KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/HnrbKp/prog:2:1: Syntax error: Operator expected
ERROR: /home/HnrbKp/prog:34:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit