fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. /* Definitions */
  6. DIGIT [0-9]
  7. LETTER [a-zA-Z]
  8. ID ({LETTER}|_){LETTER}*({LETTER}|{DIGIT}|_)*
  9. INTEGER {DIGIT}+
  10. FLOAT {DIGIT}+"."{DIGIT}+
  11. OPERATOR "+"|"-"|"*"|"/"
  12. WHITESPACE [ \t\n]+
  13.  
  14. %%
  15.  
  16. /* Rules */
  17. {INTEGER} { printf("INTEGER: %s\n", yytext); }
  18. {FLOAT} { printf("FLOAT: %s\n", yytext); }
  19. {ID} { printf("IDENTIFIER: %s\n", yytext); }
  20. {OPERATOR} { printf("OPERATOR: %s\n", yytext); }
  21. {WHITESPACE} /* skip whitespace */
  22. . { printf("UNRECOGNIZED: %s\n", yytext); }
  23.  
  24. %%
  25.  
  26. int main(int argc, char *argv[]) {
  27. // Initialize the lexer
  28. yyin = fopen(argv[1], "r");
  29. // Call the lexer
  30. yylex();
  31. // Close the input file
  32. fclose(yyin);
  33. return 0;
  34. }
  35.  
Success #stdin #stdout #stderr 0.03s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/NikElb/prog:2:1: Syntax error: Operator expected
ERROR: /home/NikElb/prog:34:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit