fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4. %opƟon noyywrap
  5. // Regular expressions
  6. DIGIT [0-9]
  7. ID [a-zA-Z_][a-zA-Z0-9_]*
  8. KEYWORD int|float|if|else|for|while|return|void|char
  9. OPERATOR (\+|\-|\*|/|==|!=|<=|>=|<|>|=)
  10. DELIMITER [\{\}\[\]\(\);,]
  11. WHITESPACE [ \t\r\n]+
  12. COMMENT (//.*|/\*([^*]|\*+[^*/])*\*+/)
  13. %%
  14. {KEYWORD} { prinƞ("Keyword: %s\n", yytext); }
  15. {ID} { prinƞ("IdenƟfier: %s\n", yytext); }
  16. {DIGIT}+ { prinƞ("Integer: %s\n", yytext); }
  17. {DIGIT}+"."{DIGIT}+ { prinƞ("Float: %s\n", yytext); }
  18. {OPERATOR} { prinƞ("Operator: %s\n", yytext); }
  19. {DELIMITER} { prinƞ("Delimiter: %s\n", yytext); }
  20. {COMMENT} { prinƞ("Comment\n"); }
  21. {WHITESPACE} { /* ignore */ }
  22. . { prinƞ("Unknown character: %s\n", yytext); }
  23. %%
  24. int main() {
  25. yylex();
  26. return 0;
  27. }
  28.  
Success #stdin #stdout #stderr 0.03s 6904KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/lSFlYV/prog:2:1: Syntax error: Operator expected
ERROR: /home/lSFlYV/prog:27:2: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit