syntax.c 108 KB

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