fork download
  1. %{
  2. #include <stdio.h>
  3. int num1, num2;
  4. %}
  5.  
  6. %%
  7.  
  8. [0-9]+ {
  9. if (num1 == 0) {
  10. num1 = atoi(yytext);
  11. } else {
  12. num2 = atoi(yytext);
  13. }
  14. }
  15.  
  16. "+" {
  17. ; // This simply matches the plus sign, no action needed
  18. }
  19.  
  20. \n {
  21. printf("Sum: %d\n", num1 + num2);
  22. num1 = 0;
  23. num2 = 0;
  24. }
  25.  
  26. . { ; }
  27.  
  28. %%
  29.  
  30. int main() {
  31. num1 = 0;
  32. num2 = 0;
  33. yylex();
  34. return 0;
  35. }
  36.  
Success #stdin #stdout #stderr 0.02s 6876KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/EDr6FC/prog:2:1: Syntax error: Operator expected
ERROR: /home/EDr6FC/prog:35:1: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit