diff --git a/version0.9/pda_demo.cpp b/version0.9/pda_demo.cpp deleted file mode 100644 index be371a9..0000000 --- a/version0.9/pda_demo.cpp +++ /dev/null @@ -1,262 +0,0 @@ -#include -#include -#include -#include - -enum token_type -{ - e=1,E,_E,T,_T,F,I,__add,__sub,__mul,__div,__link,__left_curve,__right_curve,sharp -}; - -const int max_len=5; -struct cmp_seq -{ - int tokens[max_len]; - int res; -}; -cmp_seq par[]= -{ - {{T,_E}, E}, - {{__add,T,_E}, _E}, - {{__sub,T,_E}, _E}, - {{__link,T,_E}, _E}, - {{e}, _E}, - {{F,_T}, T}, - {{__mul,F,_T}, _T}, - {{__div,F,_T}, _T}, - {{e}, _T}, - {{__left_curve,E,__right_curve},F}, - {{I}, F} -}; -int num_of_par=sizeof(par)/sizeof(cmp_seq); - -cmp_seq first_set[]= -{ - {{__left_curve,I},E}, - {{__left_curve,I},T}, - {{__left_curve,I},F}, - {{__add,__sub,__link,e},_E}, - {{__mul,__div,e},_T}, -}; -int num_of_set=sizeof(first_set)/sizeof(cmp_seq); - -bool isEnd(int type) -{ - return ((type==__left_curve) || (type==__right_curve) || (type==I) || (type==__add) || (type==__sub) || (type==__mul) || (type==__div) || (type==__link) || (type==e) || (type==sharp)); -} -bool isHead(int head,int type) -{ - for(int i=0;i main_stack; - std::stack comp_stack; - public: - PDA(std::string& text) - { - main_stack.push(sharp); - for(int i=(int)text.length()-1;i>=0;--i) - { - if(text[i]=='(') - main_stack.push(__left_curve); - else if(text[i]==')') - main_stack.push(__right_curve); - else if(text[i]=='i') - main_stack.push(I); - else if(text[i]=='+') - main_stack.push(__add); - else if(text[i]=='-') - main_stack.push(__sub); - else if(text[i]=='*') - main_stack.push(__mul); - else if(text[i]=='/') - main_stack.push(__div); - else if(text[i]=='~') - main_stack.push(__link); - } - comp_stack.push(sharp); - comp_stack.push(E); - } - void print_stack(std::stack& temp) - { - std::stack t; - while(!temp.empty()) - { - t.push(temp.top()); - print_token(t.top()); - temp.pop(); - } - while(!t.empty()) - { - temp.push(t.top()); - t.pop(); - } - return; - } - void print_main_and_comp() - { - print_stack(main_stack); - std::cout<<" "; - print_stack(comp_stack); - std::cout<=0;--j) - if(par[i].tokens[j]) - comp_stack.push(par[i].tokens[j]); - } - else if(!isHead(main_stack.top(),comp_stack.top())) - { - //to check if this can be extended as 'e' - int i=place_operator_end(comp_stack.top()); - if(i!=-1) - comp_stack.pop(); - else - { - std::cout<<"error."<>text; - PDA m(text); - m.work(); - } - return 0; -}