syntax.c 108 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885
  1. #include"token.h"
  2. #include"lex.h"
  3. #include"../inter/interpreter.h"
  4. void factor(p_status *status, token_node *list);
  5. void power(p_status *status, token_node *list);
  6. void call_down(p_status *status, token_node *list);
  7. void paser_value(p_status *status, token_node *list);
  8. void element(p_status *status, token_node *list);
  9. void var_token(p_status *status, token_node *list);
  10. void polynomial(p_status *status, token_node *list);
  11. void bit_move(p_status *status, token_node *list);
  12. void command(p_status *status, token_node *list);
  13. void while_(p_status *status, token_node *list);
  14. void if_(p_status *status, token_node *list);
  15. void for_(p_status *status, token_node *list);
  16. void elif_(p_status *status, token_node *list);
  17. void block_(p_status *status, token_node *list);
  18. void top_exp(p_status *status, token_node *list);
  19. void negative(p_status *status, token_node *list);
  20. void bit_not(p_status *status, token_node *list);
  21. void bit_notor(p_status *status, token_node *list);
  22. void bit_or(p_status *status, token_node *list);
  23. void bit_and(p_status *status, token_node *list);
  24. void compare(p_status *status, token_node *list);
  25. void bool_and(p_status *status, token_node *list);
  26. void bool_or(p_status *status, token_node *list);
  27. void bool_not(p_status *status, token_node *list);
  28. void eq_number(p_status *status, token_node *list);
  29. void call_back_(p_status *status, token_node *list);
  30. void def_class(p_status *status, token_node *list);
  31. void ctrl_(p_status *status, token_node *list);
  32. void var_ctrl_(p_status *status, token_node *list);
  33. void return_(p_status *status, token_node *list);
  34. void formal_parameter(p_status *status, token_node *list);
  35. void list_(p_status *status, token_node *list);
  36. void dict_(p_status *status, token_node *list);
  37. void hide_list(p_status *status, token_node *list);
  38. void do_while_(p_status *status, token_node *list);
  39. void try_(p_status *status, token_node *list);
  40. void out_exception(p_status *status, token_node *list);
  41. void self_exp(p_status *status, token_node *list);
  42. void lambda_(p_status *status, token_node *list);
  43. void attribute(p_status *status, token_node *list);
  44. void import_include(p_status *status, token_node *list);
  45. void chose_exp_(p_status *status, token_node *list);
  46. void svar_token(p_status *status, token_node *list);
  47. void paser_error(char *text);
  48. /*
  49. command_list : command
  50. | command_list command
  51. */
  52. void command_list(p_status *status, token_node *list){ // 多项式
  53. fprintf(status_log, "[info][grammar] mode status: command_list\n", text);
  54. token left, right, new_token;
  55. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  56. if(left.type == NON_command_list){ // 模式2
  57. fprintf(status_log, "[info][grammar] (command_list)reduce right\n");
  58. get_right_token(status, list, command, right); // 回调右边
  59. if(right.type == NON_command){
  60. new_token.type = NON_command_list;
  61. new_token.data_type = empty;
  62. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  63. return command_list(status, list); // 回调自己
  64. }
  65. else{ // 递归跳出[EOF_token]
  66. printf("right.type = %d\n", right.type);
  67. fprintf(status_log, "[info][grammar] (command_list)out\n");
  68. back_one_token(list, left);
  69. back_again(list, right);
  70. return;
  71. }
  72. }
  73. else if(left.type == EOF_token){ // 递归跳出的条件
  74. fprintf(status_log, "[info][grammar] (command_list)out again\n");
  75. back_one_token(list, left);
  76. return;
  77. }
  78. else{ // 模式1
  79. fprintf(status_log, "[info][grammar] (command_list)back one token to (command)\n");
  80. back_one_token(list, left);
  81. get_base_token(status, list, command, new_token);
  82. if(new_token.type != NON_command){
  83. back_one_token(list, new_token); // 往回[不匹配类型]
  84. return;
  85. }
  86. new_token.type = NON_command_list;
  87. add_node(list, new_token);
  88. return command_list(status, list); // 回调自己
  89. }
  90. }
  91. /*
  92. command : top_exp <ENTER>
  93. */
  94. void command(p_status *old_status, token_node *list){ // 多项式
  95. p_status status;
  96. status = *old_status;
  97. status.is_left = false; // is_left复位[只有top_exp会开启以及element会开启]
  98. fprintf(status_log, "[info][grammar] mode status: command\n", text);
  99. token left, new_token;
  100. left = pop_node(list); // 先弹出一个token 检查token
  101. if(left.type == WHILE_PASER){ // 是while类型的数据
  102. fprintf(status_log, "[info][grammar] (command)back one token to (while)\n");
  103. back_one_token(list, left);
  104. get_base_token(&status, list, while_, new_token);
  105. get_stop_token(status, list);
  106. push_statement(statement_base, new_token);
  107. }
  108. else if(left.type == IF_PASER){
  109. fprintf(status_log, "[info][grammar] (command)back one token to (if)\n");
  110. back_one_token(list, left);
  111. get_base_token(&status, list, if_, new_token);
  112. get_stop_token(status, list);
  113. push_statement(statement_base, new_token);
  114. }
  115. else if(left.type == FOR_PASER){
  116. fprintf(status_log, "[info][grammar] (command)back one token to (for)\n");
  117. back_one_token(list, left);
  118. get_base_token(&status, list, for_, new_token);
  119. get_stop_token(status, list);
  120. push_statement(statement_base, new_token);
  121. }
  122. else if(left.type == DEF_PASER || left.type == CLASS_PASER){
  123. fprintf(status_log, "[info][grammar] (command)back one token to (def_class)\n");
  124. back_one_token(list, left);
  125. get_base_token(&status, list, def_class, new_token);
  126. get_stop_token(status, list);
  127. push_statement(statement_base, new_token);
  128. }
  129. else if(left.type == BREAK_PASER || left.type == BROKEN_PASER || left.type == CONTINUE_PASER || left.type == CONTINUED_PASER ||
  130. left.type == RESTART_PASER || left.type == RESTARTED_PASER || left.type == REGO_PASER || left.type == REWENT_PASER){
  131. fprintf(status_log, "[info][grammar] (command)back one token to (ctrl_)\n");
  132. back_one_token(list, left);
  133. get_base_token(&status, list, ctrl_, new_token);
  134. get_stop_token(status, list);
  135. push_statement(statement_base, new_token);
  136. }
  137. else if(left.type == GLOBAL_PASER || left.type == DEFAULT_PASER || left.type == NOLOCAL_PASER){
  138. fprintf(status_log, "[info][grammar] (command)back one token to (var_ctrl_)\n");
  139. back_one_token(list, left);
  140. get_base_token(&status, list, var_ctrl_, new_token);
  141. get_stop_token(status, list);
  142. push_statement(statement_base, new_token);
  143. }
  144. else if(left.type == IMPORT_PASER || left.type == INCLUDE_PASER){
  145. fprintf(status_log, "[info][grammar] (command)back one token to (import_include)\n");
  146. back_one_token(list, left);
  147. get_base_token(&status, list, import_include, new_token);
  148. get_stop_token(status, list);
  149. push_statement(statement_base, new_token);
  150. }
  151. else if(left.type == RETURN_PASER){
  152. fprintf(status_log, "[info][grammar] (command)back one token to (return_)\n");
  153. back_one_token(list, left);
  154. get_base_token(&status, list, return_, new_token);
  155. get_stop_token(status, list);
  156. push_statement(statement_base, new_token);
  157. }
  158. else if(left.type == TRY_PASER){
  159. fprintf(status_log, "[info][grammar] (command)back one token to (try_)\n");
  160. back_one_token(list, left);
  161. get_base_token(&status, list, try_, new_token);
  162. get_stop_token(status, list);
  163. push_statement(statement_base, new_token);
  164. }
  165. else if(left.type == DO_PASER){
  166. fprintf(status_log, "[info][grammar] (command)back one token to (do/do...while)\n");
  167. back_one_token(list, left);
  168. get_base_token(&status, list, do_while_, new_token);
  169. get_stop_token(status, list);
  170. push_statement(statement_base, new_token);
  171. }
  172. else if(left.type == RAISE_PASER || left.type == THROW_PASER || left.type == ASSERT_PASER){
  173. fprintf(status_log, "[info][grammar] (command)back one token to (out_exception)\n");
  174. back_one_token(list, left);
  175. get_base_token(&status, list, out_exception, new_token);
  176. get_stop_token(status, list);
  177. push_statement(statement_base, new_token);
  178. }
  179. else if(left.type == ENTER_PASER){
  180. fprintf(status_log, "[info][grammar] (command)back <ENTER>\n");
  181. }
  182. else if(left.type == EOF_token){
  183. fprintf(status_log, "[info][grammar] (command)back <EOF>\n");
  184. back_one_token(list, left);
  185. goto return_back;
  186. }
  187. else{ // 表达式
  188. fprintf(status_log, "[info][grammar] (command)back one token to (top_exp)\n");
  189. back_one_token(list, left);
  190. status.is_left = true;
  191. get_base_token(&status, list, top_exp, new_token);
  192. status.is_left = false;
  193. if(new_token.type != NON_top_exp){
  194. back_one_token(list, new_token); // 往回[不匹配类型]
  195. return;
  196. }
  197. get_stop_token(status, list);
  198. push_statement(statement_base, new_token);
  199. }
  200. new_token.type = NON_command;
  201. add_node(list, new_token);
  202. return_back:
  203. return; // 回调自己
  204. }
  205. /*
  206. if_ : IF LB top_exp RB block
  207. */
  208. void if_(p_status *status, token_node *list){
  209. fprintf(status_log, "[info][grammar] mode status: if_\n");
  210. token if_t, exp_t, block_t, next_t, child_t, new_token;
  211. if_t = pop_node(list);
  212. if(if_t.type == IF_PASER){
  213. get_right_token(status,list,top_exp,exp_t);
  214. if(exp_t.type != NON_top_exp){ // 不是表达式
  215. paser_error("Don't get 'top_exp'");
  216. }
  217. get_right_token(status,list,block_,block_t);
  218. if(block_t.type != NON_block){ // 不是表达式
  219. paser_error("Don't get '{'");
  220. }
  221. statement *if_tmp = make_statement();
  222. if_tmp->type = if_branch;
  223. if_tmp->code.if_branch.done = make_if(exp_t.data.statement_value, block_t.data.statement_value);
  224. // 检查else和elseif
  225. el_again:
  226. get_pop_token(status,list,next_t);
  227. if(next_t.type == ENTER_PASER){ // 忽略Enter
  228. goto el_again;
  229. }
  230. printf("next_t.type = %d\n", next_t.type);
  231. if(next_t.type == ELIF_PASER || next_t.type == ELSE_PASER){ // elif
  232. back_one_token(list, next_t);
  233. get_base_token(status,list,elif_,child_t);
  234. if(child_t.type == NON_elif){
  235. append_elif(child_t.data.if_list_base, if_tmp->code.if_branch.done);
  236. goto el_again;
  237. }
  238. }
  239. else{
  240. back_again(list, next_t); // 下一次读取需要用safe_get_token
  241. }
  242. new_token.type = NON_if;
  243. new_token.data_type = statement_value;
  244. new_token.data.statement_value = if_tmp;
  245. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  246. token tmp_enter;
  247. tmp_enter.type = ENTER_PASER;
  248. tmp_enter.data_type = empty;
  249. back_again(list, tmp_enter); // push入一个ENTER
  250. return;
  251. }
  252. else{
  253. back_one_token(list, if_t);
  254. return;
  255. }
  256. }
  257. /*
  258. elif_ : ELIF LB top_exp RB block
  259. */
  260. void elif_(p_status *status, token_node *list){
  261. fprintf(status_log, "[info][grammar] mode status: elif_\n");
  262. token elif_t, exp_t, block_t, next_t, new_token;
  263. elif_t = pop_node(list);
  264. if(elif_t.type == ELIF_PASER){
  265. get_right_token(status,list,top_exp,exp_t);
  266. if(exp_t.type != NON_top_exp){ // 不是表达式
  267. paser_error("Don't get 'top_exp'");
  268. }
  269. get_right_token(status,list,block_,block_t);
  270. if(block_t.type != NON_block){ // 不是表达式
  271. paser_error("Don't get '{'");
  272. }
  273. if_list *if_tmp = make_if(exp_t.data.statement_value, block_t.data.statement_value);
  274. new_token.type = NON_elif;
  275. new_token.data_type = if_list_base;
  276. new_token.data.if_list_base = if_tmp;
  277. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  278. return;
  279. }
  280. if(elif_t.type == ELSE_PASER){ // else
  281. get_right_token(status,list,block_,block_t);
  282. if(block_t.type != NON_block){ // 不是表达式
  283. paser_error("Don't get '{'");
  284. }
  285. if_list *if_tmp = make_if(NULL, block_t.data.statement_value);
  286. new_token.type = NON_elif;
  287. new_token.data_type = if_list_base;
  288. new_token.data.if_list_base = if_tmp;
  289. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  290. return;
  291. }
  292. else{
  293. back_one_token(list, elif_t);
  294. return;
  295. }
  296. }
  297. /*
  298. for_ : FOR LB top_exp COMMA top_exp COMMA top_exp RB block
  299. */
  300. void for_(p_status *status, token_node *list){
  301. fprintf(status_log, "[info][grammar] mode status: for_\n");
  302. token for_t, exp_1, exp_2, exp_3, block_t, comma_t,new_token;
  303. statement *exp_a, *exp_b, *exp_c;
  304. for_t = pop_node(list);
  305. if(for_t.type == FOR_PASER){
  306. bool is_for_in = false; // 是否为for in模式
  307. get_pop_token(status, list, exp_1);
  308. if(exp_1.type == COMMA_PASER){
  309. exp_a = NULL; // exp_1 = NULL;
  310. }
  311. else{
  312. back_one_token(list, exp_1);
  313. p_status new_status;
  314. new_status = *status;
  315. new_status.is_for = true;
  316. get_base_token(&new_status,list,top_exp,exp_1); // 不是使用right token,不需要执行safe_get_token
  317. new_status.is_for = false;
  318. if(exp_1.type != NON_top_exp){ // 不是表达式
  319. paser_error("Don't get 'top_exp'");
  320. }
  321. get_pop_token(status, list, comma_t);
  322. if(comma_t.type == IN_PASER){ // for in 模式 -> exp1不可以为NULL
  323. is_for_in = true;
  324. exp_a = exp_1.data.statement_value;
  325. goto exp3;
  326. }
  327. else if(comma_t.type != COMMA_PASER){
  328. paser_error("Don't get ',' in for cycle");
  329. }
  330. exp_a = exp_1.data.statement_value;
  331. }
  332. get_pop_token(status, list, exp_2);
  333. if(exp_2.type == COMMA_PASER){
  334. exp_b = NULL; // exp_1 = NULL;
  335. }
  336. else{
  337. back_one_token(list, exp_2);
  338. p_status new_status;
  339. new_status = *status;
  340. new_status.is_for = true;
  341. get_base_token(&new_status,list,top_exp,exp_2); // 不是使用right token,不需要执行safe_get_token
  342. new_status.is_for = false;
  343. if(exp_2.type != NON_top_exp){ // 不是表达式
  344. paser_error("Don't get 'top_exp'");
  345. }
  346. get_pop_token(status, list, comma_t);
  347. if(comma_t.type != COMMA_PASER){
  348. paser_error("Don't get ',' in for cycle");
  349. }
  350. exp_b = exp_2.data.statement_value;
  351. }
  352. exp3:
  353. get_pop_token(status, list, exp_3);
  354. if(exp_3.type == COMMA_PASER){
  355. if(is_for_in){
  356. paser_error("Don't get iter object");
  357. }
  358. exp_c = NULL; // exp_1 = NULL;
  359. }
  360. else{
  361. back_one_token(list, exp_3);
  362. p_status new_status;
  363. new_status = *status;
  364. if(!is_for_in) new_status.is_for = true;
  365. get_base_token(&new_status,list,top_exp,exp_3); // 不是使用right token,不需要执行safe_get_token
  366. if(!is_for_in) new_status.is_for = false;
  367. if(exp_3.type != NON_top_exp){ // 不是表达式
  368. paser_error("Don't get 'top_exp'");
  369. }
  370. if(!is_for_in){ // for in 不需要匹配“,”
  371. get_pop_token(status, list, comma_t);
  372. if(comma_t.type != COMMA_PASER){
  373. paser_error("Don't get ',' in for cycle");
  374. }
  375. }
  376. exp_c = exp_3.data.statement_value;
  377. }
  378. get_right_token(status,list,block_,block_t);
  379. if(block_t.type != NON_block){ // 不是表达式
  380. paser_error("Don't get '{'");
  381. }
  382. statement *for_tmp = make_statement();
  383. if(is_for_in){
  384. for_tmp->type = for_in_cycle;
  385. for_tmp->code.for_in_cycle.var = exp_a;
  386. for_tmp->code.for_in_cycle.iter = exp_c;
  387. for_tmp->code.for_in_cycle.done = block_t.data.statement_value;
  388. }
  389. else{
  390. for_tmp->type = for_cycle;
  391. for_tmp->code.for_cycle.first = exp_a;
  392. for_tmp->code.for_cycle.condition = exp_b;
  393. for_tmp->code.for_cycle.after = exp_c;
  394. for_tmp->code.for_cycle.done = block_t.data.statement_value;
  395. }
  396. new_token.type = NON_for;
  397. new_token.data_type = statement_value;
  398. new_token.data.statement_value = for_tmp;
  399. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  400. return;
  401. }
  402. else{
  403. back_one_token(list, for_t);
  404. return;
  405. }
  406. }
  407. /*
  408. def_ : DEF LB RB block
  409. */
  410. void def_class(p_status *status, token_node *list){
  411. fprintf(status_log, "[info][grammar] mode status: def_\n");
  412. token def_t, lb_t, rb_t, block_t, name_t, parameter_t, new_token;
  413. parameter *p_list;
  414. def_t = pop_node(list);
  415. if(def_t.type == DEF_PASER || def_t.type == CLASS_PASER){
  416. p_status new_status;
  417. new_status = *status;
  418. new_status.not_match_tuple = true;
  419. new_status.not_match_call = true;
  420. get_right_token(&new_status,list,top_exp,name_t); // 避免了top_exp把括号捕捉为call_back,不过,可以使用list设置status参数从而让call_back不捕捉[未实现]
  421. if(name_t.type != NON_top_exp){ // 不是表达式
  422. paser_error("Don't get 'top_exp'");
  423. }
  424. get_pop_token(status, list, lb_t);
  425. if(lb_t.type != LB_PASER){
  426. printf("lb_t.type = %d\n", lb_t.type);
  427. paser_error("Don't get '('");
  428. }
  429. get_pop_token(status, list, rb_t);
  430. if(rb_t.type != RB_PASER){ // 带参数
  431. back_one_token(list, rb_t);
  432. get_base_token(status,list,formal_parameter,parameter_t); // 不需要safe_get_token
  433. if(parameter_t.type != NON_parameter){
  434. paser_error("Don't get formal_parameter");
  435. }
  436. printf("parameter_t = %d\n", parameter_t.data.parameter_list->u.var->type);
  437. get_pop_token(status, list, rb_t);
  438. printf("rb_t.type = %d\n", rb_t.type);
  439. if(rb_t.type != RB_PASER){
  440. paser_error("Don't get ')'[1]");
  441. }
  442. p_list = parameter_t.data.parameter_list;
  443. }
  444. else{
  445. p_list = NULL; // 没参数
  446. }
  447. get_right_token(status,list,block_,block_t);
  448. if(block_t.type != NON_block){ // 不是表达式
  449. paser_error("Don't get '{'");
  450. }
  451. statement *def_tmp = make_statement();
  452. if(def_t.type == DEF_PASER){
  453. def_tmp->type = def;
  454. def_tmp->code.def.var = name_t.data.statement_value;
  455. def_tmp->code.def.parameter_list = p_list;
  456. def_tmp->code.def.done = block_t.data.statement_value;
  457. }
  458. else{
  459. def_tmp->type = set_class;
  460. def_tmp->code.set_class.var = name_t.data.statement_value;
  461. def_tmp->code.set_class.father_list = p_list;
  462. def_tmp->code.set_class.done = block_t.data.statement_value;
  463. }
  464. new_token.type = NON_def;
  465. new_token.data_type = statement_value;
  466. new_token.data.statement_value = def_tmp;
  467. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  468. return;
  469. }
  470. else{
  471. back_one_token(list, def_t);
  472. return;
  473. }
  474. }
  475. void formal_parameter(p_status *status, token_node *list){ // 因试分解
  476. fprintf(status_log, "[info][grammar] mode status: formal_parameter\n");
  477. token left, next, comma, before, eq, value_token, new_token;
  478. int mode = only_value;
  479. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  480. if(left.type == NON_parameter){ // 模式2/3
  481. fprintf(status_log, "[info][grammar] (formal_parameter)reduce right\n");
  482. get_pop_token(status, list, comma);
  483. if(comma.type == (status->is_slice ? COLON_PASER : COMMA_PASER)){
  484. get_pop_token(status, list, before);
  485. if(before.type == MUL_PASER){
  486. if(status->match_dict){
  487. paser_error("dict shouldn't get '*'");
  488. }
  489. mode = put_args;
  490. }
  491. else if(before.type == POW_PASER){
  492. if(status->match_list){
  493. paser_error("list shouldn't get '*'");
  494. }
  495. mode = put_kwargs;
  496. }
  497. else{
  498. mode = only_value;
  499. back_again(list,before); // 回退
  500. }
  501. p_status new_status;
  502. new_status = *status;
  503. new_status.not_match_eq = true;
  504. new_status.not_match_tuple = true;
  505. get_right_token(&new_status, list, top_exp, next);
  506. if(next.type != NON_top_exp){ // 结尾分号
  507. back_one_token(list, left); // 分号忽略
  508. back_again(list, next);
  509. return;
  510. }
  511. new_token = left;
  512. parameter *tmp = NULL;
  513. get_pop_token(status, list, eq);
  514. printf("eq.type = %d %d\n", eq.type, status->is_peq);
  515. if(eq.type == ((status->match_dict || status->is_peq) ? COLON_PASER : EQ_PASER)){ // name_value模式
  516. if(status->match_list){
  517. paser_error("list shouldn't get '='");
  518. }
  519. p_status new_status;
  520. new_status = *status;
  521. if(!status->match_dict) new_status.not_match_eq = true; // dict使用了 : 代替 =
  522. new_status.not_match_tuple = true;
  523. get_right_token(&new_status, list, top_exp, value_token);
  524. if(value_token.type != NON_top_exp){
  525. paser_error("Don't get a top_exp");
  526. return;
  527. }
  528. tmp = append_parameter_name(next.data.statement_value, new_token.data.parameter_list);
  529. tmp->type = name_value;
  530. tmp->u.value = value_token.data.statement_value;
  531. }
  532. else{
  533. if(status->match_dict){
  534. paser_error("dict should get ':'[1]");
  535. }
  536. back_again(list,eq); // 回退[如果使用back_one_token则会导致add_node在EQ的后面]
  537. tmp = append_parameter_value(next.data.statement_value, new_token.data.parameter_list);
  538. tmp->type = mode;
  539. tmp->u.var = tmp->u.value;
  540. }
  541. add_node(list, new_token);
  542. return formal_parameter(status, list); // 回调自己
  543. }
  544. else{ // 递归跳出
  545. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  546. fprintf(status_log, "[info][grammar] (formal_parameter)out\n");
  547. back_one_token(list, left);
  548. back_again(list, comma);
  549. return;
  550. }
  551. }
  552. else if(left.type == POW_PASER || left.type == MUL_PASER){ // 模式1
  553. fprintf(status_log, "[info][grammar] (formal_parameter)back one token to (top_exp)[**/*]\n");
  554. p_status new_status;
  555. new_status = *status;
  556. new_status.not_match_eq = true;
  557. new_status.not_match_tuple = true;
  558. get_right_token(&new_status, list, top_exp, next); // 不需要back_one_token
  559. if(next.type != NON_top_exp){
  560. back_one_token(list, next); // 往回[不匹配类型]
  561. return;
  562. }
  563. new_token.type = NON_parameter;
  564. new_token.data_type = parameter_list;
  565. new_token.data.parameter_list = make_parameter_value(next.data.statement_value);
  566. new_token.data.parameter_list->u.var = new_token.data.parameter_list->u.value;
  567. if(left.type == POW_PASER){
  568. if(status->match_list){
  569. paser_error("list shouldn't get '**'");
  570. }
  571. new_token.data.parameter_list->type = put_kwargs;
  572. }
  573. else{
  574. if(status->match_dict){
  575. paser_error("dict shouldn't get '*'");
  576. }
  577. new_token.data.parameter_list->type = put_args;
  578. }
  579. add_node(list, new_token);
  580. return formal_parameter(status, list); // 回调自己
  581. }
  582. else{ // 模式1
  583. fprintf(status_log, "[info][grammar] (formal_parameter)back one token to (top_exp)\n");
  584. back_one_token(list, left);
  585. p_status new_status;
  586. new_status = *status;
  587. new_status.not_match_eq = true;
  588. new_status.not_match_tuple = true;
  589. get_base_token(&new_status, list, top_exp, next);
  590. if(next.type != NON_top_exp){
  591. back_one_token(list, next); // 往回[不匹配类型]
  592. return;
  593. }
  594. new_token.type = NON_parameter;
  595. new_token.data_type = parameter_list;
  596. parameter *tmp = NULL;
  597. get_pop_token(status, list, eq);
  598. if(eq.type == ((status->match_dict || status->is_peq) ? COLON_PASER : EQ_PASER)){ // name_value模式
  599. if(status->match_list){
  600. paser_error("list shouldn't get '='");
  601. }
  602. p_status new_status;
  603. new_status = *status;
  604. new_status.not_match_tuple = true;
  605. if(!status->match_dict) new_status.not_match_eq = true;
  606. get_right_token(&new_status, list, top_exp, value_token);
  607. if(value_token.type != NON_top_exp){
  608. paser_error("Don't get a top_exp");
  609. return;
  610. }
  611. new_token.data.parameter_list = make_parameter_name(next.data.statement_value);
  612. new_token.data.parameter_list->u.value = value_token.data.statement_value;
  613. new_token.data.parameter_list->type = name_value;
  614. }
  615. else{
  616. if(status->match_dict){
  617. paser_error("dict should get ':'[2]");
  618. }
  619. back_again(list,eq); // 回退[如果使用back_one_token则会导致add_node在EQ的后面]
  620. new_token.data.parameter_list = make_parameter_value(next.data.statement_value);
  621. new_token.data.parameter_list->u.var = new_token.data.parameter_list->u.value;
  622. new_token.data.parameter_list->type = only_value;
  623. }
  624. add_node(list, new_token);
  625. return formal_parameter(status, list); // 回调自己
  626. }
  627. }
  628. /*
  629. import “aaa” as AA 和 include 语句
  630. */
  631. void import_include(p_status *status, token_node *list){
  632. fprintf(status_log, "[info][grammar] mode status: while_\n");
  633. token type_t, str_t, as_t, var_t, new_token;
  634. type_t = pop_node(list);
  635. if(type_t.type == IMPORT_PASER || type_t.type == INCLUDE_PASER){
  636. get_right_token(status,list,top_exp,str_t);
  637. if(str_t.type != NON_top_exp){ // 不是表达式
  638. paser_error("Don't get top_exp");
  639. }
  640. statement *tmp = make_statement();
  641. if(type_t.type == IMPORT_PASER){ // import才有as top_exp
  642. get_pop_token(status, list, as_t);
  643. if(as_t.type != AS_PASER){
  644. paser_error("Don't get as");
  645. }
  646. get_right_token(status,list,top_exp,var_t);
  647. if(var_t.type != NON_top_exp){ // 不是表达式
  648. paser_error("Don't get top_exp");
  649. }
  650. tmp->type = import_class;
  651. tmp->code.import_class.file = str_t.data.statement_value;
  652. tmp->code.import_class.var = var_t.data.statement_value;
  653. }
  654. else{
  655. tmp->type = include_import;
  656. tmp->code.include_import.file = str_t.data.statement_value;
  657. }
  658. new_token.type = NON_import;
  659. new_token.data_type = statement_value;
  660. new_token.data.statement_value = tmp;
  661. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  662. return;
  663. }
  664. else{
  665. back_one_token(list, type_t);
  666. return;
  667. }
  668. }
  669. /*
  670. while_ : WHILE LB top_exp RB block
  671. */
  672. void do_while_(p_status *status, token_node *list){
  673. fprintf(status_log, "[info][grammar] mode status: while_\n");
  674. token do_t, while_t, exp_t, block_t, new_token;
  675. do_t = pop_node(list);
  676. if(do_t.type == DO_PASER){
  677. get_right_token(status,list,block_,block_t);
  678. if(block_t.type != NON_block){ // 不是表达式
  679. paser_error("Don't get '{'");
  680. }
  681. statement *tmp = make_statement();
  682. get_pop_token(status, list, while_t);
  683. if(while_t.type != WHILE_PASER){ // block模式
  684. back_again(list,while_t);
  685. tmp->type = code_block;
  686. tmp->code.code_block.done = block_t.data.statement_value;
  687. }
  688. else{
  689. get_right_token(status,list,top_exp,exp_t);
  690. if(exp_t.type != NON_top_exp){ // 不是表达式
  691. paser_error("Don't get 'top_exp'");
  692. }
  693. tmp->type = while_cycle;
  694. tmp->code.while_cycle.condition = exp_t.data.statement_value;
  695. tmp->code.while_cycle.done = block_t.data.statement_value;
  696. tmp->code.while_cycle.first_do = true;
  697. }
  698. new_token.type = NON_do_while;
  699. new_token.data_type = statement_value;
  700. new_token.data.statement_value = tmp;
  701. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  702. return;
  703. }
  704. else{
  705. back_one_token(list, do_t);
  706. return;
  707. }
  708. }
  709. /*
  710. while_ : WHILE LB top_exp RB block
  711. */
  712. void while_(p_status *status, token_node *list){
  713. fprintf(status_log, "[info][grammar] mode status: while_\n");
  714. token while_t, exp_t, block_t, new_token;
  715. while_t = pop_node(list);
  716. if(while_t.type == WHILE_PASER){
  717. get_right_token(status,list,top_exp,exp_t);
  718. if(exp_t.type != NON_top_exp){ // 不是表达式
  719. paser_error("Don't get 'top_exp'");
  720. }
  721. get_right_token(status,list,block_,block_t);
  722. if(block_t.type != NON_block){ // 不是表达式
  723. paser_error("Don't get '{'");
  724. }
  725. statement *while_tmp = make_statement();
  726. while_tmp->type = while_cycle;
  727. while_tmp->code.while_cycle.condition = exp_t.data.statement_value;
  728. while_tmp->code.while_cycle.done = block_t.data.statement_value;
  729. while_tmp->code.while_cycle.first_do = false;
  730. new_token.type = NON_while;
  731. new_token.data_type = statement_value;
  732. new_token.data.statement_value = while_tmp;
  733. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  734. return;
  735. }
  736. else{
  737. back_one_token(list, while_t);
  738. return;
  739. }
  740. }
  741. /*
  742. try_ : TRY block EXCEPT AS top_exp block
  743. */
  744. void try_(p_status *status, token_node *list){
  745. fprintf(status_log, "[info][grammar] mode status: while_\n");
  746. token try_t, try_block, except_t, as_t, var_t, except_block, new_token;
  747. try_t = pop_node(list);
  748. if(try_t.type == TRY_PASER){
  749. get_right_token(status, list, block_, try_block);
  750. if(try_block.type != NON_block){
  751. paser_error("Don't get '{'");
  752. }
  753. except_again:
  754. get_pop_token(status,list,except_t);
  755. if(except_t.type == ENTER_PASER){
  756. goto except_again;
  757. }
  758. else if(except_t.type != EXCEPT_PASER){ // 不是except
  759. paser_error("Don't get 'except'");
  760. }
  761. get_pop_token(status,list,as_t);
  762. if(as_t.type != AS_PASER){ // 不是except
  763. paser_error("Don't get 'as'");
  764. }
  765. get_right_token(status, list, top_exp, var_t);
  766. if(var_t.type != NON_top_exp){
  767. paser_error("Don't get top_exp");
  768. }
  769. get_right_token(status,list,block_,except_block);
  770. if(except_block.type != NON_block){ // 不是表达式
  771. paser_error("Don't get '{'");
  772. }
  773. statement *try_tmp = make_statement();
  774. try_tmp->type = try_code;
  775. try_tmp->code.try_code.try = try_block.data.statement_value;
  776. try_tmp->code.try_code.except = except_block.data.statement_value;
  777. try_tmp->code.try_code.var = var_t.data.statement_value;
  778. new_token.type = NON_try;
  779. new_token.data_type = statement_value;
  780. new_token.data.statement_value = try_tmp;
  781. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  782. return;
  783. }
  784. else{
  785. back_one_token(list, try_t);
  786. return;
  787. }
  788. }
  789. /*
  790. block_ : LP command_list RB
  791. */
  792. void block_(p_status *status, token_node *list){
  793. fprintf(status_log, "[info][grammar] mode status: block_\n");
  794. token lp_t, rp_t, new_token, command_list_t;
  795. lp_t = pop_node(list);
  796. again:
  797. if(lp_t.type == LP_PASER){
  798. statement *block_tmp = make_statement();
  799. statement_base = append_statement_list(block_tmp, statement_base);
  800. p_status new_status = *status; // 继承file_p等值
  801. reset_status(new_status); // 不会影响 *staus
  802. new_status.dict_to_enter = true;
  803. get_right_token(&new_status,list,command_list,command_list_t); // 要把command_list也弹出来
  804. statement_base = free_statement_list(statement_base); // 重新释放
  805. get_pop_token(status, list, rp_t);
  806. if(rp_t.type != RP_PASER){
  807. paser_error("Don't get '}'");
  808. }
  809. new_token.type = NON_block;
  810. new_token.data_type = statement_value;
  811. new_token.data.statement_value = block_tmp;
  812. add_node(list, new_token); // 压入节点
  813. return;
  814. }
  815. if(lp_t.type == ENTER_PASER){
  816. get_pop_token(status,list,lp_t);
  817. goto again;
  818. }
  819. else{
  820. printf("lp_t.type = %d != %d\n", lp_t.type, LP_PASER);
  821. back_one_token(list, lp_t);
  822. return;
  823. }
  824. }
  825. // var_ctrl_ 包含诸如:global, nolocal,之类的
  826. void var_ctrl_(p_status *status, token_node *list){
  827. fprintf(status_log, "[info][grammar] mode status: bit_not\n");
  828. token left, var, right, new_token;
  829. statement *times = NULL;
  830. char *var_name = NULL;
  831. left = pop_node(list);
  832. if(left.type == GLOBAL_PASER || left.type == DEFAULT_PASER || left.type == NOLOCAL_PASER){
  833. fprintf(status_log, "[info][grammar] (ctrl_)reduce right\n");
  834. statement *base_tmp = NULL;
  835. again:
  836. {
  837. p_status new_status;
  838. new_status = *status;
  839. new_status.not_match_tuple = true; // 不捕捉,
  840. get_right_token(&new_status, list, top_exp, var); // 取得base_var
  841. if(var.type != NON_top_exp && var.data.statement_value->type != base_var){
  842. paser_error("Don't get var");
  843. }
  844. else{
  845. var_name = malloc(sizeof(var.data.statement_value->code.base_var.var_name));
  846. strcpy(var_name, var.data.statement_value->code.base_var.var_name);
  847. times = var.data.statement_value->code.base_var.from;
  848. // TODO:: 本质上没有完全释放
  849. free(var.data.statement_value->code.base_var.var_name);
  850. free(var.data.statement_value);
  851. }
  852. if(left.type == DEFAULT_PASER){ // 设置times
  853. get_right_token(&new_status, list, top_exp, right); // 回调右边
  854. if(right.type != NON_top_exp){
  855. back_again(list, right); // 不是期望的数字
  856. }
  857. else{
  858. times = right.data.statement_value;
  859. }
  860. }
  861. // 逻辑操作
  862. new_token.type = NON_ctrl;
  863. new_token.data_type = statement_value;
  864. statement *code_tmp = make_statement();
  865. if(base_tmp == NULL){
  866. base_tmp = code_tmp;
  867. }
  868. else{
  869. append_statement(base_tmp, code_tmp);
  870. }
  871. switch (left.type)
  872. {
  873. case GLOBAL_PASER:
  874. code_tmp->type = set_global;
  875. code_tmp->code.set_global.name = var_name;
  876. break;
  877. case DEFAULT_PASER:
  878. code_tmp->type = set_default;
  879. code_tmp->code.set_default.name = var_name;
  880. code_tmp->code.set_default.times = times;
  881. break;
  882. case NOLOCAL_PASER:
  883. code_tmp->type = set_nonlocal;
  884. code_tmp->code.set_nonlocal.name = var_name;
  885. break;
  886. default:
  887. break;
  888. }
  889. }
  890. token comma_t;
  891. get_pop_token(status,list,comma_t);
  892. if(comma_t.type == COMMA_PASER){
  893. goto again;
  894. }
  895. else{
  896. back_again(list, comma_t);
  897. }
  898. new_token.data.statement_value = base_tmp;
  899. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  900. return; // 回调自己
  901. }
  902. else{ // 模式1
  903. back_one_token(list, left);
  904. return;
  905. }
  906. }
  907. // raise throw 和 assert
  908. void out_exception(p_status *status, token_node *list){
  909. fprintf(status_log, "[info][grammar] mode status: out_exception\n");
  910. token left, exp1, exp2, new_token;
  911. left = pop_node(list);
  912. if(left.type == RAISE_PASER || left.type == THROW_PASER || left.type == ASSERT_PASER){
  913. fprintf(status_log, "[info][grammar] (out_exception)reduce right\n");
  914. get_right_token(status, list, top_exp, exp1); // 取得base_var
  915. if(exp1.type != NON_top_exp){
  916. paser_error("Don't get top_exp");
  917. }
  918. if(left.type != THROW_PASER){ // 设置times
  919. get_right_token(status, list, top_exp, exp2); // 回调右边
  920. if(exp2.type != NON_top_exp){
  921. paser_error("Don't get top_exp");
  922. }
  923. }
  924. // 逻辑操作
  925. new_token.type = NON_exception;
  926. new_token.data_type = statement_value;
  927. statement *code_tmp = make_statement();
  928. switch (left.type)
  929. {
  930. case RAISE_PASER:
  931. code_tmp->type = raise_e;
  932. code_tmp->code.raise_e.done = exp1.data.statement_value;
  933. code_tmp->code.raise_e.info = exp2.data.statement_value;
  934. break;
  935. case THROW_PASER:
  936. code_tmp->type = throw_e;
  937. code_tmp->code.throw_e.done = exp1.data.statement_value;
  938. break;
  939. case ASSERT_PASER:
  940. code_tmp->type = assert_e;
  941. code_tmp->code.assert_e.condition = exp1.data.statement_value;
  942. code_tmp->code.assert_e.info = exp2.data.statement_value;
  943. break;
  944. default:
  945. break;
  946. }
  947. new_token.data.statement_value = code_tmp;
  948. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  949. return; // 回调自己
  950. }
  951. else{ // 模式1
  952. back_one_token(list, left);
  953. return;
  954. }
  955. }
  956. void return_(p_status *status, token_node *list){
  957. fprintf(status_log, "[info][grammar] mode status: return_\n");
  958. token left, right, value, new_token;
  959. statement *times = NULL, *back_value = NULL;
  960. left = pop_node(list);
  961. if(left.type == RETURN_PASER){
  962. fprintf(status_log, "[info][grammar] (return_)reduce right\n");
  963. get_right_token(status, list, top_exp, value); // 回调右边
  964. if(value.type != NON_top_exp){
  965. back_again(list, value); // 不是期望的数字,就默认使用NULL,并且回退
  966. times = NULL;
  967. back_value = NULL;
  968. goto not_times;
  969. }
  970. else{
  971. back_value = value.data.statement_value;
  972. }
  973. get_right_token(status, list, top_exp, right); // 回调右边
  974. if(right.type != NON_top_exp){
  975. back_again(list, right); // 不是期望的数字,就默认使用NULL,并且回退
  976. times = NULL;
  977. }
  978. else{
  979. times = right.data.statement_value;
  980. }
  981. not_times:
  982. new_token.type = NON_return;
  983. new_token.data_type = statement_value;
  984. statement *code_tmp = make_statement();
  985. code_tmp->type = return_code;
  986. code_tmp->code.return_code.times = times;
  987. code_tmp->code.return_code.value = back_value;
  988. new_token.data.statement_value = code_tmp;
  989. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  990. return; // 回调自己
  991. }
  992. else{ // 模式1
  993. back_one_token(list, left);
  994. return;
  995. }
  996. }
  997. // ctrl_包含诸如:break,broken,之类的
  998. void ctrl_(p_status *status, token_node *list){
  999. fprintf(status_log, "[info][grammar] mode status: bit_not\n");
  1000. token left, right, new_token;
  1001. statement *times = NULL;
  1002. left = pop_node(list);
  1003. if(left.type == BREAK_PASER || left.type == BROKEN_PASER || left.type == CONTINUE_PASER || left.type == CONTINUED_PASER ||
  1004. left.type == RESTART_PASER || left.type == RESTARTED_PASER || left.type == REGO_PASER || left.type == REWENT_PASER){
  1005. fprintf(status_log, "[info][grammar] (ctrl_)reduce right\n");
  1006. if(left.type != REGO_PASER && left.type != REWENT_PASER){
  1007. get_right_token(status, list, top_exp, right); // 回调右边
  1008. if(right.type != NON_top_exp){
  1009. back_again(list, right); // 不是期望的数字,就默认使用NULL,并且回退
  1010. times = NULL;
  1011. }
  1012. else{
  1013. times = right.data.statement_value;
  1014. }
  1015. }
  1016. // 逻辑操作
  1017. new_token.type = NON_ctrl;
  1018. new_token.data_type = statement_value;
  1019. statement *code_tmp = make_statement();
  1020. switch (left.type)
  1021. {
  1022. case BREAK_PASER:
  1023. code_tmp->type = break_cycle;
  1024. code_tmp->code.break_cycle.times = times;
  1025. break;
  1026. case BROKEN_PASER:
  1027. code_tmp->type = broken;
  1028. code_tmp->code.broken.times = times;
  1029. break;
  1030. case CONTINUE_PASER:
  1031. code_tmp->type = continue_cycle;
  1032. code_tmp->code.continue_cycle.times = times;
  1033. break;
  1034. case CONTINUED_PASER:
  1035. code_tmp->type = continued;
  1036. code_tmp->code.continued.times = times;
  1037. break;
  1038. case RESTART_PASER:
  1039. code_tmp->type = restart;
  1040. code_tmp->code.restart.times = times;
  1041. break;
  1042. case RESTARTED_PASER:
  1043. code_tmp->type = restarted;
  1044. code_tmp->code.restarted.times = times;
  1045. break;
  1046. case REGO_PASER:
  1047. code_tmp->type = rego;
  1048. break;
  1049. case REWENT_PASER:
  1050. code_tmp->type = rewent;
  1051. break;
  1052. default:
  1053. break;
  1054. }
  1055. new_token.data.statement_value = code_tmp;
  1056. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1057. return; // 回调自己
  1058. }
  1059. else{ // 模式1
  1060. back_one_token(list, left);
  1061. return;
  1062. }
  1063. }
  1064. /*
  1065. top_exp : polynomial
  1066. */
  1067. void top_exp(p_status *status, token_node *list){
  1068. fprintf(status_log, "[info][grammar] mode status: top_exp\n");
  1069. token exp;
  1070. get_base_token(status,list,eq_number,exp);
  1071. if(exp.type != NON_eq){
  1072. back_one_token(list, exp);
  1073. return;
  1074. }
  1075. exp.type = NON_top_exp;
  1076. add_node(list, exp); // 压入节点
  1077. return;
  1078. }
  1079. /*
  1080. eq_number : bool_or
  1081. | eq_number AND bool_or
  1082. */
  1083. void eq_number(p_status *status, token_node *list){ // 因试分解
  1084. fprintf(status_log, "[info][grammar] mode status: eq_number\n");
  1085. token left, right, symbol, new_token;
  1086. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1087. if(left.type == NON_eq){ // 模式2/3
  1088. fprintf(status_log, "[info][grammar] (eq_number)reduce right\n");
  1089. get_pop_token(status, list, symbol);
  1090. if((symbol.type == EQ_PASER && !status->not_match_eq) || symbol.type == AADD_PASER || symbol.type == ASUB_PASER || symbol.type == AMUL_PASER || symbol.type == ADIV_PASER||
  1091. symbol.type == AMOD_PASER || symbol.type == AINTDIV_PASER || symbol.type == APOW_PASER){ // 模式2/3
  1092. get_right_token(status, list, hide_list, right); // 回调右边
  1093. if(right.type != NON_hide_list){
  1094. paser_error("Don't get a hide_list");
  1095. }
  1096. // 逻辑操作
  1097. new_token.type = NON_eq;
  1098. new_token.data_type = statement_value;
  1099. statement *code_tmp = make_statement();
  1100. code_tmp->type = operation;
  1101. switch (symbol.type)
  1102. {
  1103. case EQ_PASER:
  1104. code_tmp->code.operation.type = ASSIGnMENT_func;
  1105. break;
  1106. case AADD_PASER:
  1107. code_tmp->code.operation.type = AADD_func;
  1108. break;
  1109. case ASUB_PASER:
  1110. code_tmp->code.operation.type = ASUB_func;
  1111. break;
  1112. case AMUL_PASER:
  1113. code_tmp->code.operation.type = AMUL_func;
  1114. break;
  1115. case ADIV_PASER:
  1116. code_tmp->code.operation.type = ADIV_func;
  1117. break;
  1118. case AMOD_PASER:
  1119. code_tmp->code.operation.type = AMOD_func;
  1120. break;
  1121. case AINTDIV_PASER:
  1122. code_tmp->code.operation.type = AINTDIV_func;
  1123. break;
  1124. case APOW_PASER:
  1125. code_tmp->code.operation.type = APOW_func;
  1126. break;
  1127. }
  1128. code_tmp->code.operation.left_exp = left.data.statement_value;
  1129. code_tmp->code.operation.right_exp = right.data.statement_value;
  1130. new_token.data.statement_value = code_tmp;
  1131. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1132. return eq_number(status, list); // 回调自己
  1133. }
  1134. else{ // 递归跳出
  1135. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1136. fprintf(status_log, "[info][grammar] (bit_notor)out\n");
  1137. back_one_token(list, left);
  1138. back_again(list, symbol);
  1139. return;
  1140. }
  1141. }
  1142. else{ // 模式1
  1143. fprintf(status_log, "[info][grammar] (eq_number)back one token to (hide_list)\n");
  1144. back_one_token(list, left);
  1145. get_base_token(status, list, hide_list, new_token); // hide_list会处理is_left
  1146. if(new_token.type != NON_hide_list){
  1147. back_one_token(list, new_token); // 往回[不匹配类型]
  1148. return;
  1149. }
  1150. if(status->is_left){ // 必须是在最左边 -> 进入解包赋值
  1151. status->is_left = false;
  1152. token comma, p_left, eq_t, p_right, tmp;
  1153. parameter *the_right;
  1154. get_pop_token(status, list,comma);
  1155. if(comma.type == COMMA_PASER){ // a,b = [1,2]的赋值方式
  1156. back_one_token(list, new_token); // 先把new_token和comma一起回退
  1157. back_again(list, comma);
  1158. p_status new_status;
  1159. new_status = *status;
  1160. new_status.is_peq = true;
  1161. get_base_token(&new_status,list,formal_parameter,p_left);
  1162. if(p_left.type != NON_parameter){
  1163. paser_error("Dont get formal_parameter");
  1164. }
  1165. get_pop_token(status, list, eq_t);
  1166. if(eq_t.type != EQ_PASER || status->not_match_eq){ // 变成hide_list
  1167. back_again(list, eq_t);
  1168. statement *code_tmp = make_statement();
  1169. code_tmp->type = base_tuple;
  1170. code_tmp->code.base_tuple.value = p_left.data.parameter_list;
  1171. new_token.data.statement_value = code_tmp;
  1172. new_token.data_type = statement_value;
  1173. goto return_back;
  1174. }
  1175. get_pop_token(status,list,tmp);
  1176. if(tmp.type == POW_PASER || tmp.type == MUL_PASER || tmp.type == COLON_PASER){
  1177. if(tmp.type != COLON_PASER){
  1178. back_again(list, tmp);
  1179. }
  1180. get_right_token(status,list,formal_parameter,p_right);
  1181. if(p_right.type != NON_parameter){
  1182. paser_error("Don't get formal_parameter");
  1183. }
  1184. the_right = p_right.data.parameter_list;
  1185. }
  1186. else{
  1187. back_again(list, tmp);
  1188. get_right_token(status,list,hide_list,p_right); // 把后面匹配为list
  1189. if(p_right.type != NON_hide_list){
  1190. paser_error("Don't get hide_list");
  1191. }
  1192. the_right = make_parameter_value(p_right.data.statement_value);
  1193. the_right->type = put_args;
  1194. the_right->u.var = the_right->u.value;
  1195. }
  1196. new_token.data_type = statement_value;
  1197. new_token.data.statement_value = make_statement();
  1198. new_token.data.statement_value->type = pack_eq;
  1199. new_token.data.statement_value->code.pack_eq.left = p_left.data.parameter_list;
  1200. new_token.data.statement_value->code.pack_eq.right = the_right;
  1201. }
  1202. else{
  1203. back_again(list, comma); // 回退comma 使用back_again目的是让new_token在comma之前
  1204. }
  1205. }
  1206. return_back:
  1207. new_token.type = NON_eq;
  1208. add_node(list, new_token);
  1209. return eq_number(status, list); // 回调自己
  1210. }
  1211. }
  1212. void hide_list(p_status *status, token_node *list){
  1213. fprintf(status_log, "[info][grammar] mode status: hide_list\n");
  1214. token exp;
  1215. bool old_is_left = status->is_left;
  1216. p_status new_status;
  1217. new_status = *status;
  1218. new_status.is_left = false; // 接下去的运算 is_left均为false
  1219. get_base_token(&new_status,list,lambda_,exp);
  1220. new_status.is_left = old_is_left;
  1221. if(exp.type != NON_lambda){
  1222. back_one_token(list, exp);
  1223. return;
  1224. }
  1225. if(!status->not_match_tuple && !status->is_left && !status->is_for){ // 几个会用到逗号的选项先排除
  1226. token comma;
  1227. get_pop_token(status,list,comma);
  1228. if(comma.type == COMMA_PASER){
  1229. token new_token;
  1230. back_one_token(list, exp);
  1231. back_again(list, comma);
  1232. p_status new_status;
  1233. new_status = *status;
  1234. new_status.not_match_tuple = true;
  1235. get_base_token(&new_status, list, formal_parameter, new_token);
  1236. if(new_token.type != NON_parameter){
  1237. paser_error("Don't get formal_parameter");
  1238. }
  1239. statement *code_tmp = make_statement();
  1240. code_tmp->type = base_tuple;
  1241. code_tmp->code.base_tuple.value = new_token.data.parameter_list;
  1242. exp.data.statement_value = code_tmp;
  1243. exp.data_type = statement_value;
  1244. }
  1245. else{
  1246. back_again(list, comma);
  1247. }
  1248. }
  1249. exp.type = NON_hide_list;
  1250. add_node(list, exp); // 压入节点
  1251. return;
  1252. }
  1253. void lambda_(p_status *status, token_node *list){
  1254. fprintf(status_log, "[info][grammar] mode status: lambda_\n");
  1255. token left, lambda_t, block_t, symbol, new_token;
  1256. left = pop_node(list);
  1257. if(left.type != NON_chose){
  1258. back_one_token(list, left);
  1259. get_base_token(status, list, chose_exp_, left);
  1260. if(left.type != NON_chose){
  1261. back_one_token(list, left);
  1262. return;
  1263. }
  1264. }
  1265. get_pop_token(status, list, lambda_t);
  1266. if(lambda_t.type != LAMBDA_PASER){ // 不是lambda表达式
  1267. left.type = NON_lambda;
  1268. back_one_token(list, left);
  1269. back_again(list, lambda_t);
  1270. return;
  1271. }
  1272. get_right_token(status, list, block_, block_t);
  1273. if(block_t.type != NON_block){
  1274. paser_error("Do't get '{");
  1275. }
  1276. statement *lambda_tmp = make_statement();
  1277. lambda_tmp->type = lambda_func;
  1278. if(left.data.statement_value->type == base_tuple){
  1279. lambda_tmp->code.lambda_func.parameter_list = left.data.statement_value->code.base_tuple.value;
  1280. }
  1281. else{
  1282. lambda_tmp->code.lambda_func.parameter_list = NULL;
  1283. }
  1284. free(left.data.statement_value);
  1285. lambda_tmp->code.lambda_func.done = block_t.data.statement_value;
  1286. new_token.type = NON_lambda;
  1287. new_token.data_type = statement_value;
  1288. new_token.data.statement_value = lambda_tmp;
  1289. add_node(list, new_token);
  1290. return;
  1291. }
  1292. // xxx if yyy else zzz
  1293. void chose_exp_(p_status *status, token_node *list){
  1294. fprintf(status_log, "[info][grammar] mode status: chose_exp\n");
  1295. token left, if_t, else_t, condition, right, new_token;
  1296. left = pop_node(list);
  1297. if(left.type != NON_bool_or){
  1298. back_one_token(list, left);
  1299. get_base_token(status, list, bool_or, left);
  1300. if(left.type != NON_bool_or){
  1301. back_one_token(list, left);
  1302. return;
  1303. }
  1304. }
  1305. get_pop_token(status, list, if_t);
  1306. if(if_t.type != IF_PASER){ // 不是if else表达式
  1307. left.type = NON_chose;
  1308. back_one_token(list, left);
  1309. back_again(list, if_t);
  1310. return;
  1311. }
  1312. get_right_token(status, list, bool_or, condition);
  1313. if(condition.type != NON_bool_or){
  1314. paser_error("Do't get condition");
  1315. }
  1316. get_pop_token(status, list, else_t);
  1317. if(else_t.type != ELSE_PASER){ // 不是if else表达式
  1318. paser_error("Do't get else");
  1319. return;
  1320. }
  1321. get_right_token(status, list, bool_or, right);
  1322. if(right.type != NON_bool_or){
  1323. paser_error("Do't get bool or");
  1324. }
  1325. statement *chose_tmp = make_statement();
  1326. chose_tmp->type = chose_exp;
  1327. chose_tmp->code.chose_exp.condition = condition.data.statement_value;
  1328. chose_tmp->code.chose_exp.true_do = left.data.statement_value;
  1329. chose_tmp->code.chose_exp.false_do = right.data.statement_value;
  1330. new_token.type = NON_chose;
  1331. new_token.data_type = statement_value;
  1332. new_token.data.statement_value = chose_tmp;
  1333. add_node(list, new_token);
  1334. return;
  1335. }
  1336. /*
  1337. bool_or : bool_and
  1338. | bool_or AND bool_and
  1339. */
  1340. void bool_or(p_status *status, token_node *list){ // 因试分解
  1341. fprintf(status_log, "[info][grammar] mode status: bool_or\n");
  1342. token left, right, symbol, new_token;
  1343. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1344. if(left.type == NON_bool_or){ // 模式2/3
  1345. fprintf(status_log, "[info][grammar] (bool_or)reduce right\n");
  1346. get_pop_token(status, list, symbol);
  1347. if(symbol.type == OR_PASER){ // 模式2/3
  1348. get_right_token(status, list, bool_and, right); // 回调右边
  1349. if(right.type != NON_bool_and){
  1350. paser_error("Don't get a compare");
  1351. }
  1352. // 逻辑操作
  1353. new_token.type = NON_bool_or;
  1354. new_token.data_type = statement_value;
  1355. statement *code_tmp = make_statement();
  1356. code_tmp->type = operation;
  1357. code_tmp->code.operation.type = OR_func;
  1358. code_tmp->code.operation.left_exp = left.data.statement_value;
  1359. code_tmp->code.operation.right_exp = right.data.statement_value;
  1360. new_token.data.statement_value = code_tmp;
  1361. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1362. return bool_or(status, list); // 回调自己
  1363. }
  1364. else{ // 递归跳出
  1365. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1366. fprintf(status_log, "[info][grammar] (bit_notor)out\n");
  1367. back_one_token(list, left);
  1368. back_again(list, symbol);
  1369. return;
  1370. }
  1371. }
  1372. else{ // 模式1
  1373. fprintf(status_log, "[info][grammar] (bool_or)back one token to (bool_and)\n");
  1374. back_one_token(list, left);
  1375. get_base_token(status, list, bool_and, new_token);
  1376. if(new_token.type != NON_bool_and){
  1377. back_one_token(list, new_token); // 往回[不匹配类型]
  1378. return;
  1379. }
  1380. new_token.type = NON_bool_or;
  1381. add_node(list, new_token);
  1382. return bool_or(status, list); // 回调自己
  1383. }
  1384. }
  1385. /*
  1386. bool_and : bool_not
  1387. | bool_and AND bool_not
  1388. */
  1389. void bool_and(p_status *status, token_node *list){ // 因试分解
  1390. fprintf(status_log, "[info][grammar] mode status: bool_and\n");
  1391. token left, right, symbol, new_token;
  1392. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1393. if(left.type == NON_bool_and){ // 模式2/3
  1394. fprintf(status_log, "[info][grammar] (bool_and)reduce right\n");
  1395. get_pop_token(status, list, symbol);
  1396. if(symbol.type == AND_PASER){ // 模式2/3
  1397. get_right_token(status, list, bool_not, right); // 回调右边
  1398. if(right.type != NON_bool_not){
  1399. paser_error("Don't get a bool_not");
  1400. }
  1401. // 逻辑操作
  1402. new_token.type = NON_bool_and;
  1403. new_token.data_type = statement_value;
  1404. statement *code_tmp = make_statement();
  1405. code_tmp->type = operation;
  1406. code_tmp->code.operation.type = AND_func;
  1407. code_tmp->code.operation.left_exp = left.data.statement_value;
  1408. code_tmp->code.operation.right_exp = right.data.statement_value;
  1409. new_token.data.statement_value = code_tmp;
  1410. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1411. return bool_and(status, list); // 回调自己
  1412. }
  1413. else{ // 递归跳出
  1414. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1415. fprintf(status_log, "[info][grammar] (bit_notor)out\n");
  1416. back_one_token(list, left);
  1417. back_again(list, symbol);
  1418. return;
  1419. }
  1420. }
  1421. else{ // 模式1
  1422. fprintf(status_log, "[info][grammar] (bool_and)back one token to (compare)\n");
  1423. back_one_token(list, left);
  1424. get_base_token(status, list, bool_not, new_token);
  1425. if(new_token.type != NON_bool_not){
  1426. back_one_token(list, new_token); // 往回[不匹配类型]
  1427. return;
  1428. }
  1429. new_token.type = NON_bool_and;
  1430. add_node(list, new_token);
  1431. return bool_and(status, list); // 回调自己
  1432. }
  1433. }
  1434. /*
  1435. bool_not : compare
  1436. | BITNOT bool_not
  1437. */
  1438. void bool_not(p_status *status, token_node *list){
  1439. fprintf(status_log, "[info][grammar] mode status: negative\n");
  1440. token left, right, new_token;
  1441. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1442. if(left.type == NOT_PASER){ // 模式2
  1443. fprintf(status_log, "[info][grammar] (bool_not)reduce right\n");
  1444. get_right_token(status, list, bool_not, right); // 回调右边
  1445. if(right.type != NON_bool_not){
  1446. paser_error("Don't get a bool_not");
  1447. }
  1448. // 逻辑操作
  1449. new_token.type = NON_bool_not;
  1450. new_token.data_type = statement_value;
  1451. statement *code_tmp = make_statement();
  1452. code_tmp->type = operation;
  1453. code_tmp->code.operation.type = NOT_func;
  1454. code_tmp->code.operation.left_exp = NULL;
  1455. code_tmp->code.operation.right_exp = right.data.statement_value;
  1456. new_token.data.statement_value = code_tmp;
  1457. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1458. return; // 回调自己
  1459. }
  1460. else{ // 模式1
  1461. fprintf(status_log, "[info][grammar] (negative)back one token to (compare)\n");
  1462. back_one_token(list, left);
  1463. get_base_token(status, list, compare, new_token);
  1464. if(new_token.type != NON_compare){
  1465. back_one_token(list, new_token); // 往回[不匹配类型]
  1466. return;
  1467. }
  1468. new_token.type = NON_bool_not;
  1469. add_node(list, new_token);
  1470. return;
  1471. }
  1472. }
  1473. void compare(p_status *status, token_node *list){ // 多项式
  1474. fprintf(status_log, "[info][grammar] mode status: compare\n");
  1475. token left, right, symbol, new_token;
  1476. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1477. if(left.type == NON_compare){ // 模式2/3
  1478. fprintf(status_log, "[info][grammar] (compare)reduce right\n");
  1479. get_pop_token(status, list, symbol);
  1480. if(symbol.type == EQEQ_PASER || symbol.type == MOREEQ_PASER || symbol.type == LESSEQ_PASER ||
  1481. symbol.type == MORE_PASER || symbol.type == LESS_PASER || symbol.type == NOTEQ_PASER){ // 模式2/3
  1482. get_right_token(status, list, bit_notor, right); // 回调右边
  1483. if(right.type != NON_bit_notor){
  1484. paser_error("Don't get a bit_notor");
  1485. }
  1486. new_token.type = NON_compare;
  1487. new_token.data_type = statement_value;
  1488. statement *code_tmp = make_statement();
  1489. code_tmp->type = operation;
  1490. if(symbol.type == EQEQ_PASER){
  1491. code_tmp->code.operation.type = EQUAL_func;
  1492. }
  1493. else if(symbol.type == MOREEQ_PASER){
  1494. code_tmp->code.operation.type = MOREEQ_func;
  1495. }
  1496. else if(symbol.type == LESSEQ_PASER){
  1497. code_tmp->code.operation.type = LESSEQ_func;
  1498. }
  1499. else if(symbol.type == MORE_PASER){
  1500. code_tmp->code.operation.type = MORE_func;
  1501. }
  1502. else if(symbol.type == LESS_PASER){
  1503. code_tmp->code.operation.type = LESS_func;
  1504. }
  1505. else{
  1506. code_tmp->code.operation.type = NOTEQ_func;
  1507. }
  1508. code_tmp->code.operation.left_exp = left.data.statement_value;
  1509. code_tmp->code.operation.right_exp = right.data.statement_value;
  1510. new_token.data.statement_value = code_tmp;
  1511. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1512. return compare(status, list); // 回调自己
  1513. }
  1514. else{ // 递归跳出
  1515. fprintf(status_log, "[info][grammar] (compare)out\n");
  1516. back_one_token(list, left);
  1517. back_again(list, symbol);
  1518. return;
  1519. }
  1520. }
  1521. else{ // 模式1
  1522. fprintf(status_log, "[info][grammar] (compare)back one token to (bit_notor)\n");
  1523. back_one_token(list, left);
  1524. get_base_token(status, list, bit_notor, new_token);
  1525. if(new_token.type != NON_bit_notor){
  1526. back_one_token(list, new_token); // 往回[不匹配类型]
  1527. return;
  1528. }
  1529. new_token.type = NON_compare;
  1530. add_node(list, new_token);
  1531. return compare(status, list); // 回调自己
  1532. }
  1533. }
  1534. /*
  1535. bit_notor : bit_or
  1536. | bit_notor BITOR bit_or
  1537. */
  1538. void bit_notor(p_status *status, token_node *list){ // 因试分解
  1539. fprintf(status_log, "[info][grammar] mode status: bit_notor\n");
  1540. token left, right, symbol, new_token;
  1541. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1542. if(left.type == NON_bit_notor){ // 模式2/3
  1543. fprintf(status_log, "[info][grammar] (bit_notor)reduce right\n");
  1544. get_pop_token(status, list, symbol);
  1545. if(symbol.type == BITNOTOR_PASER){ // 模式2/3
  1546. get_right_token(status, list, bit_or, right); // 回调右边
  1547. if(right.type != NON_bit_or){
  1548. paser_error("Don't get a bit_or");
  1549. }
  1550. // 逻辑操作
  1551. new_token.type = NON_bit_notor;
  1552. new_token.data_type = statement_value;
  1553. statement *code_tmp = make_statement();
  1554. code_tmp->type = operation;
  1555. code_tmp->code.operation.type = BITNOTOR_func;
  1556. code_tmp->code.operation.left_exp = left.data.statement_value;
  1557. code_tmp->code.operation.right_exp = right.data.statement_value;
  1558. new_token.data.statement_value = code_tmp;
  1559. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1560. return bit_notor(status, list); // 回调自己
  1561. }
  1562. else{ // 递归跳出
  1563. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1564. fprintf(status_log, "[info][grammar] (bit_notor)out\n");
  1565. back_one_token(list, left);
  1566. back_again(list, symbol);
  1567. return;
  1568. }
  1569. }
  1570. else{ // 模式1
  1571. fprintf(status_log, "[info][grammar] (bit_notor)back one token to (bit_and)\n");
  1572. back_one_token(list, left);
  1573. get_base_token(status, list, bit_or, new_token);
  1574. if(new_token.type != NON_bit_or){
  1575. back_one_token(list, new_token); // 往回[不匹配类型]
  1576. return;
  1577. }
  1578. new_token.type = NON_bit_notor;
  1579. add_node(list, new_token);
  1580. return bit_notor(status, list); // 回调自己
  1581. }
  1582. }
  1583. /*
  1584. bit_or : bit_and
  1585. | bit_or BITOR bit_and
  1586. */
  1587. void bit_or(p_status *status, token_node *list){ // 因试分解
  1588. fprintf(status_log, "[info][grammar] mode status: bit_or\n");
  1589. token left, right, symbol, new_token;
  1590. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1591. if(left.type == NON_bit_or){ // 模式2/3
  1592. fprintf(status_log, "[info][grammar] (bit_or)reduce right\n");
  1593. get_pop_token(status, list, symbol);
  1594. if(symbol.type == BITOR_PASER){ // 模式2/3
  1595. get_right_token(status, list, bit_and, right); // 回调右边
  1596. if(right.type != NON_bit_and){
  1597. paser_error("Don't get a bit_and");
  1598. }
  1599. // 逻辑操作
  1600. new_token.type = NON_bit_or;
  1601. new_token.data_type = statement_value;
  1602. statement *code_tmp = make_statement();
  1603. code_tmp->type = operation;
  1604. code_tmp->code.operation.type = BITOR_func;
  1605. code_tmp->code.operation.left_exp = left.data.statement_value;
  1606. code_tmp->code.operation.right_exp = right.data.statement_value;
  1607. new_token.data.statement_value = code_tmp;
  1608. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1609. return bit_or(status, list); // 回调自己
  1610. }
  1611. else{ // 递归跳出
  1612. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1613. fprintf(status_log, "[info][grammar] (bit_or)out\n");
  1614. back_one_token(list, left);
  1615. back_again(list, symbol);
  1616. return;
  1617. }
  1618. }
  1619. else{ // 模式1
  1620. fprintf(status_log, "[info][grammar] (bit_or)back one token to (bit_and)\n");
  1621. back_one_token(list, left);
  1622. get_base_token(status, list, bit_and, new_token);
  1623. if(new_token.type != NON_bit_and){
  1624. back_one_token(list, new_token); // 往回[不匹配类型]
  1625. return;
  1626. }
  1627. new_token.type = NON_bit_or;
  1628. add_node(list, new_token);
  1629. return bit_or(status, list); // 回调自己
  1630. }
  1631. }
  1632. /*
  1633. bit_and : bit_move
  1634. | bit_and BITAND bit_move
  1635. */
  1636. void bit_and(p_status *status, token_node *list){ // 因试分解
  1637. fprintf(status_log, "[info][grammar] mode status: bit_and\n");
  1638. token left, right, symbol, new_token;
  1639. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1640. if(left.type == NON_bit_and){ // 模式2/3
  1641. fprintf(status_log, "[info][grammar] (factor)reduce right\n");
  1642. get_pop_token(status, list, symbol);
  1643. if(symbol.type == BITAND_PASER){ // 模式2/3
  1644. get_right_token(status, list, bit_move, right); // 回调右边
  1645. if(right.type != NON_bit_move){
  1646. paser_error("Don't get a bit_move");
  1647. }
  1648. // 逻辑操作
  1649. new_token.type = NON_bit_and;
  1650. new_token.data_type = statement_value;
  1651. statement *code_tmp = make_statement();
  1652. code_tmp->type = operation;
  1653. code_tmp->code.operation.type = BITAND_func;
  1654. code_tmp->code.operation.left_exp = left.data.statement_value;
  1655. code_tmp->code.operation.right_exp = right.data.statement_value;
  1656. new_token.data.statement_value = code_tmp;
  1657. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1658. return bit_and(status, list); // 回调自己
  1659. }
  1660. else{ // 递归跳出
  1661. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1662. fprintf(status_log, "[info][grammar] (bit_and)out\n");
  1663. back_one_token(list, left);
  1664. back_again(list, symbol);
  1665. return;
  1666. }
  1667. }
  1668. else{ // 模式1
  1669. fprintf(status_log, "[info][grammar] (bit_move)back one token to (factor)\n");
  1670. back_one_token(list, left);
  1671. get_base_token(status, list, bit_move, new_token);
  1672. if(new_token.type != NON_bit_move){
  1673. back_one_token(list, new_token); // 往回[不匹配类型]
  1674. return;
  1675. }
  1676. new_token.type = NON_bit_and;
  1677. add_node(list, new_token);
  1678. return bit_and(status, list); // 回调自己
  1679. }
  1680. }
  1681. /*
  1682. bit_move : power
  1683. | bit_move BITRIGHT factor
  1684. | bit_move BITLEFT factor
  1685. */
  1686. void bit_move(p_status *status, token_node *list){ // 因试分解
  1687. fprintf(status_log, "[info][grammar] mode status: bit_move\n");
  1688. token left, right, symbol, new_token;
  1689. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1690. if(left.type == NON_bit_move){ // 模式2/3
  1691. fprintf(status_log, "[info][grammar] (bit_move)reduce right\n");
  1692. get_pop_token(status, list, symbol);
  1693. if(symbol.type == BITRIGHT_PASER || symbol.type == BITLEFT_PASER){ // 模式2/3
  1694. get_right_token(status, list, polynomial, right); // 回调右边
  1695. if(right.type != NON_polynomial){
  1696. paser_error("Don't get a polynomial");
  1697. }
  1698. // 逻辑操作
  1699. new_token.type = NON_bit_move;
  1700. new_token.data_type = statement_value;
  1701. statement *code_tmp = make_statement();
  1702. code_tmp->type = operation;
  1703. if(symbol.type == BITRIGHT_PASER){
  1704. code_tmp->code.operation.type = BITRIGHT_func;
  1705. }
  1706. else{
  1707. code_tmp->code.operation.type = BITLEFT_func;
  1708. }
  1709. code_tmp->code.operation.left_exp = left.data.statement_value;
  1710. code_tmp->code.operation.right_exp = right.data.statement_value;
  1711. new_token.data.statement_value = code_tmp;
  1712. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1713. return bit_move(status, list); // 回调自己
  1714. }
  1715. else{ // 递归跳出
  1716. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1717. fprintf(status_log, "[info][grammar] (bit_move)out\n");
  1718. back_one_token(list, left);
  1719. back_again(list, symbol);
  1720. return;
  1721. }
  1722. }
  1723. else{ // 模式1
  1724. fprintf(status_log, "[info][grammar] (bit_move)back one token to (polynomial)\n");
  1725. back_one_token(list, left);
  1726. get_base_token(status, list, polynomial, new_token);
  1727. if(new_token.type != NON_polynomial){
  1728. back_one_token(list, new_token); // 往回[不匹配类型]
  1729. return;
  1730. }
  1731. new_token.type = NON_bit_move;
  1732. add_node(list, new_token);
  1733. return bit_move(status, list); // 回调自己
  1734. }
  1735. }
  1736. /*
  1737. polynomial : factor
  1738. | polynomial ADD factor
  1739. | polynomial SUB factor
  1740. */
  1741. void polynomial(p_status *status, token_node *list){ // 多项式
  1742. fprintf(status_log, "[info][grammar] mode status: polynomial\n");
  1743. token left, right, symbol, new_token;
  1744. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1745. if(left.type == NON_polynomial){ // 模式2/3
  1746. fprintf(status_log, "[info][grammar] (polynomial)reduce right\n");
  1747. get_pop_token(status, list, symbol);
  1748. if(symbol.type == ADD_PASER || symbol.type == SUB_PASER){ // 模式2/3
  1749. get_right_token(status, list, factor, right); // 回调右边
  1750. if(right.type != NON_factor){
  1751. paser_error("Don't get a factor");
  1752. }
  1753. new_token.type = NON_polynomial;
  1754. new_token.data_type = statement_value;
  1755. statement *code_tmp = make_statement();
  1756. code_tmp->type = operation;
  1757. if(symbol.type == ADD_PASER){
  1758. code_tmp->code.operation.type = ADD_func;
  1759. }
  1760. else{
  1761. code_tmp->code.operation.type = SUB_func;
  1762. }
  1763. code_tmp->code.operation.left_exp = left.data.statement_value;
  1764. code_tmp->code.operation.right_exp = right.data.statement_value;
  1765. new_token.data.statement_value = code_tmp;
  1766. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1767. return polynomial(status, list); // 回调自己
  1768. }
  1769. else{ // 递归跳出
  1770. fprintf(status_log, "[info][grammar] (polynomial)out\n");
  1771. back_one_token(list, left);
  1772. back_again(list, symbol);
  1773. return;
  1774. }
  1775. }
  1776. else{ // 模式1
  1777. fprintf(status_log, "[info][grammar] (polynomial)back one token to (factor)\n");
  1778. back_one_token(list, left);
  1779. get_base_token(status, list, factor, new_token);
  1780. if(new_token.type != NON_factor){
  1781. back_one_token(list, new_token); // 往回[不匹配类型]
  1782. return;
  1783. }
  1784. new_token.type = NON_polynomial;
  1785. add_node(list, new_token);
  1786. return polynomial(status, list); // 回调自己
  1787. }
  1788. }
  1789. /*
  1790. factor : power
  1791. | factor MUL power
  1792. | factor DIV power
  1793. */
  1794. void factor(p_status *status, token_node *list){ // 因试分解
  1795. fprintf(status_log, "[info][grammar] mode status: factor\n");
  1796. token left, right, symbol, new_token;
  1797. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1798. if(left.type == NON_factor){ // 模式2/3
  1799. fprintf(status_log, "[info][grammar] (factor)reduce right\n");
  1800. get_pop_token(status, list, symbol);
  1801. if(symbol.type == MUL_PASER || symbol.type == DIV_PASER || symbol.type == INTDIV_PASER || symbol.type == MOD_PASER){ // 模式2/3
  1802. get_right_token(status, list, negative, right); // 回调右边
  1803. if(right.type != NON_negative){
  1804. paser_error("Don't get a value");
  1805. }
  1806. // 逻辑操作
  1807. new_token.type = NON_factor;
  1808. new_token.data_type = statement_value;
  1809. statement *code_tmp = make_statement();
  1810. code_tmp->type = operation;
  1811. if(symbol.type == MUL_PASER){
  1812. code_tmp->code.operation.type = MUL_func;
  1813. }
  1814. else if(symbol.type == DIV_PASER){
  1815. code_tmp->code.operation.type = DIV_func;
  1816. }
  1817. else if(symbol.type == INTDIV_PASER){
  1818. code_tmp->code.operation.type = INTDIV_func;
  1819. }
  1820. else{
  1821. code_tmp->code.operation.type = MOD_func;
  1822. }
  1823. code_tmp->code.operation.left_exp = left.data.statement_value;
  1824. code_tmp->code.operation.right_exp = right.data.statement_value;
  1825. new_token.data.statement_value = code_tmp;
  1826. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1827. return factor(status, list); // 回调自己
  1828. }
  1829. else{ // 递归跳出
  1830. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1831. fprintf(status_log, "[info][grammar] (factor)out\n");
  1832. back_one_token(list, left);
  1833. back_again(list, symbol);
  1834. return;
  1835. }
  1836. }
  1837. else{ // 模式1
  1838. fprintf(status_log, "[info][grammar] (factor)back one token to (element)\n");
  1839. back_one_token(list, left);
  1840. get_base_token(status, list, negative, new_token);
  1841. if(new_token.type != NON_negative){
  1842. back_one_token(list, new_token); // 往回[不匹配类型]
  1843. return;
  1844. }
  1845. new_token.type = NON_factor;
  1846. add_node(list, new_token);
  1847. return factor(status, list); // 回调自己
  1848. }
  1849. }
  1850. /*
  1851. negative : bit_not
  1852. | SUB_PASER bit_not
  1853. | ADD_PASER bit_not
  1854. */
  1855. void negative(p_status *status, token_node *list){
  1856. fprintf(status_log, "[info][grammar] mode status: negative\n");
  1857. token left, right, new_token;
  1858. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1859. if(left.type == SUB_PASER){ // 模式2
  1860. fprintf(status_log, "[info][grammar] (bit_not)reduce right\n");
  1861. get_right_token(status, list, negative, right); // 回调右边
  1862. if(right.type != NON_negative){
  1863. paser_error("Don't get a negative");
  1864. }
  1865. // 逻辑操作
  1866. new_token.type = NON_negative;
  1867. new_token.data_type = statement_value;
  1868. statement *code_tmp = make_statement();
  1869. code_tmp->type = operation;
  1870. code_tmp->code.operation.type = NEGATIVE_func;
  1871. code_tmp->code.operation.left_exp = NULL;
  1872. code_tmp->code.operation.right_exp = right.data.statement_value;
  1873. new_token.data.statement_value = code_tmp;
  1874. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1875. return;
  1876. }
  1877. else{ // 模式1
  1878. fprintf(status_log, "[info][grammar] (negative)back one token to (bit_not)\n");
  1879. if(left.type != ADD_PASER){ // 取正运算符
  1880. back_one_token(list, left);
  1881. get_base_token(status, list, bit_not, new_token);
  1882. }
  1883. else{ // 需要safe_get_token
  1884. get_right_token(status, list, negative, new_token);
  1885. }
  1886. if(new_token.type != NON_bit_not && new_token.type != NON_negative){
  1887. back_one_token(list, new_token); // 往回[不匹配类型]
  1888. return;
  1889. }
  1890. new_token.type = NON_negative;
  1891. add_node(list, new_token);
  1892. return;
  1893. }
  1894. }
  1895. /*
  1896. bit_not : power
  1897. | BITNOT power
  1898. */
  1899. void bit_not(p_status *status, token_node *list){
  1900. fprintf(status_log, "[info][grammar] mode status: bit_not\n");
  1901. token left, right, new_token;
  1902. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1903. if(left.type == BITNOT_PASER){ // 模式2
  1904. fprintf(status_log, "[info][grammar] (bit_not)reduce right\n");
  1905. get_right_token(status, list, bit_not, right); // 回调右边
  1906. if(right.type != NON_bit_not){
  1907. paser_error("Don't get a bit_not");
  1908. }
  1909. // 逻辑操作
  1910. new_token.type = NON_bit_not;
  1911. new_token.data_type = statement_value;
  1912. statement *code_tmp = make_statement();
  1913. code_tmp->type = operation;
  1914. code_tmp->code.operation.type = BITNOT_func;
  1915. code_tmp->code.operation.left_exp = NULL;
  1916. code_tmp->code.operation.right_exp = right.data.statement_value;
  1917. new_token.data.statement_value = code_tmp;
  1918. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1919. return; // 回调自己
  1920. }
  1921. else{ // 模式1
  1922. fprintf(status_log, "[info][grammar] (bit_not)back one token to (power)\n");
  1923. back_one_token(list, left);
  1924. get_base_token(status, list, power, new_token);
  1925. if(new_token.type != NON_power){
  1926. back_one_token(list, new_token); // 往回[不匹配类型]
  1927. return;
  1928. }
  1929. new_token.type = NON_bit_not;
  1930. add_node(list, new_token);
  1931. return;
  1932. }
  1933. }
  1934. /*
  1935. power : element
  1936. | power POW element
  1937. | power LOG element
  1938. | power SQRT element
  1939. */
  1940. void power(p_status *status, token_node *list){
  1941. fprintf(status_log, "[info][grammar] mode status: power\n");
  1942. token left, right, symbol, new_token;
  1943. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  1944. if(left.type == NON_power){ // 模式2/3
  1945. fprintf(status_log, "[info][grammar] (power)reduce right\n");
  1946. get_pop_token(status, list, symbol);
  1947. if(symbol.type == POW_PASER || symbol.type == LOG_PASER || symbol.type == SQRT_PASER){ // 模式2/3/4
  1948. get_right_token(status, list, self_exp, right); // 回调右边
  1949. if(right.type != NON_self_exp){
  1950. paser_error("Don't get a self_exp");
  1951. }
  1952. // 逻辑操作
  1953. new_token.type = NON_power;
  1954. new_token.data_type = statement_value;
  1955. statement *code_tmp = make_statement();
  1956. code_tmp->type = operation;
  1957. if(symbol.type == POW_PASER){
  1958. code_tmp->code.operation.type = POW_func;
  1959. }
  1960. else if(symbol.type == LOG_PASER){
  1961. code_tmp->code.operation.type = LOG_func;
  1962. }
  1963. else{
  1964. code_tmp->code.operation.type = SQRT_func;
  1965. }
  1966. code_tmp->code.operation.left_exp = left.data.statement_value;
  1967. code_tmp->code.operation.right_exp = right.data.statement_value;
  1968. new_token.data.statement_value = code_tmp;
  1969. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  1970. return power(status, list); // 回调自己
  1971. }
  1972. else{ // 递归跳出
  1973. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  1974. fprintf(status_log, "[info][grammar] (power)out\n");
  1975. back_one_token(list, left);
  1976. back_again(list, symbol);
  1977. return;
  1978. }
  1979. }
  1980. else{ // 模式1
  1981. fprintf(status_log, "[info][grammar] (power)back one token to (element)\n");
  1982. back_one_token(list, left);
  1983. get_base_token(status, list, self_exp, new_token);
  1984. if(new_token.type != NON_self_exp){
  1985. back_one_token(list, new_token); // 往回[不匹配类型]
  1986. return;
  1987. }
  1988. new_token.type = NON_power;
  1989. add_node(list, new_token);
  1990. return power(status, list); // 回调自己
  1991. }
  1992. }
  1993. /*
  1994. self_exp : hide_list
  1995. | FADD self_exp
  1996. | FSUB self_exp
  1997. | self_exp FADD
  1998. | self_exp FSUB
  1999. */
  2000. void self_exp(p_status *status, token_node *list){ // 因试分解
  2001. fprintf(status_log, "[info][grammar] mode status: self_exp\n");
  2002. token left, right, new_token;
  2003. parameter *p_list;
  2004. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  2005. if(left.type == FADD_PASER || left.type == FSUB_PASER){ // ++a和--a
  2006. get_right_token(status, list, self_exp, right); // 递归自己,比如----a匹配为--new_token,new_token匹配为--a
  2007. if(right.type != NON_self_exp){
  2008. paser_error("Don't get self_exp");
  2009. }
  2010. statement *code_tmp = make_statement();
  2011. code_tmp->type = operation;
  2012. code_tmp->code.operation.type = (left.type == FADD_PASER) ? FADD_func : FSUB_func;
  2013. code_tmp->code.operation.left_exp = NULL;
  2014. code_tmp->code.operation.right_exp = right.data.statement_value;
  2015. new_token.data.statement_value = code_tmp;
  2016. new_token.data_type = statement_value;
  2017. new_token.type = NON_self_exp;
  2018. add_node(list, new_token); // 压入节点
  2019. return;
  2020. }
  2021. else if(left.type == NON_self_exp){
  2022. get_pop_token(status, list, right);
  2023. if(right.type == FADD_PASER || right.type == FSUB_PASER){ // a++和a--
  2024. statement *code_tmp = make_statement();
  2025. code_tmp->type = operation;
  2026. code_tmp->code.operation.type = (right.type == FADD_PASER) ? LADD_func : LSUB_func;
  2027. code_tmp->code.operation.left_exp = left.data.statement_value;
  2028. code_tmp->code.operation.right_exp = NULL;
  2029. new_token.data.statement_value = code_tmp;
  2030. new_token.data_type = statement_value;
  2031. new_token.type = NON_self_exp;
  2032. add_node(list, new_token); // 压入节点
  2033. return self_exp(status, list); // 回调自己,比如a----匹配为self_exp--,再匹配为self_exp
  2034. }
  2035. else{ // 跳出递归
  2036. back_one_token(list, left);
  2037. back_again(list, right);
  2038. return;
  2039. }
  2040. }
  2041. else{ // a--和a++
  2042. back_one_token(list,left);
  2043. get_base_token(status, list, attribute, new_token);
  2044. if(new_token.type != NON_point){
  2045. back_one_token(list, new_token); // 往回[不匹配类型]
  2046. return;
  2047. }
  2048. new_token.type = NON_self_exp;
  2049. add_node(list, new_token);
  2050. return self_exp(status, list); // 回调自己
  2051. }
  2052. }
  2053. /*
  2054. attribute : bit_or
  2055. | attribute POINT bit_or
  2056. */
  2057. void attribute(p_status *status, token_node *list){ // 因试分解
  2058. fprintf(status_log, "[info][grammar] mode status: attribute\n");
  2059. token left, right, symbol, new_token;
  2060. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  2061. if(left.type == NON_point){ // 模式2/3
  2062. fprintf(status_log, "[info][grammar] (attribute)reduce right\n");
  2063. get_pop_token(status, list, symbol);
  2064. if(symbol.type == POINT_PASER){ // 模式2/3
  2065. get_right_token(status, list, call_down, right); // 回调右边
  2066. if(right.type != NON_call_down){
  2067. paser_error("Don't get a call_down");
  2068. }
  2069. // 逻辑操作
  2070. new_token.type = NON_point;
  2071. new_token.data_type = statement_value;
  2072. statement *code_tmp = make_statement();
  2073. code_tmp->type = point;
  2074. code_tmp->code.point.base_var = left.data.statement_value;
  2075. code_tmp->code.point.child_var = right.data.statement_value;
  2076. new_token.data.statement_value = code_tmp;
  2077. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  2078. return attribute(status, list); // 回调自己
  2079. }
  2080. else{ // 递归跳出
  2081. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  2082. fprintf(status_log, "[info][grammar] (attribute)out\n");
  2083. back_one_token(list, left);
  2084. back_again(list, symbol);
  2085. return;
  2086. }
  2087. }
  2088. else{ // 模式1
  2089. fprintf(status_log, "[info][grammar] (attribute)back one token to (call_down)\n");
  2090. back_one_token(list, left);
  2091. get_base_token(status, list, call_down, new_token);
  2092. if(new_token.type != NON_call_down){
  2093. back_one_token(list, new_token); // 往回[不匹配类型]
  2094. return;
  2095. }
  2096. new_token.type = NON_point;
  2097. add_node(list, new_token);
  2098. return attribute(status, list); // 回调自己
  2099. }
  2100. }
  2101. /*
  2102. call_down : element
  2103. | call_down LI top_exp RI
  2104. */
  2105. void call_down(p_status *status, token_node *list){ // 因试分解
  2106. fprintf(status_log, "[info][grammar] mode status: call_down\n");
  2107. token left, lb_t, rb_t, new_token, parameter_t;
  2108. parameter *p_list = NULL;
  2109. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  2110. if(left.type == NON_call_down){
  2111. fprintf(status_log, "[info][grammar] (call_down)reduce right\n");
  2112. get_pop_token(status, list, lb_t);
  2113. if(lb_t.type == LI_PASER){
  2114. p_status new_status;
  2115. new_status = *status;
  2116. new_status.not_match_tuple = true;
  2117. get_right_token(&new_status, list, top_exp, parameter_t); // 回调右边
  2118. if(parameter_t.type != NON_top_exp){
  2119. paser_error("Don't get a top_exp");
  2120. }
  2121. statement *code_tmp = make_statement();
  2122. get_pop_token(status, list, rb_t);
  2123. if(rb_t.type == RI_PASER || rb_t.type == COMMA_PASER){ // a[1,2,3,4]模式
  2124. back_one_token(list, parameter_t);
  2125. back_again(list, rb_t);
  2126. get_base_token(status,list,formal_parameter,parameter_t);
  2127. if(parameter_t.type != NON_parameter){
  2128. paser_error("Don't get formal_parameter");
  2129. }
  2130. get_pop_token(status, list, rb_t); // 把rb重新弹出来
  2131. p_list = parameter_t.data.parameter_list;
  2132. code_tmp->type = down;
  2133. code_tmp->code.down.base_var = left.data.statement_value;
  2134. code_tmp->code.down.child_var = p_list;
  2135. }
  2136. else if(rb_t.type == COLON_PASER){ // a[1,2,3,4]模式
  2137. back_one_token(list, parameter_t);
  2138. back_again(list, rb_t);
  2139. p_status new_status;
  2140. new_status = *status;
  2141. new_status.is_slice = true;
  2142. get_base_token(&new_status,list,formal_parameter,parameter_t);
  2143. if(parameter_t.type != NON_parameter){
  2144. paser_error("Don't get formal_parameter");
  2145. }
  2146. get_pop_token(status, list, rb_t); // 把rb重新弹出来
  2147. if(rb_t.type != RI_PASER){
  2148. printf("rb_t.type = %d\n", rb_t.type);
  2149. goto error;
  2150. }
  2151. p_list = parameter_t.data.parameter_list;
  2152. code_tmp->type = slice;
  2153. code_tmp->code.slice.base_var = left.data.statement_value;
  2154. code_tmp->code.slice.value = p_list;
  2155. }
  2156. else{
  2157. free(code_tmp);
  2158. error: paser_error("Don't get ']', ':' or ','");
  2159. }
  2160. // 逻辑操作
  2161. new_token.type = NON_call_down;
  2162. new_token.data_type = statement_value;
  2163. new_token.data.statement_value = code_tmp;
  2164. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  2165. return call_down(status, list); // 回调自己
  2166. }
  2167. else{ // 递归跳出
  2168. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  2169. fprintf(status_log, "[info][grammar] (call_back_)out\n");
  2170. back_one_token(list, left);
  2171. back_again(list, lb_t);
  2172. return;
  2173. }
  2174. }
  2175. else{ // 模式1
  2176. fprintf(status_log, "[info][grammar] (call_down)back one token to (call_back_)\n");
  2177. back_one_token(list, left);
  2178. get_base_token(status, list, call_back_, new_token);
  2179. if(new_token.type != NON_call){
  2180. back_one_token(list, new_token); // 往回[不匹配类型]
  2181. return;
  2182. }
  2183. new_token.type = NON_call_down;
  2184. add_node(list, new_token);
  2185. return call_down(status, list); // 回调自己
  2186. }
  2187. }
  2188. /*
  2189. call_back_ : bool_or
  2190. | call_back_ LB RB
  2191. */
  2192. void call_back_(p_status *status, token_node *list){ // 因试分解
  2193. fprintf(status_log, "[info][grammar] mode status: call_back_\n");
  2194. token left, symbol, rb_t, new_token, parameter_t;
  2195. parameter *p_list;
  2196. left = pop_node(list); // 先弹出一个token 检查token的类型:区分是模式1,还是模式2/3
  2197. if(left.type == NON_call){
  2198. fprintf(status_log, "[info][grammar] (call_back_)reduce right\n");
  2199. get_pop_token(status, list, symbol);
  2200. if(symbol.type == LB_PASER && !status->not_match_call){
  2201. get_pop_token(status, list, rb_t);
  2202. if(rb_t.type != RB_PASER){ // 带参数
  2203. back_again(list, rb_t);
  2204. p_status new_status = *status; // 继承file_p等值
  2205. reset_status(new_status); // 不会影响 *staus
  2206. new_status.not_match_tuple = true;
  2207. new_status.is_left = false;
  2208. get_right_token(&new_status,list,formal_parameter,parameter_t);
  2209. if(parameter_t.type != NON_parameter){
  2210. paser_error("Don't get formal_parameter");
  2211. }
  2212. printf("rb_t.type = %d\n", rb_t.type);
  2213. get_pop_token(status, list, rb_t);
  2214. if(rb_t.type != RB_PASER){
  2215. paser_error("Don't get ')'[2]");
  2216. }
  2217. p_list = parameter_t.data.parameter_list;
  2218. }
  2219. else{
  2220. p_list = NULL; // 没参数
  2221. }
  2222. // 逻辑操作
  2223. new_token.type = NON_call;
  2224. new_token.data_type = statement_value;
  2225. statement *code_tmp = make_statement();
  2226. code_tmp->type = call;
  2227. code_tmp->code.call.func = left.data.statement_value;
  2228. code_tmp->code.call.parameter_list = p_list;
  2229. new_token.data.statement_value = code_tmp;
  2230. add_node(list, new_token); // 压入节点[弹出3个压入1个]
  2231. return call_back_(status, list); // 回调自己
  2232. }
  2233. else{ // 递归跳出
  2234. // 回退,也就是让下一次pop的时候读取到的是left而不是symbol
  2235. fprintf(status_log, "[info][grammar] (call_back_)out\n");
  2236. back_one_token(list, left);
  2237. back_again(list, symbol);
  2238. return;
  2239. }
  2240. }
  2241. else{ // 模式1
  2242. fprintf(status_log, "[info][grammar] (call_back_)back one token to (element)\n");
  2243. back_one_token(list, left);
  2244. get_base_token(status, list, element, new_token);
  2245. if(new_token.type != NON_element){
  2246. back_one_token(list, new_token); // 往回[不匹配类型]
  2247. return;
  2248. }
  2249. new_token.type = NON_call;
  2250. add_node(list, new_token);
  2251. return call_back_(status, list); // 回调自己
  2252. }
  2253. }
  2254. /*
  2255. element : number
  2256. | LB top_exp RB
  2257. */
  2258. void element(p_status *status, token_node *list){ // 数字归约
  2259. fprintf(status_log, "[info][grammar] mode status: element\n");
  2260. token gett, new_token;
  2261. gett = pop_node(list); // 取得一个token
  2262. if(gett.type == LB_PASER){ // 模式3
  2263. fprintf(status_log, "[info][grammar] (element)get LB\n");
  2264. p_status new_status = *status; // 继承file_p等值
  2265. reset_status(new_status); // 不会影响 *staus
  2266. new_status.ignore_enter = true; // 括号内忽略回车
  2267. get_right_token(&new_status, list, top_exp, new_token);
  2268. if(new_token.type == RB_PASER){
  2269. statement *code_tmp = make_statement(); // 默认
  2270. new_token.data_type = statement_value;
  2271. new_token.data.statement_value = code_tmp;
  2272. goto return_back;
  2273. }
  2274. else if(new_token.type != NON_top_exp){
  2275. paser_error("Don't get 'top_exp'");
  2276. }
  2277. token rb;
  2278. get_pop_token(status, list ,rb);
  2279. if(rb.type != RB_PASER){ // 匹配失败
  2280. paser_error("Don't get ')'");
  2281. }
  2282. return_back:
  2283. new_token.type = NON_element;
  2284. add_node(list, new_token); // 压入节点
  2285. return;
  2286. }
  2287. else if(gett.type == VAR_PASER){ // a
  2288. back_one_token(list, gett);
  2289. get_base_token(status, list, var_token, new_token);
  2290. if(new_token.type != NON_base_var){
  2291. back_one_token(list, new_token); // 往回[不匹配类型]
  2292. return;
  2293. }
  2294. new_token.type = NON_element;
  2295. add_node(list, new_token);
  2296. return;
  2297. }
  2298. else if(gett.type == SVAR_PASER){ // a
  2299. back_one_token(list, gett);
  2300. get_base_token(status, list, svar_token, new_token);
  2301. if(new_token.type != NON_svar){
  2302. back_one_token(list, new_token); // 往回[不匹配类型]
  2303. return;
  2304. }
  2305. new_token.type = NON_element;
  2306. add_node(list, new_token);
  2307. return;
  2308. }
  2309. else if(gett.type == LP_PASER){ // dict
  2310. back_one_token(list, gett);
  2311. p_status new_status = *status; // 继承file_p等值
  2312. reset_status(new_status); // 不会影响 *staus
  2313. new_status.ignore_enter = true; // 括号内忽略回车
  2314. get_base_token(&new_status,list,dict_,new_token); // 不需要safe_get_token
  2315. if(new_token.type != NON_dict){
  2316. paser_error("Don't get a dict_");
  2317. }
  2318. new_token.type = NON_element;
  2319. add_node(list, new_token);
  2320. return;
  2321. }
  2322. else if(gett.type == LI_PASER){ // [1]a或[1]列表或[1,2,3,4]列表
  2323. token exp_token, rb, tmp_var;
  2324. p_status new_status;
  2325. new_status = *status;
  2326. new_status.match_list = true; // 防止top_exp收走逗号
  2327. new_status.not_match_tuple = true;
  2328. new_status.ignore_enter = true; // 括号内忽略回车
  2329. get_right_token(&new_status, list, top_exp, exp_token);
  2330. if(exp_token.type == RI_PASER){ //可以认定为空list
  2331. back_one_token(list, gett);
  2332. back_again(list, exp_token);
  2333. get_base_token(status,list,list_,new_token); // 返回空列表
  2334. if(new_token.type != NON_list){
  2335. paser_error("Don't get a list_");
  2336. }
  2337. goto back;
  2338. }
  2339. else if(exp_token.type != NON_top_exp){
  2340. paser_error("Don't get 'top_exp'");
  2341. }
  2342. get_pop_token(status, list ,rb);
  2343. if(rb.type == RI_PASER){ // 匹配失败 TODO:: 检查是不是[1,2,3,4]的列表类型
  2344. get_pop_token(status, list ,tmp_var);
  2345. if(tmp_var.type == VAR_PASER){ // a
  2346. back_one_token(list, tmp_var);
  2347. get_base_token(status, list, var_token, new_token);
  2348. if(new_token.type != NON_base_var){
  2349. paser_error("Don't get var");
  2350. }
  2351. new_token.data.statement_value->code.base_var.from = exp_token.data.statement_value;
  2352. goto back;
  2353. }
  2354. else if(tmp_var.type == SVAR_PASER){ // a
  2355. back_one_token(list, tmp_var);
  2356. get_base_token(status, list, svar_token, new_token);
  2357. if(new_token.type != NON_svar){
  2358. paser_error("Don't get svar");
  2359. }
  2360. new_token.data.statement_value->code.base_svar.from = exp_token.data.statement_value;
  2361. goto back;
  2362. }
  2363. else{
  2364. // back again连用的时候要倒过来使用
  2365. /* 原因:
  2366. 先back_one_token的时候,token流变成
  2367. <之前的> - <A> - <NULL[seek/index]>
  2368. 先back_again的时候,token流变成
  2369. <之前的> - <A> - <B[seek]> - <NULL[index]>
  2370. 再back_again的时候,token流变成
  2371. <之前的> - <A> - <C[seek]> - <B> - <NULL[index]>
  2372. 其实还有一种解决方法:
  2373. 连用三次back_one_token
  2374. 然后再用两次back_token手动回退
  2375. */
  2376. back_one_token(list, gett);
  2377. back_again(list, tmp_var);
  2378. back_again(list, rb);
  2379. back_again(list, exp_token);
  2380. get_base_token(&new_status,list,list_,new_token); // 不需要safe_get_token
  2381. if(new_token.type != NON_list){
  2382. paser_error("Don't get a list_");
  2383. }
  2384. goto back;
  2385. }
  2386. }
  2387. else{
  2388. back_one_token(list, gett);
  2389. back_again(list, rb);
  2390. back_again(list, exp_token);
  2391. get_base_token(&new_status,list,list_,new_token); // 不需要safe_get_token
  2392. if(new_token.type != NON_list){
  2393. paser_error("Don't get a list_");
  2394. }
  2395. goto back;
  2396. }
  2397. back:
  2398. new_token.type = NON_element;
  2399. add_node(list, new_token);
  2400. return;
  2401. }
  2402. else{
  2403. fprintf(status_log, "[info][grammar] (element)back one token to (paser_value)\n");
  2404. back_one_token(list, gett);
  2405. get_base_token(status, list, paser_value, new_token);
  2406. if(new_token.type != NON_base_value){
  2407. back_one_token(list, new_token); // 往回[不匹配类型]
  2408. return;
  2409. }
  2410. new_token.type = NON_element;
  2411. add_node(list, new_token);
  2412. return;
  2413. }
  2414. }
  2415. /*
  2416. list_ : LI formal_parameter RI
  2417. */
  2418. void list_(p_status *status, token_node *list){ // 数字归约
  2419. fprintf(status_log, "[info][grammar] mode status: list_\n");
  2420. token gett, list_core, ri_t, new_token;
  2421. parameter *base = NULL;
  2422. gett = pop_node(list); // 取得一个token
  2423. if(gett.type == LI_PASER){ // var类型
  2424. p_status new_status;
  2425. new_status = *status;
  2426. new_status.match_list = true;
  2427. new_status.not_match_tuple = true;
  2428. get_right_token(&new_status,list,formal_parameter,list_core);
  2429. if(list_core.type == RI_PASER){ // 空列表
  2430. base = NULL;
  2431. goto make_list;
  2432. }
  2433. else if(list_core.type == NON_parameter){
  2434. base = list_core.data.parameter_list;
  2435. }
  2436. else{
  2437. paser_error("Don't get formal_parameter");
  2438. }
  2439. get_pop_token(status,list,ri_t);
  2440. if(ri_t.type != RI_PASER){
  2441. paser_error("Don't get ']'");
  2442. }
  2443. make_list:
  2444. new_token.type = NON_list;
  2445. statement *code_tmp = make_statement();
  2446. code_tmp->type = base_list;
  2447. code_tmp->code.base_list.value = base;
  2448. new_token.data.statement_value = code_tmp;
  2449. new_token.data_type = statement_value;
  2450. fprintf(status_log, "[info][grammar] (list_)out\n");
  2451. add_node(list, new_token); // 压入节点
  2452. return;
  2453. }
  2454. else{ // 不是期望值
  2455. fprintf(status_log, "[info][grammar] (list_)back one token\n");
  2456. back_one_token(list, gett);
  2457. return;
  2458. }
  2459. }
  2460. /*
  2461. dict_ : LP formal_parameter RP
  2462. */
  2463. void dict_(p_status *status, token_node *list){ // 数字归约
  2464. fprintf(status_log, "[info][grammar] mode status: dict_\n");
  2465. token gett, dict_core, rp_t, new_token;
  2466. parameter *base = NULL;
  2467. gett = pop_node(list); // 取得一个token
  2468. if(gett.type == LP_PASER){ // var类型
  2469. p_status new_status;
  2470. new_status = *status;
  2471. new_status.match_dict = true;
  2472. new_status.not_match_tuple = true;
  2473. get_right_token(&new_status,list,formal_parameter,dict_core);
  2474. if(dict_core.type == RP_PASER){ // 空列表
  2475. base = NULL;
  2476. goto make_dict;
  2477. }
  2478. else if(dict_core.type == NON_parameter){
  2479. base = dict_core.data.parameter_list;
  2480. }
  2481. else{
  2482. paser_error("Don't get formal_parameter");
  2483. }
  2484. get_pop_token(status,list,rp_t);
  2485. if(rp_t.type != RP_PASER){
  2486. paser_error("Don't get '}'");
  2487. }
  2488. make_dict:
  2489. new_token.type = NON_dict;
  2490. statement *code_tmp = make_statement();
  2491. code_tmp->type = base_dict;
  2492. code_tmp->code.base_dict.value = base;
  2493. new_token.data.statement_value = code_tmp;
  2494. new_token.data_type = statement_value;
  2495. fprintf(status_log, "[info][grammar] (dict_)out\n");
  2496. add_node(list, new_token); // 压入节点
  2497. return;
  2498. }
  2499. else{ // 不是期望值
  2500. fprintf(status_log, "[info][grammar] (dict_)back one token\n");
  2501. back_one_token(list, gett);
  2502. return;
  2503. }
  2504. }
  2505. void svar_token(p_status *status, token_node *list){ // 数字归约
  2506. fprintf(status_log, "[info][grammar] mode status: svar_token\n");
  2507. token gett, var_t, new_token;
  2508. gett = pop_node(list); // 取得一个token
  2509. if(gett.type == SVAR_PASER){ // var类型
  2510. new_token.type = NON_svar;
  2511. get_right_token(status, list, element, var_t);
  2512. if(var_t.type != NON_element){
  2513. paser_error("Don't get element[1]");
  2514. }
  2515. statement *code_tmp = make_statement();
  2516. code_tmp->type = base_svar;
  2517. code_tmp->code.base_svar.var = var_t.data.statement_value;
  2518. code_tmp->code.base_svar.from = NULL;
  2519. new_token.data.statement_value = code_tmp;
  2520. new_token.data_type = statement_value;
  2521. fprintf(status_log, "[info][grammar] (svar_token)out\n");
  2522. add_node(list, new_token); // 压入节点
  2523. return;
  2524. }
  2525. else{ // 不是期望值
  2526. fprintf(status_log, "[info][grammar] (svar_token)back one token\n");
  2527. back_one_token(list, gett);
  2528. return;
  2529. }
  2530. }
  2531. /*
  2532. var_token : VAR
  2533. */
  2534. void var_token(p_status *status, token_node *list){ // 数字归约
  2535. fprintf(status_log, "[info][grammar] mode status: var_token\n");
  2536. token gett, new_token;
  2537. gett = pop_node(list); // 取得一个token
  2538. if(gett.type == VAR_PASER){ // var类型
  2539. new_token.type = NON_base_var;
  2540. statement *code_tmp = make_statement();
  2541. code_tmp->type = base_var;
  2542. code_tmp->code.base_var.var_name = gett.data.text;
  2543. code_tmp->code.base_var.from = NULL;
  2544. new_token.data.statement_value = code_tmp;
  2545. new_token.data_type = statement_value;
  2546. fprintf(status_log, "[info][grammar] (var_token)out\n");
  2547. add_node(list, new_token); // 压入节点
  2548. return;
  2549. }
  2550. else{ // 不是期望值
  2551. fprintf(status_log, "[info][grammar] (var_token)back one token\n");
  2552. back_one_token(list, gett);
  2553. return;
  2554. }
  2555. }
  2556. /*
  2557. number : INT_PASER
  2558. | DOUBLE_PASER
  2559. */
  2560. void paser_value(p_status *status, token_node *list){ // 数字归约
  2561. fprintf(status_log, "[info][grammar] mode status: paser_value\n");
  2562. token gett, new_token;
  2563. gett = pop_node(list); // 取得一个token
  2564. if(gett.type == INT_PASER){ // int类型
  2565. new_token.type = NON_base_value;
  2566. GWARF_value tmp_value;
  2567. tmp_value.type = INT_value;
  2568. tmp_value.value.int_value = atoi(gett.data.text);
  2569. statement *code_tmp = make_statement();
  2570. code_tmp->type = call;
  2571. code_tmp->code.call.func = pack_call_name("int", NULL);
  2572. code_tmp->code.call.parameter_list = pack_value_parameter(tmp_value);
  2573. new_token.data.statement_value = code_tmp;
  2574. new_token.data_type = statement_value;
  2575. }
  2576. else if(gett.type == DOUBLE_PASER){
  2577. new_token.type = NON_base_value;
  2578. GWARF_value tmp_value;
  2579. tmp_value.type = NUMBER_value;
  2580. tmp_value.value.double_value = atof(gett.data.text);
  2581. statement *code_tmp = make_statement();
  2582. code_tmp->type = call;
  2583. code_tmp->code.call.func = pack_call_name("double", NULL);
  2584. code_tmp->code.call.parameter_list = pack_value_parameter(tmp_value);
  2585. new_token.data.statement_value = code_tmp;
  2586. new_token.data_type = statement_value;
  2587. }
  2588. else if(gett.type == STR_PASER){
  2589. new_token.type = NON_base_value;
  2590. GWARF_value tmp_value;
  2591. tmp_value.type = STRING_value;
  2592. if(gett.data.text == NULL){
  2593. tmp_value.value.string = "";
  2594. }
  2595. else{
  2596. tmp_value.value.string = gett.data.text;
  2597. }
  2598. printf("tmp_value.value.string = %s, %s\n", tmp_value.value.string, gett.data.text);
  2599. statement *code_tmp = make_statement();
  2600. code_tmp->type = call;
  2601. code_tmp->code.call.func = pack_call_name("str", NULL);
  2602. code_tmp->code.call.parameter_list = pack_value_parameter(tmp_value);
  2603. new_token.data.statement_value = code_tmp;
  2604. new_token.data_type = statement_value;
  2605. goto not_free;
  2606. // printf("[info][grammar] (paser_value)get str: %s\n", tmp_value.value.string);
  2607. }
  2608. else if(gett.type == TRUE_PASER || gett.type == FALSE_PASER){
  2609. new_token.type = NON_base_value;
  2610. GWARF_value tmp_value;
  2611. tmp_value.type = BOOL_value;
  2612. if(gett.type == TRUE_PASER){
  2613. tmp_value.value.bool_value = true;
  2614. }
  2615. else{
  2616. tmp_value.value.bool_value = false;
  2617. }
  2618. statement *code_tmp = make_statement();
  2619. code_tmp->type = call;
  2620. code_tmp->code.call.func = pack_call_name("bool", NULL);
  2621. code_tmp->code.call.parameter_list = pack_value_parameter(tmp_value);
  2622. new_token.data.statement_value = code_tmp;
  2623. new_token.data_type = statement_value;
  2624. }
  2625. else if(gett.type == NONE_PASER){
  2626. new_token.type = NON_base_value;
  2627. statement *code_tmp = make_statement();
  2628. code_tmp->type = base_value;
  2629. code_tmp->code.base_value.value.type = NULL_value;
  2630. code_tmp->code.base_value.value.value.int_value = 0;
  2631. new_token.data.statement_value = code_tmp;
  2632. new_token.data_type = statement_value;
  2633. }
  2634. else{ // 不是期望值
  2635. fprintf(status_log, "[info][grammar] (paser_value)back one token\n");
  2636. back_one_token(list, gett);
  2637. return;
  2638. }
  2639. free(gett.data.text); // 释放字符串
  2640. not_free:
  2641. fprintf(status_log, "[info][grammar] (paser_value)add one token\n");
  2642. add_node(list, new_token); // 压入节点
  2643. }
  2644. void paser_error(char *text){
  2645. fprintf(status_log, "[error][grammar] paser error : %s\n\n", text);
  2646. printf("[error][grammar] paser error : %s\n\n", text);
  2647. exit(1);
  2648. }