From 79e620277292933c968827865a09d28ff5b30f04 Mon Sep 17 00:00:00 2001 From: Valk Richard Li <48872266+ValKmjolnir@users.noreply.github.com> Date: Fri, 30 Aug 2019 02:56:09 -0500 Subject: [PATCH] Update PDA demo --- version0.7/pda_demo.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/version0.7/pda_demo.cpp b/version0.7/pda_demo.cpp index 8693229..be371a9 100644 --- a/version0.7/pda_demo.cpp +++ b/version0.7/pda_demo.cpp @@ -5,10 +5,10 @@ enum token_type { - e=1,E,_E,T,_T,F,I,__add,__sub,__mul,__div,__left_curve,__right_curve,sharp + e=1,E,_E,T,_T,F,I,__add,__sub,__mul,__div,__link,__left_curve,__right_curve,sharp }; -const int max_len=3; +const int max_len=5; struct cmp_seq { int tokens[max_len]; @@ -19,6 +19,7 @@ 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}, @@ -34,14 +35,14 @@ cmp_seq first_set[]= {{__left_curve,I},E}, {{__left_curve,I},T}, {{__left_curve,I},F}, - {{__add,__sub,e},_E}, + {{__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==e) || (type==sharp)); + 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) { @@ -120,6 +121,9 @@ void print_token(int type) case __div: str="/"; break; + case __link: + str="~"; + break; case __left_curve: str="("; break; @@ -159,6 +163,8 @@ class PDA 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);