fork download
  1. #include <stdio.h>
  2. #include <string.h>
  3. void main() {
  4. char input[100], l[50], r[50], temp[10], tempprod[20], productions[25][50];
  5. int i = 0, j = 0, flag = 0, consumed = 0;
  6. printf("Enter the productions: ");
  7. scanf("%1s->%s", l, r);
  8. printf("%s", r);
  9. while (sscanf(r + consumed, "%[^|]s", temp) == 1 && consumed <= strlen(r)) {
  10. if (temp[0] == l[0]) {
  11. flag = 1;
  12. sprintf(productions[i++], "%s->%s%s'\0", l, temp + 1, l);
  13. } else {
  14. sprintf(productions[i++], "%s'->%s%s'\0", l, temp, l);
  15. }
  16. consumed += strlen(temp) + 1;
  17. }
  18. if (flag == 1) {
  19. sprintf(productions[i++], "%s->ε\0", l);
  20. printf("The productions after eliminating Left Recursion are:\n");
  21. for (j = 0; j < i; j++)
  22. printf("%s\n", productions[j]);
  23. } else {
  24. printf("The Given Grammar has no Left Recursion");
  25. }
  26. }
Success #stdin #stdout #stderr 0.03s 6892KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/QjUPcy/prog:26:0: Syntax error: Unexpected end of file
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit