fork download
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4.  
  5. %}
  6.  
  7. KEYWORD int|float|if|else|while|for|return|void|char|double
  8. DATATYPE int|float|char|double|void
  9. IDENTIFIER [a-zA-Z_][a-zA-Z0-9_]*
  10. NUMBER [0-9]+
  11. OPERATOR (\+|\-|\*|\/|\=|\==|\!=|\<|\>|<=|>=)
  12. SYMBOL [;,\(\)\{\}]
  13.  
  14. %%
  15. {KEYWORD} { printf("Keyword: %s\n", yytext); }
  16. {DATATYPE} { printf("Datatype: %s\n", yytext); }
  17. {IDENTIFIER} { printf("Identifier: %s\n", yytext); }
  18. {NUMBER} { printf("Number: %s\n", yytext); }
  19. {OPERATOR} { printf("Operator: %s\n", yytext); }
  20. {SYMBOL} { printf("Symbol: %s\n", yytext); }
  21. [ \t\n] ; // Ignore whitespace
  22. . { printf("Unknown: %s\n", yytext); }
  23. %%
  24.  
  25. int main() {
  26. yylex();
  27. return 0;
  28. }
  29. int yywrap() { return 1; }
Success #stdin #stdout #stderr 0.02s 7012KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/BoSGfa/prog:2:1: Syntax error: Operator expected
ERROR: /home/BoSGfa/prog:29:25: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit