fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. void print_token(char* token, char* type) {
  6. printf("%s: %s\n", type, token);
  7. }
  8. %}
  9.  
  10. %%
  11.  
  12. Noun [A-Z][a-zA-Z]* { print_token(yytext, "Noun"); }
  13. Verb (run|jump|eat|play|write) { print_token(yytext, "Verb"); }
  14. Adverb (quickly|slowly|gracefully) { print_token(yytext, "Adverb"); }
  15. Adjective (big|small|beautiful|happy) { print_token(yytext, "Adjective"); }
  16.  
  17. [ \t\n] { /* Ignore spaces, tabs, and newlines */ }
  18. . { /* Ignore other characters */ }
  19.  
  20. %%
  21.  
  22. int main() {
  23. yylex(); // Start lexical analysis
  24. return 0;
  25. }
  26.  
Success #stdin #stdout #stderr 0.03s 6972KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/8sOXOM/prog:2:1: Syntax error: Operator expected
ERROR: /home/8sOXOM/prog:25:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit