fork download
  1. #include<stdio.h>
  2. #include<string.h>
  3. int top;
  4. char s[10];
  5. char data;
  6. void push(int x)
  7. {
  8. s[top++]=x;
  9. }
  10. char pop()
  11. {
  12. data = s[--top];
  13. return data;
  14. }
  15. int main()
  16. {
  17. int i=0,n,state=0;
  18. char a[10],x;
  19. printf("Program For PDA Which Accepts Strings Of WCW^r\n");
  20. printf("Enter String:");
  21. gets(a);
  22. n=strlen(a);
  23.  
  24. top=-1;
  25. while(a[i]!='c'){
  26. if(a[i]=='a'||a[i]=='b')
  27. {
  28. state=0;
  29. push(a[i]);
  30. i++;
  31. }
  32. else
  33. {
  34. state=99;
  35. break;
  36. }
  37. }
  38. if(a[i]=='c' && state==0)
  39. {
  40. state=1;
  41. i++;
  42. }
  43. while(a[i]!='\0' && state==1)
  44. {
  45. x=pop();
  46. if(a[i]==x)
  47.  
  48. state=1;
  49. if(a[i]!=x)
  50. {
  51. state=99;
  52. break;
  53. }
  54. i++;
  55. }
  56. if(state==1 && a[i]=='\0')
  57. state=100;
  58. if (state==100)
  59. printf("String Accepted.");
  60. else
  61. printf("String Rejected.");
  62. return 0;
  63. }
Success #stdin #stdout #stderr 0.02s 6992KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: /home/97d3A6/prog:63:0: Syntax error: end_of_file_in_quasi_quotation
ERROR: '$runtoplevel'/0: Undefined procedure: program/0
   Exception: (3) program ? EOF: exit