fork download
  1. %{
  2. #include <stdio.h>
  3. int block_count = 0; // Counter for blocks
  4. %}
  5.  
  6. %%
  7. begin {
  8. block_count++;
  9. printf("Block %d begins.\n", block_count);
  10. }
  11. end {
  12. printf("Block %d ends.\n", block_count);
  13. block_count--;
  14. }
  15. .|\n ; // Ignore all other characters
  16. %%
  17.  
  18. int main() {
  19. printf("Enter your input (Ctrl+D to end):\n");
  20. yylex(); // Start lexical analysis
  21. if (block_count == 0) {
  22. printf("All blocks processed successfully.\n");
  23. } else {
  24. printf("Error: Unmatched 'begin' and 'end'.\n");
  25. }
  26. return 0;
  27. }
  28.  
  29.  
Success #stdin #stdout #stderr 0.04s 6940KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/qIMb6t/prog:28:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit