fork download
  1. %{
  2. #include <stdio.h>
  3. %}
  4.  
  5. %%
  6. [\t .,;:()*+_\-=!?/“”] { /* Ignore spacing and punctuation */ }
  7. 100 { printf("String contains '100'\n"); }
  8. 0[01]*1 { printf("String starts with '0' and ends with '1'\n"); }
  9. (0|1)* { if (isBinaryDivisibleBy3(yytext)) printf("Binary string divisible by 3\n"); }
  10. a|a*b+ { printf("String contains 'a' or 'a*b+'\n"); }
  11. . { /* Ignore other characters */ }
  12. %%
  13.  
  14. int isBinaryDivisibleBy3(char *bin) {
  15. int state = 0;
  16. for (int i = 0; bin[i] != '\0'; i++) {
  17. if (bin[i] == '0') state = state == 0 ? 0 : (state == 1 ? 2 : 1);
  18. else if (bin[i] == '1') state = state == 0 ? 1 : (state == 1 ? 0 : 2);
  19. }
  20. return (state == 0);
  21. }
  22.  
  23. int main() {
  24. yylex();
  25. return 0;
  26. }
  27.  
Success #stdin #stdout #stderr 0.02s 6780KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/OWaA0k/prog:2:1: Syntax error: Operator expected
ERROR: /home/OWaA0k/prog:26:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit