fork download
  1. %{
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. int sum = 0; // Variable to store the sum
  5. %}
  6.  
  7. %%
  8. [0-9]+ { sum += atoi(yytext); } // Convert text to int and add to sum
  9. \n { printf("Sum: %d\n", sum); sum = 0; } // Print sum after each line
  10. [ \t] { /* Ignore spaces and tabs */ }
  11. . { /* Ignore any other characters */ }
  12. %%
  13.  
  14. int main() {
  15. printf("Enter two numbers separated by spaces or newlines to sum them:\n");
  16. yylex(); // Start lexical analysis
  17. return 0;
  18. }
  19.  
Success #stdin #stdout #stderr 0.03s 7016KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/YZvuTs/prog:2:1: Syntax error: Operator expected
ERROR: /home/YZvuTs/prog:18:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit