syntax.c 109 KB

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