pascal.c 167 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191
  1. /* A packrat parser generated by PackCC 1.5.0 */
  2. #ifdef _MSC_VER
  3. #undef _CRT_SECURE_NO_WARNINGS
  4. #define _CRT_SECURE_NO_WARNINGS
  5. #endif /* _MSC_VER */
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <string.h>
  9. #ifndef _MSC_VER
  10. #if defined __GNUC__ && defined _WIN32 /* MinGW */
  11. #ifndef PCC_USE_SYSTEM_STRNLEN
  12. #define strnlen(str, maxlen) pcc_strnlen(str, maxlen)
  13. static size_t pcc_strnlen(const char *str, size_t maxlen) {
  14. size_t i;
  15. for (i = 0; i < maxlen && str[i]; i++);
  16. return i;
  17. }
  18. #endif /* !PCC_USE_SYSTEM_STRNLEN */
  19. #endif /* defined __GNUC__ && defined _WIN32 */
  20. #endif /* !_MSC_VER */
  21. #define PCC_DBG_EVALUATE 0
  22. #define PCC_DBG_MATCH 1
  23. #define PCC_DBG_NOMATCH 2
  24. #include "pascal.h"
  25. #include <stdio.h>
  26. static const char *dbg_str[] = { "Evaluating rule", "Matched rule", "Abandoning rule" };
  27. #define PCC_DEBUG(event, rule, level, pos, buffer, length) \
  28. fprintf(stdout, "%*s%s %s @%d [%.*s]\n", (int)(level * 2), "", dbg_str[event], rule, (int)pos, (int)length, buffer); fflush(stdout)
  29. /* NOTE: To guarantee the output order, stderr, which can lead a race condition with stdout, is not used. */
  30. #ifndef PCC_BUFFERSIZE
  31. #define PCC_BUFFERSIZE 256
  32. #endif /* !PCC_BUFFERSIZE */
  33. #ifndef PCC_ARRAYSIZE
  34. #define PCC_ARRAYSIZE 2
  35. #endif /* !PCC_ARRAYSIZE */
  36. #define VOID_VALUE (~(size_t)0)
  37. typedef enum pcc_bool_tag {
  38. PCC_FALSE = 0,
  39. PCC_TRUE
  40. } pcc_bool_t;
  41. typedef struct pcc_char_array_tag {
  42. char *buf;
  43. size_t max;
  44. size_t len;
  45. } pcc_char_array_t;
  46. typedef struct pcc_range_tag {
  47. size_t start;
  48. size_t end;
  49. } pcc_range_t;
  50. typedef int pcc_value_t;
  51. typedef void *pcc_auxil_t;
  52. typedef struct pcc_value_table_tag {
  53. pcc_value_t *buf;
  54. size_t max;
  55. size_t len;
  56. } pcc_value_table_t;
  57. typedef struct pcc_value_refer_table_tag {
  58. pcc_value_t **buf;
  59. size_t max;
  60. size_t len;
  61. } pcc_value_refer_table_t;
  62. typedef struct pcc_capture_tag {
  63. pcc_range_t range;
  64. char *string; /* mutable */
  65. } pcc_capture_t;
  66. typedef struct pcc_capture_table_tag {
  67. pcc_capture_t *buf;
  68. size_t max;
  69. size_t len;
  70. } pcc_capture_table_t;
  71. typedef struct pcc_capture_const_table_tag {
  72. const pcc_capture_t **buf;
  73. size_t max;
  74. size_t len;
  75. } pcc_capture_const_table_t;
  76. typedef struct pcc_thunk_tag pcc_thunk_t;
  77. typedef struct pcc_thunk_array_tag pcc_thunk_array_t;
  78. typedef void (*pcc_action_t)(pascal_context_t *, pcc_thunk_t *, pcc_value_t *);
  79. typedef enum pcc_thunk_type_tag {
  80. PCC_THUNK_LEAF,
  81. PCC_THUNK_NODE
  82. } pcc_thunk_type_t;
  83. typedef struct pcc_thunk_leaf_tag {
  84. pcc_value_refer_table_t values;
  85. pcc_capture_const_table_t capts;
  86. pcc_capture_t capt0;
  87. pcc_action_t action;
  88. } pcc_thunk_leaf_t;
  89. typedef struct pcc_thunk_node_tag {
  90. const pcc_thunk_array_t *thunks; /* just a reference */
  91. pcc_value_t *value; /* just a reference */
  92. } pcc_thunk_node_t;
  93. typedef union pcc_thunk_data_tag {
  94. pcc_thunk_leaf_t leaf;
  95. pcc_thunk_node_t node;
  96. } pcc_thunk_data_t;
  97. struct pcc_thunk_tag {
  98. pcc_thunk_type_t type;
  99. pcc_thunk_data_t data;
  100. };
  101. struct pcc_thunk_array_tag {
  102. pcc_thunk_t **buf;
  103. size_t max;
  104. size_t len;
  105. };
  106. typedef struct pcc_thunk_chunk_tag {
  107. pcc_value_table_t values;
  108. pcc_capture_table_t capts;
  109. pcc_thunk_array_t thunks;
  110. size_t pos; /* the starting position in the character buffer */
  111. } pcc_thunk_chunk_t;
  112. typedef struct pcc_lr_entry_tag pcc_lr_entry_t;
  113. typedef enum pcc_lr_answer_type_tag {
  114. PCC_LR_ANSWER_LR,
  115. PCC_LR_ANSWER_CHUNK
  116. } pcc_lr_answer_type_t;
  117. typedef union pcc_lr_answer_data_tag {
  118. pcc_lr_entry_t *lr;
  119. pcc_thunk_chunk_t *chunk;
  120. } pcc_lr_answer_data_t;
  121. typedef struct pcc_lr_answer_tag pcc_lr_answer_t;
  122. struct pcc_lr_answer_tag {
  123. pcc_lr_answer_type_t type;
  124. pcc_lr_answer_data_t data;
  125. size_t pos; /* the absolute position in the input */
  126. pcc_lr_answer_t *hold;
  127. };
  128. typedef pcc_thunk_chunk_t *(*pcc_rule_t)(pascal_context_t *);
  129. typedef struct pcc_rule_set_tag {
  130. pcc_rule_t *buf;
  131. size_t max;
  132. size_t len;
  133. } pcc_rule_set_t;
  134. typedef struct pcc_lr_head_tag pcc_lr_head_t;
  135. struct pcc_lr_head_tag {
  136. pcc_rule_t rule;
  137. pcc_rule_set_t invol;
  138. pcc_rule_set_t eval;
  139. pcc_lr_head_t *hold;
  140. };
  141. typedef struct pcc_lr_memo_tag {
  142. pcc_rule_t rule;
  143. pcc_lr_answer_t *answer;
  144. } pcc_lr_memo_t;
  145. typedef struct pcc_lr_memo_map_tag {
  146. pcc_lr_memo_t *buf;
  147. size_t max;
  148. size_t len;
  149. } pcc_lr_memo_map_t;
  150. typedef struct pcc_lr_table_entry_tag {
  151. pcc_lr_head_t *head; /* just a reference */
  152. pcc_lr_memo_map_t memos;
  153. pcc_lr_answer_t *hold_a;
  154. pcc_lr_head_t *hold_h;
  155. } pcc_lr_table_entry_t;
  156. typedef struct pcc_lr_table_tag {
  157. pcc_lr_table_entry_t **buf;
  158. size_t max;
  159. size_t len;
  160. } pcc_lr_table_t;
  161. struct pcc_lr_entry_tag {
  162. pcc_rule_t rule;
  163. pcc_thunk_chunk_t *seed; /* just a reference */
  164. pcc_lr_head_t *head; /* just a reference */
  165. };
  166. typedef struct pcc_lr_stack_tag {
  167. pcc_lr_entry_t **buf;
  168. size_t max;
  169. size_t len;
  170. } pcc_lr_stack_t;
  171. struct pascal_context_tag {
  172. size_t pos; /* the position in the input of the first character currently buffered */
  173. size_t cur; /* the current parsing position in the character buffer */
  174. size_t level;
  175. pcc_char_array_t buffer;
  176. pcc_lr_table_t lrtable;
  177. pcc_lr_stack_t lrstack;
  178. pcc_auxil_t auxil;
  179. };
  180. #ifndef PCC_ERROR
  181. #define PCC_ERROR(auxil) pcc_error()
  182. static void pcc_error(void) {
  183. fprintf(stderr, "Syntax error\n");
  184. exit(1);
  185. }
  186. #endif /* !PCC_ERROR */
  187. #ifndef PCC_GETCHAR
  188. #define PCC_GETCHAR(auxil) getchar()
  189. #endif /* !PCC_GETCHAR */
  190. #ifndef PCC_MALLOC
  191. #define PCC_MALLOC(auxil, size) pcc_malloc_e(size)
  192. static void *pcc_malloc_e(size_t size) {
  193. void *const p = malloc(size);
  194. if (p == NULL) {
  195. fprintf(stderr, "Out of memory\n");
  196. exit(1);
  197. }
  198. return p;
  199. }
  200. #endif /* !PCC_MALLOC */
  201. #ifndef PCC_REALLOC
  202. #define PCC_REALLOC(auxil, ptr, size) pcc_realloc_e(ptr, size)
  203. static void *pcc_realloc_e(void *ptr, size_t size) {
  204. void *const p = realloc(ptr, size);
  205. if (p == NULL) {
  206. fprintf(stderr, "Out of memory\n");
  207. exit(1);
  208. }
  209. return p;
  210. }
  211. #endif /* !PCC_REALLOC */
  212. #ifndef PCC_FREE
  213. #define PCC_FREE(auxil, ptr) free(ptr)
  214. #endif /* !PCC_FREE */
  215. #ifndef PCC_DEBUG
  216. #define PCC_DEBUG(event, rule, level, pos, buffer, length) ((void)0)
  217. #endif /* !PCC_DEBUG */
  218. static char *pcc_strndup_e(pcc_auxil_t auxil, const char *str, size_t len) {
  219. const size_t m = strnlen(str, len);
  220. char *const s = (char *)PCC_MALLOC(auxil, m + 1);
  221. if (auxil) { }
  222. memcpy(s, str, m);
  223. s[m] = '\0';
  224. return s;
  225. }
  226. static void pcc_char_array__init(pcc_auxil_t auxil, pcc_char_array_t *array, size_t max) {
  227. array->len = 0;
  228. array->max = max;
  229. if (auxil) { }
  230. array->buf = (char *)PCC_MALLOC(auxil, array->max);
  231. }
  232. static void pcc_char_array__add(pcc_auxil_t auxil, pcc_char_array_t *array, char ch) {
  233. if (array->max <= array->len) {
  234. const size_t n = array->len + 1;
  235. size_t m = array->max;
  236. if (m == 0) m = 1;
  237. while (m < n && m != 0) m <<= 1;
  238. if (m == 0) m = n;
  239. if (auxil) { }
  240. array->buf = (char *)PCC_REALLOC(auxil, array->buf, m);
  241. array->max = m;
  242. }
  243. array->buf[array->len++] = ch;
  244. }
  245. static void pcc_char_array__term(pcc_auxil_t auxil, pcc_char_array_t *array) {
  246. PCC_FREE(auxil, array->buf);
  247. }
  248. static void pcc_value_table__init(pcc_auxil_t auxil, pcc_value_table_t *table, size_t max) {
  249. table->len = 0;
  250. table->max = max;
  251. table->buf = (pcc_value_t *)PCC_MALLOC(auxil, sizeof(pcc_value_t) * table->max);
  252. if (auxil) { }
  253. return;
  254. }
  255. static void pcc_value_table__resize(pcc_auxil_t auxil, pcc_value_table_t *table, size_t len) {
  256. if (table->max < len) {
  257. size_t m = table->max;
  258. if (m == 0) m = 1;
  259. while (m < len && m != 0) m <<= 1;
  260. if (m == 0) m = len;
  261. table->buf = (pcc_value_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t) * m);
  262. table->max = m;
  263. }
  264. table->len = len;
  265. }
  266. static void pcc_value_table__term(pcc_auxil_t auxil, pcc_value_table_t *table) {
  267. PCC_FREE(auxil, table->buf);
  268. }
  269. static void pcc_value_refer_table__init(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t max) {
  270. table->len = 0;
  271. table->max = max;
  272. table->buf = (pcc_value_t **)PCC_MALLOC(auxil, sizeof(pcc_value_t *) * table->max);
  273. }
  274. static void pcc_value_refer_table__resize(pcc_auxil_t auxil, pcc_value_refer_table_t *table, size_t len) {
  275. size_t i;
  276. if (table->max < len) {
  277. size_t m = table->max;
  278. if (m == 0) m = 1;
  279. while (m < len && m != 0) m <<= 1;
  280. if (m == 0) m = len;
  281. table->buf = (pcc_value_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_value_t *) * m);
  282. table->max = m;
  283. }
  284. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  285. table->len = len;
  286. }
  287. static void pcc_value_refer_table__term(pcc_auxil_t auxil, pcc_value_refer_table_t *table) {
  288. PCC_FREE(auxil, table->buf);
  289. }
  290. static void pcc_capture_table__init(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t max) {
  291. table->len = 0;
  292. table->max = max;
  293. table->buf = (pcc_capture_t *)PCC_MALLOC(auxil, sizeof(pcc_capture_t) * table->max);
  294. }
  295. static void pcc_capture_table__resize(pcc_auxil_t auxil, pcc_capture_table_t *table, size_t len) {
  296. size_t i;
  297. for (i = len; i < table->len; i++) PCC_FREE(auxil, table->buf[i].string);
  298. if (table->max < len) {
  299. size_t m = table->max;
  300. if (m == 0) m = 1;
  301. while (m < len && m != 0) m <<= 1;
  302. if (m == 0) m = len;
  303. table->buf = (pcc_capture_t *)PCC_REALLOC(auxil, table->buf, sizeof(pcc_capture_t) * m);
  304. table->max = m;
  305. }
  306. for (i = table->len; i < len; i++) {
  307. table->buf[i].range.start = 0;
  308. table->buf[i].range.end = 0;
  309. table->buf[i].string = NULL;
  310. }
  311. table->len = len;
  312. }
  313. static void pcc_capture_table__term(pcc_auxil_t auxil, pcc_capture_table_t *table) {
  314. while (table->len > 0) {
  315. table->len--;
  316. PCC_FREE(auxil, table->buf[table->len].string);
  317. }
  318. PCC_FREE(auxil, table->buf);
  319. }
  320. static void pcc_capture_const_table__init(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t max) {
  321. table->len = 0;
  322. table->max = max;
  323. table->buf = (const pcc_capture_t **)PCC_MALLOC(auxil, sizeof(const pcc_capture_t *) * table->max);
  324. }
  325. static void pcc_capture_const_table__resize(pcc_auxil_t auxil, pcc_capture_const_table_t *table, size_t len) {
  326. size_t i;
  327. if (table->max < len) {
  328. size_t m = table->max;
  329. if (m == 0) m = 1;
  330. while (m < len && m != 0) m <<= 1;
  331. if (m == 0) m = len;
  332. table->buf = (const pcc_capture_t **)PCC_REALLOC(auxil, (pcc_capture_t **)table->buf, sizeof(const pcc_capture_t *) * m);
  333. table->max = m;
  334. }
  335. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  336. table->len = len;
  337. }
  338. static void pcc_capture_const_table__term(pcc_auxil_t auxil, pcc_capture_const_table_t *table) {
  339. PCC_FREE(auxil, table->buf);
  340. }
  341. static pcc_thunk_t *pcc_thunk__create_leaf(pcc_auxil_t auxil, pcc_action_t action, size_t valuec, size_t captc) {
  342. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  343. thunk->type = PCC_THUNK_LEAF;
  344. pcc_value_refer_table__init(auxil, &thunk->data.leaf.values, valuec);
  345. pcc_value_refer_table__resize(auxil, &thunk->data.leaf.values, valuec);
  346. pcc_capture_const_table__init(auxil, &thunk->data.leaf.capts, captc);
  347. pcc_capture_const_table__resize(auxil, &thunk->data.leaf.capts, captc);
  348. thunk->data.leaf.capt0.range.start = 0;
  349. thunk->data.leaf.capt0.range.end = 0;
  350. thunk->data.leaf.capt0.string = NULL;
  351. thunk->data.leaf.action = action;
  352. return thunk;
  353. }
  354. static pcc_thunk_t *pcc_thunk__create_node(pcc_auxil_t auxil, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  355. pcc_thunk_t *const thunk = (pcc_thunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_t));
  356. thunk->type = PCC_THUNK_NODE;
  357. thunk->data.node.thunks = thunks;
  358. thunk->data.node.value = value;
  359. return thunk;
  360. }
  361. static void pcc_thunk__destroy(pcc_auxil_t auxil, pcc_thunk_t *thunk) {
  362. if (thunk == NULL) return;
  363. switch (thunk->type) {
  364. case PCC_THUNK_LEAF:
  365. PCC_FREE(auxil, thunk->data.leaf.capt0.string);
  366. pcc_capture_const_table__term(auxil, &thunk->data.leaf.capts);
  367. pcc_value_refer_table__term(auxil, &thunk->data.leaf.values);
  368. break;
  369. case PCC_THUNK_NODE:
  370. break;
  371. default: /* unknown */
  372. break;
  373. }
  374. PCC_FREE(auxil, thunk);
  375. }
  376. static void pcc_thunk_array__init(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t max) {
  377. array->len = 0;
  378. array->max = max;
  379. array->buf = (pcc_thunk_t **)PCC_MALLOC(auxil, sizeof(pcc_thunk_t *) * array->max);
  380. }
  381. static void pcc_thunk_array__add(pcc_auxil_t auxil, pcc_thunk_array_t *array, pcc_thunk_t *thunk) {
  382. if (array->max <= array->len) {
  383. const size_t n = array->len + 1;
  384. size_t m = array->max;
  385. if (m == 0) m = 1;
  386. while (m < n && m != 0) m <<= 1;
  387. if (m == 0) m = n;
  388. array->buf = (pcc_thunk_t **)PCC_REALLOC(auxil, array->buf, sizeof(pcc_thunk_t *) * m);
  389. array->max = m;
  390. }
  391. array->buf[array->len++] = thunk;
  392. }
  393. static void pcc_thunk_array__revert(pcc_auxil_t auxil, pcc_thunk_array_t *array, size_t len) {
  394. while (array->len > len) {
  395. array->len--;
  396. pcc_thunk__destroy(auxil, array->buf[array->len]);
  397. }
  398. }
  399. static void pcc_thunk_array__term(pcc_auxil_t auxil, pcc_thunk_array_t *array) {
  400. while (array->len > 0) {
  401. array->len--;
  402. pcc_thunk__destroy(auxil, array->buf[array->len]);
  403. }
  404. PCC_FREE(auxil, array->buf);
  405. }
  406. static pcc_thunk_chunk_t *pcc_thunk_chunk__create(pcc_auxil_t auxil) {
  407. pcc_thunk_chunk_t *const chunk = (pcc_thunk_chunk_t *)PCC_MALLOC(auxil, sizeof(pcc_thunk_chunk_t));
  408. pcc_value_table__init(auxil, &chunk->values, PCC_ARRAYSIZE);
  409. pcc_capture_table__init(auxil, &chunk->capts, PCC_ARRAYSIZE);
  410. pcc_thunk_array__init(auxil, &chunk->thunks, PCC_ARRAYSIZE);
  411. chunk->pos = 0;
  412. return chunk;
  413. }
  414. static void pcc_thunk_chunk__destroy(pcc_auxil_t auxil, pcc_thunk_chunk_t *chunk) {
  415. if (chunk == NULL) return;
  416. pcc_thunk_array__term(auxil, &chunk->thunks);
  417. pcc_capture_table__term(auxil, &chunk->capts);
  418. pcc_value_table__term(auxil, &chunk->values);
  419. PCC_FREE(auxil, chunk);
  420. }
  421. static void pcc_rule_set__init(pcc_auxil_t auxil, pcc_rule_set_t *set, size_t max) {
  422. set->len = 0;
  423. set->max = max;
  424. set->buf = (pcc_rule_t *)PCC_MALLOC(auxil, sizeof(pcc_rule_t) * set->max);
  425. }
  426. static size_t pcc_rule_set__index(pcc_auxil_t auxil, const pcc_rule_set_t *set, pcc_rule_t rule) {
  427. size_t i;
  428. for (i = 0; i < set->len; i++) {
  429. if (set->buf[i] == rule) return i;
  430. }
  431. return VOID_VALUE;
  432. }
  433. static pcc_bool_t pcc_rule_set__add(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  434. const size_t i = pcc_rule_set__index(auxil, set, rule);
  435. if (i != VOID_VALUE) return PCC_FALSE;
  436. if (set->max <= set->len) {
  437. const size_t n = set->len + 1;
  438. size_t m = set->max;
  439. if (m == 0) m = 1;
  440. while (m < n && m != 0) m <<= 1;
  441. if (m == 0) m = n;
  442. set->buf = (pcc_rule_t *)PCC_REALLOC(auxil, set->buf, sizeof(pcc_rule_t) * m);
  443. set->max = m;
  444. }
  445. set->buf[set->len++] = rule;
  446. return PCC_TRUE;
  447. }
  448. static pcc_bool_t pcc_rule_set__remove(pcc_auxil_t auxil, pcc_rule_set_t *set, pcc_rule_t rule) {
  449. const size_t i = pcc_rule_set__index(auxil, set, rule);
  450. if (i == VOID_VALUE) return PCC_FALSE;
  451. memmove(set->buf + i, set->buf + (i + 1), sizeof(pcc_rule_t) * (set->len - (i + 1)));
  452. return PCC_TRUE;
  453. }
  454. static void pcc_rule_set__clear(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  455. set->len = 0;
  456. }
  457. static void pcc_rule_set__copy(pcc_auxil_t auxil, pcc_rule_set_t *set, const pcc_rule_set_t *src) {
  458. size_t i;
  459. pcc_rule_set__clear(auxil, set);
  460. for (i = 0; i < src->len; i++) {
  461. pcc_rule_set__add(auxil, set, src->buf[i]);
  462. }
  463. }
  464. static void pcc_rule_set__term(pcc_auxil_t auxil, pcc_rule_set_t *set) {
  465. PCC_FREE(auxil, set->buf);
  466. }
  467. static pcc_lr_head_t *pcc_lr_head__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  468. pcc_lr_head_t *const head = (pcc_lr_head_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_head_t));
  469. head->rule = rule;
  470. pcc_rule_set__init(auxil, &head->invol, PCC_ARRAYSIZE);
  471. pcc_rule_set__init(auxil, &head->eval, PCC_ARRAYSIZE);
  472. head->hold = NULL;
  473. return head;
  474. }
  475. static void pcc_lr_head__destroy(pcc_auxil_t auxil, pcc_lr_head_t *head) {
  476. if (head == NULL) return;
  477. pcc_lr_head__destroy(auxil, head->hold);
  478. pcc_rule_set__term(auxil, &head->eval);
  479. pcc_rule_set__term(auxil, &head->invol);
  480. PCC_FREE(auxil, head);
  481. }
  482. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr);
  483. static pcc_lr_answer_t *pcc_lr_answer__create(pcc_auxil_t auxil, pcc_lr_answer_type_t type, size_t pos) {
  484. pcc_lr_answer_t *answer = (pcc_lr_answer_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_answer_t));
  485. answer->type = type;
  486. answer->pos = pos;
  487. answer->hold = NULL;
  488. switch (answer->type) {
  489. case PCC_LR_ANSWER_LR:
  490. answer->data.lr = NULL;
  491. break;
  492. case PCC_LR_ANSWER_CHUNK:
  493. answer->data.chunk = NULL;
  494. break;
  495. default: /* unknown */
  496. PCC_FREE(auxil, answer);
  497. answer = NULL;
  498. }
  499. return answer;
  500. }
  501. static void pcc_lr_answer__set_chunk(pcc_auxil_t auxil, pcc_lr_answer_t *answer, pcc_thunk_chunk_t *chunk) {
  502. pcc_lr_answer_t *const a = pcc_lr_answer__create(auxil, answer->type, answer->pos);
  503. switch (answer->type) {
  504. case PCC_LR_ANSWER_LR:
  505. a->data.lr = answer->data.lr;
  506. break;
  507. case PCC_LR_ANSWER_CHUNK:
  508. a->data.chunk = answer->data.chunk;
  509. break;
  510. default: /* unknown */
  511. break;
  512. }
  513. a->hold = answer->hold;
  514. answer->hold = a;
  515. answer->type = PCC_LR_ANSWER_CHUNK;
  516. answer->data.chunk = chunk;
  517. }
  518. static void pcc_lr_answer__destroy(pcc_auxil_t auxil, pcc_lr_answer_t *answer) {
  519. if (answer == NULL) return;
  520. pcc_lr_answer__destroy(auxil, answer->hold);
  521. switch (answer->type) {
  522. case PCC_LR_ANSWER_LR:
  523. pcc_lr_entry__destroy(auxil, answer->data.lr);
  524. break;
  525. case PCC_LR_ANSWER_CHUNK:
  526. pcc_thunk_chunk__destroy(auxil, answer->data.chunk);
  527. break;
  528. default: /* unknown */
  529. break;
  530. }
  531. PCC_FREE(auxil, answer);
  532. }
  533. static void pcc_lr_memo_map__init(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, size_t max) {
  534. map->len = 0;
  535. map->max = max;
  536. map->buf = (pcc_lr_memo_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_memo_t) * map->max);
  537. }
  538. static size_t pcc_lr_memo_map__index(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  539. size_t i;
  540. for (i = 0; i < map->len; i++) {
  541. if (map->buf[i].rule == rule) return i;
  542. }
  543. return VOID_VALUE;
  544. }
  545. static void pcc_lr_memo_map__put(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule, pcc_lr_answer_t *answer) {
  546. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  547. if (i != VOID_VALUE) {
  548. pcc_lr_answer__destroy(auxil, map->buf[i].answer);
  549. map->buf[i].answer = answer;
  550. }
  551. else {
  552. if (map->max <= map->len) {
  553. const size_t n = map->len + 1;
  554. size_t m = map->max;
  555. if (m == 0) m = 1;
  556. while (m < n && m != 0) m <<= 1;
  557. if (m == 0) m = n;
  558. map->buf = (pcc_lr_memo_t *)PCC_REALLOC(auxil, map->buf, sizeof(pcc_lr_memo_t) * m);
  559. map->max = m;
  560. }
  561. map->buf[map->len].rule = rule;
  562. map->buf[map->len].answer = answer;
  563. map->len++;
  564. }
  565. }
  566. static pcc_lr_answer_t *pcc_lr_memo_map__get(pcc_auxil_t auxil, pcc_lr_memo_map_t *map, pcc_rule_t rule) {
  567. const size_t i = pcc_lr_memo_map__index(auxil, map, rule);
  568. return (i != VOID_VALUE) ? map->buf[i].answer : NULL;
  569. }
  570. static void pcc_lr_memo_map__term(pcc_auxil_t auxil, pcc_lr_memo_map_t *map) {
  571. while (map->len > 0) {
  572. map->len--;
  573. pcc_lr_answer__destroy(auxil, map->buf[map->len].answer);
  574. }
  575. PCC_FREE(auxil, map->buf);
  576. }
  577. static pcc_lr_table_entry_t *pcc_lr_table_entry__create(pcc_auxil_t auxil) {
  578. pcc_lr_table_entry_t *const entry = (pcc_lr_table_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t));
  579. entry->head = NULL;
  580. pcc_lr_memo_map__init(auxil, &entry->memos, PCC_ARRAYSIZE);
  581. entry->hold_a = NULL;
  582. entry->hold_h = NULL;
  583. return entry;
  584. }
  585. static void pcc_lr_table_entry__destroy(pcc_auxil_t auxil, pcc_lr_table_entry_t *entry) {
  586. if (entry == NULL) return;
  587. pcc_lr_head__destroy(auxil, entry->hold_h);
  588. pcc_lr_answer__destroy(auxil, entry->hold_a);
  589. pcc_lr_memo_map__term(auxil, &entry->memos);
  590. PCC_FREE(auxil, entry);
  591. }
  592. static void pcc_lr_table__init(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t max) {
  593. table->len = 0;
  594. table->max = max;
  595. table->buf = (pcc_lr_table_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_table_entry_t *) * table->max);
  596. }
  597. static void pcc_lr_table__resize(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t len) {
  598. size_t i;
  599. for (i = len; i < table->len; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  600. if (table->max < len) {
  601. size_t m = table->max;
  602. if (m == 0) m = 1;
  603. while (m < len && m != 0) m <<= 1;
  604. if (m == 0) m = len;
  605. table->buf = (pcc_lr_table_entry_t **)PCC_REALLOC(auxil, table->buf, sizeof(pcc_lr_table_entry_t *) * m);
  606. table->max = m;
  607. }
  608. for (i = table->len; i < len; i++) table->buf[i] = NULL;
  609. table->len = len;
  610. }
  611. static void pcc_lr_table__set_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  612. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  613. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  614. table->buf[index]->head = head;
  615. }
  616. static void pcc_lr_table__hold_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_head_t *head) {
  617. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  618. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  619. head->hold = table->buf[index]->hold_h;
  620. table->buf[index]->hold_h = head;
  621. }
  622. static void pcc_lr_table__set_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_rule_t rule, pcc_lr_answer_t *answer) {
  623. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  624. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  625. pcc_lr_memo_map__put(auxil, &table->buf[index]->memos, rule, answer);
  626. }
  627. static void pcc_lr_table__hold_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_lr_answer_t *answer) {
  628. if (index >= table->len) pcc_lr_table__resize(auxil, table, index + 1);
  629. if (table->buf[index] == NULL) table->buf[index] = pcc_lr_table_entry__create(auxil);
  630. answer->hold = table->buf[index]->hold_a;
  631. table->buf[index]->hold_a = answer;
  632. }
  633. static pcc_lr_head_t *pcc_lr_table__get_head(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index) {
  634. if (index >= table->len || table->buf[index] == NULL) return NULL;
  635. return table->buf[index]->head;
  636. }
  637. static pcc_lr_answer_t *pcc_lr_table__get_answer(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t index, pcc_rule_t rule) {
  638. if (index >= table->len || table->buf[index] == NULL) return NULL;
  639. return pcc_lr_memo_map__get(auxil, &table->buf[index]->memos, rule);
  640. }
  641. static void pcc_lr_table__shift(pcc_auxil_t auxil, pcc_lr_table_t *table, size_t count) {
  642. size_t i;
  643. if (count > table->len) count = table->len;
  644. for (i = 0; i < count; i++) pcc_lr_table_entry__destroy(auxil, table->buf[i]);
  645. memmove(table->buf, table->buf + count, sizeof(pcc_lr_table_entry_t *) * (table->len - count));
  646. table->len -= count;
  647. }
  648. static void pcc_lr_table__term(pcc_auxil_t auxil, pcc_lr_table_t *table) {
  649. while (table->len > 0) {
  650. table->len--;
  651. pcc_lr_table_entry__destroy(auxil, table->buf[table->len]);
  652. }
  653. PCC_FREE(auxil, table->buf);
  654. }
  655. static pcc_lr_entry_t *pcc_lr_entry__create(pcc_auxil_t auxil, pcc_rule_t rule) {
  656. pcc_lr_entry_t *const lr = (pcc_lr_entry_t *)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t));
  657. lr->rule = rule;
  658. lr->seed = NULL;
  659. lr->head = NULL;
  660. return lr;
  661. }
  662. static void pcc_lr_entry__destroy(pcc_auxil_t auxil, pcc_lr_entry_t *lr) {
  663. PCC_FREE(auxil, lr);
  664. }
  665. static void pcc_lr_stack__init(pcc_auxil_t auxil, pcc_lr_stack_t *stack, size_t max) {
  666. stack->len = 0;
  667. stack->max = max;
  668. stack->buf = (pcc_lr_entry_t **)PCC_MALLOC(auxil, sizeof(pcc_lr_entry_t *) * stack->max);
  669. }
  670. static void pcc_lr_stack__push(pcc_auxil_t auxil, pcc_lr_stack_t *stack, pcc_lr_entry_t *lr) {
  671. if (stack->max <= stack->len) {
  672. const size_t n = stack->len + 1;
  673. size_t m = stack->max;
  674. if (m == 0) m = 1;
  675. while (m < n && m != 0) m <<= 1;
  676. if (m == 0) m = n;
  677. stack->buf = (pcc_lr_entry_t **)PCC_REALLOC(auxil, stack->buf, sizeof(pcc_lr_entry_t *) * m);
  678. stack->max = m;
  679. }
  680. stack->buf[stack->len++] = lr;
  681. }
  682. static pcc_lr_entry_t *pcc_lr_stack__pop(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  683. return stack->buf[--stack->len];
  684. }
  685. static void pcc_lr_stack__term(pcc_auxil_t auxil, pcc_lr_stack_t *stack) {
  686. PCC_FREE(auxil, stack->buf);
  687. }
  688. static pascal_context_t *pcc_context__create(pcc_auxil_t auxil) {
  689. pascal_context_t *const ctx = (pascal_context_t *)PCC_MALLOC(auxil, sizeof(pascal_context_t));
  690. ctx->pos = 0;
  691. ctx->cur = 0;
  692. ctx->level = 0;
  693. pcc_char_array__init(auxil, &ctx->buffer, PCC_BUFFERSIZE);
  694. pcc_lr_table__init(auxil, &ctx->lrtable, PCC_BUFFERSIZE);
  695. pcc_lr_stack__init(auxil, &ctx->lrstack, PCC_ARRAYSIZE);
  696. ctx->auxil = auxil;
  697. return ctx;
  698. }
  699. static void pcc_context__destroy(pascal_context_t *ctx) {
  700. if (ctx == NULL) return;
  701. pcc_lr_stack__term(ctx->auxil, &ctx->lrstack);
  702. pcc_lr_table__term(ctx->auxil, &ctx->lrtable);
  703. pcc_char_array__term(ctx->auxil, &ctx->buffer);
  704. PCC_FREE(ctx->auxil, ctx);
  705. }
  706. static size_t pcc_refill_buffer(pascal_context_t *ctx, size_t num) {
  707. if (ctx->buffer.len >= ctx->cur + num) return ctx->buffer.len - ctx->cur;
  708. while (ctx->buffer.len < ctx->cur + num) {
  709. const int c = PCC_GETCHAR(ctx->auxil);
  710. if (c == EOF) break;
  711. pcc_char_array__add(ctx->auxil, &ctx->buffer, (char)c);
  712. }
  713. return ctx->buffer.len - ctx->cur;
  714. }
  715. static void pcc_commit_buffer(pascal_context_t *ctx) {
  716. memmove(ctx->buffer.buf, ctx->buffer.buf + ctx->cur, ctx->buffer.len - ctx->cur);
  717. ctx->buffer.len -= ctx->cur;
  718. ctx->pos += ctx->cur;
  719. pcc_lr_table__shift(ctx->auxil, &ctx->lrtable, ctx->cur);
  720. ctx->cur = 0;
  721. }
  722. static const char *pcc_get_capture_string(pascal_context_t *ctx, const pcc_capture_t *capt) {
  723. if (capt->string == NULL)
  724. ((pcc_capture_t *)capt)->string =
  725. pcc_strndup_e(ctx->auxil, ctx->buffer.buf + capt->range.start, capt->range.end - capt->range.start);
  726. return capt->string;
  727. }
  728. static size_t pcc_get_char_as_utf32(pascal_context_t *ctx, int *out) { /* with checking UTF-8 validity */
  729. int c, u;
  730. size_t n;
  731. if (pcc_refill_buffer(ctx, 1) < 1) return 0;
  732. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur];
  733. n = (c < 0x80) ? 1 :
  734. ((c & 0xe0) == 0xc0) ? 2 :
  735. ((c & 0xf0) == 0xe0) ? 3 :
  736. ((c & 0xf8) == 0xf0) ? 4 : 0;
  737. if (n < 1) return 0;
  738. if (pcc_refill_buffer(ctx, n) < n) return 0;
  739. switch (n) {
  740. case 1:
  741. u = c;
  742. break;
  743. case 2:
  744. u = c & 0x1f;
  745. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  746. if ((c & 0xc0) != 0x80) return 0;
  747. u <<= 6; u |= c & 0x3f;
  748. if (u < 0x80) return 0;
  749. break;
  750. case 3:
  751. u = c & 0x0f;
  752. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  753. if ((c & 0xc0) != 0x80) return 0;
  754. u <<= 6; u |= c & 0x3f;
  755. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  756. if ((c & 0xc0) != 0x80) return 0;
  757. u <<= 6; u |= c & 0x3f;
  758. if (u < 0x800) return 0;
  759. break;
  760. case 4:
  761. u = c & 0x07;
  762. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 1];
  763. if ((c & 0xc0) != 0x80) return 0;
  764. u <<= 6; u |= c & 0x3f;
  765. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 2];
  766. if ((c & 0xc0) != 0x80) return 0;
  767. u <<= 6; u |= c & 0x3f;
  768. c = (int)(unsigned char)ctx->buffer.buf[ctx->cur + 3];
  769. if ((c & 0xc0) != 0x80) return 0;
  770. u <<= 6; u |= c & 0x3f;
  771. if (u < 0x10000 || u > 0x10ffff) return 0;
  772. break;
  773. default:
  774. return 0;
  775. }
  776. if (out) *out = u;
  777. return n;
  778. }
  779. static pcc_bool_t pcc_apply_rule(pascal_context_t *ctx, pcc_rule_t rule, pcc_thunk_array_t *thunks, pcc_value_t *value) {
  780. static pcc_value_t null;
  781. pcc_thunk_chunk_t *c = NULL;
  782. const size_t p = ctx->pos + ctx->cur;
  783. pcc_bool_t b = PCC_TRUE;
  784. pcc_lr_answer_t *a = pcc_lr_table__get_answer(ctx->auxil, &ctx->lrtable, p, rule);
  785. pcc_lr_head_t *h = pcc_lr_table__get_head(ctx->auxil, &ctx->lrtable, p);
  786. if (h != NULL) {
  787. if (a == NULL && rule != h->rule && pcc_rule_set__index(ctx->auxil, &h->invol, rule) == VOID_VALUE) {
  788. b = PCC_FALSE;
  789. c = NULL;
  790. }
  791. else if (pcc_rule_set__remove(ctx->auxil, &h->eval, rule)) {
  792. b = PCC_FALSE;
  793. c = rule(ctx);
  794. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  795. a->data.chunk = c;
  796. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  797. }
  798. }
  799. if (b) {
  800. if (a != NULL) {
  801. ctx->cur = a->pos - ctx->pos;
  802. switch (a->type) {
  803. case PCC_LR_ANSWER_LR:
  804. if (a->data.lr->head == NULL) {
  805. a->data.lr->head = pcc_lr_head__create(ctx->auxil, rule);
  806. pcc_lr_table__hold_head(ctx->auxil, &ctx->lrtable, p, a->data.lr->head);
  807. }
  808. {
  809. size_t i = ctx->lrstack.len;
  810. while (i > 0) {
  811. i--;
  812. if (ctx->lrstack.buf[i]->head == a->data.lr->head) break;
  813. ctx->lrstack.buf[i]->head = a->data.lr->head;
  814. pcc_rule_set__add(ctx->auxil, &a->data.lr->head->invol, ctx->lrstack.buf[i]->rule);
  815. }
  816. }
  817. c = a->data.lr->seed;
  818. break;
  819. case PCC_LR_ANSWER_CHUNK:
  820. c = a->data.chunk;
  821. break;
  822. default: /* unknown */
  823. break;
  824. }
  825. }
  826. else {
  827. pcc_lr_entry_t *const e = pcc_lr_entry__create(ctx->auxil, rule);
  828. pcc_lr_stack__push(ctx->auxil, &ctx->lrstack, e);
  829. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_LR, p);
  830. a->data.lr = e;
  831. pcc_lr_table__set_answer(ctx->auxil, &ctx->lrtable, p, rule, a);
  832. c = rule(ctx);
  833. pcc_lr_stack__pop(ctx->auxil, &ctx->lrstack);
  834. a->pos = ctx->pos + ctx->cur;
  835. if (e->head == NULL) {
  836. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  837. }
  838. else {
  839. e->seed = c;
  840. h = a->data.lr->head;
  841. if (h->rule != rule) {
  842. c = a->data.lr->seed;
  843. a = pcc_lr_answer__create(ctx->auxil, PCC_LR_ANSWER_CHUNK, ctx->pos + ctx->cur);
  844. a->data.chunk = c;
  845. pcc_lr_table__hold_answer(ctx->auxil, &ctx->lrtable, p, a);
  846. }
  847. else {
  848. pcc_lr_answer__set_chunk(ctx->auxil, a, a->data.lr->seed);
  849. if (a->data.chunk == NULL) {
  850. c = NULL;
  851. }
  852. else {
  853. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, h);
  854. for (;;) {
  855. ctx->cur = p - ctx->pos;
  856. pcc_rule_set__copy(ctx->auxil, &h->eval, &h->invol);
  857. c = rule(ctx);
  858. if (c == NULL || ctx->pos + ctx->cur <= a->pos) break;
  859. pcc_lr_answer__set_chunk(ctx->auxil, a, c);
  860. a->pos = ctx->pos + ctx->cur;
  861. }
  862. pcc_thunk_chunk__destroy(ctx->auxil, c);
  863. pcc_lr_table__set_head(ctx->auxil, &ctx->lrtable, p, NULL);
  864. ctx->cur = a->pos - ctx->pos;
  865. c = a->data.chunk;
  866. }
  867. }
  868. }
  869. }
  870. }
  871. if (c == NULL) return PCC_FALSE;
  872. if (value == NULL) value = &null;
  873. memset(value, 0, sizeof(pcc_value_t)); /* in case */
  874. pcc_thunk_array__add(ctx->auxil, thunks, pcc_thunk__create_node(ctx->auxil, &c->thunks, value));
  875. return PCC_TRUE;
  876. }
  877. static void pcc_do_action(pascal_context_t *ctx, const pcc_thunk_array_t *thunks, pcc_value_t *value) {
  878. size_t i;
  879. for (i = 0; i < thunks->len; i++) {
  880. pcc_thunk_t *const thunk = thunks->buf[i];
  881. switch (thunk->type) {
  882. case PCC_THUNK_LEAF:
  883. thunk->data.leaf.action(ctx, thunk, value);
  884. break;
  885. case PCC_THUNK_NODE:
  886. pcc_do_action(ctx, thunk->data.node.thunks, thunk->data.node.value);
  887. break;
  888. default: /* unknown */
  889. break;
  890. }
  891. }
  892. }
  893. static pcc_thunk_chunk_t *pcc_evaluate_rule_start(pascal_context_t *ctx);
  894. static pcc_thunk_chunk_t *pcc_evaluate_rule_program(pascal_context_t *ctx);
  895. static pcc_thunk_chunk_t *pcc_evaluate_rule_unit(pascal_context_t *ctx);
  896. static pcc_thunk_chunk_t *pcc_evaluate_rule_uses(pascal_context_t *ctx);
  897. static pcc_thunk_chunk_t *pcc_evaluate_rule_block(pascal_context_t *ctx);
  898. static pcc_thunk_chunk_t *pcc_evaluate_rule_statements(pascal_context_t *ctx);
  899. static pcc_thunk_chunk_t *pcc_evaluate_rule_declarations(pascal_context_t *ctx);
  900. static pcc_thunk_chunk_t *pcc_evaluate_rule_declaration_part(pascal_context_t *ctx);
  901. static pcc_thunk_chunk_t *pcc_evaluate_rule_interface_part(pascal_context_t *ctx);
  902. static pcc_thunk_chunk_t *pcc_evaluate_rule_implementation_part(pascal_context_t *ctx);
  903. static pcc_thunk_chunk_t *pcc_evaluate_rule_procedure_header(pascal_context_t *ctx);
  904. static pcc_thunk_chunk_t *pcc_evaluate_rule_procedure_declaration(pascal_context_t *ctx);
  905. static pcc_thunk_chunk_t *pcc_evaluate_rule_function_header(pascal_context_t *ctx);
  906. static pcc_thunk_chunk_t *pcc_evaluate_rule_function_declaration(pascal_context_t *ctx);
  907. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument_list_declaration(pascal_context_t *ctx);
  908. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument_declaration(pascal_context_t *ctx);
  909. static pcc_thunk_chunk_t *pcc_evaluate_rule_types(pascal_context_t *ctx);
  910. static pcc_thunk_chunk_t *pcc_evaluate_rule_type_declaration(pascal_context_t *ctx);
  911. static pcc_thunk_chunk_t *pcc_evaluate_rule_constants(pascal_context_t *ctx);
  912. static pcc_thunk_chunk_t *pcc_evaluate_rule_constant(pascal_context_t *ctx);
  913. static pcc_thunk_chunk_t *pcc_evaluate_rule_const_literal(pascal_context_t *ctx);
  914. static pcc_thunk_chunk_t *pcc_evaluate_rule_field_literal(pascal_context_t *ctx);
  915. static pcc_thunk_chunk_t *pcc_evaluate_rule_vars(pascal_context_t *ctx);
  916. static pcc_thunk_chunk_t *pcc_evaluate_rule_var_declaration(pascal_context_t *ctx);
  917. static pcc_thunk_chunk_t *pcc_evaluate_rule_type(pascal_context_t *ctx);
  918. static pcc_thunk_chunk_t *pcc_evaluate_rule_statement(pascal_context_t *ctx);
  919. static pcc_thunk_chunk_t *pcc_evaluate_rule_compound(pascal_context_t *ctx);
  920. static pcc_thunk_chunk_t *pcc_evaluate_rule_assignment(pascal_context_t *ctx);
  921. static pcc_thunk_chunk_t *pcc_evaluate_rule_lvalue(pascal_context_t *ctx);
  922. static pcc_thunk_chunk_t *pcc_evaluate_rule_field_access(pascal_context_t *ctx);
  923. static pcc_thunk_chunk_t *pcc_evaluate_rule_array_accesses(pascal_context_t *ctx);
  924. static pcc_thunk_chunk_t *pcc_evaluate_rule_array_access(pascal_context_t *ctx);
  925. static pcc_thunk_chunk_t *pcc_evaluate_rule_procedure_call(pascal_context_t *ctx);
  926. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument_list(pascal_context_t *ctx);
  927. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument(pascal_context_t *ctx);
  928. static pcc_thunk_chunk_t *pcc_evaluate_rule_if_else(pascal_context_t *ctx);
  929. static pcc_thunk_chunk_t *pcc_evaluate_rule_if(pascal_context_t *ctx);
  930. static pcc_thunk_chunk_t *pcc_evaluate_rule_for(pascal_context_t *ctx);
  931. static pcc_thunk_chunk_t *pcc_evaluate_rule_while(pascal_context_t *ctx);
  932. static pcc_thunk_chunk_t *pcc_evaluate_rule_repeat(pascal_context_t *ctx);
  933. static pcc_thunk_chunk_t *pcc_evaluate_rule_with(pascal_context_t *ctx);
  934. static pcc_thunk_chunk_t *pcc_evaluate_rule_function_call(pascal_context_t *ctx);
  935. static pcc_thunk_chunk_t *pcc_evaluate_rule_expression(pascal_context_t *ctx);
  936. static pcc_thunk_chunk_t *pcc_evaluate_rule_negation(pascal_context_t *ctx);
  937. static pcc_thunk_chunk_t *pcc_evaluate_rule_comparision(pascal_context_t *ctx);
  938. static pcc_thunk_chunk_t *pcc_evaluate_rule_or_binary(pascal_context_t *ctx);
  939. static pcc_thunk_chunk_t *pcc_evaluate_rule_or_expr(pascal_context_t *ctx);
  940. static pcc_thunk_chunk_t *pcc_evaluate_rule_and_binary(pascal_context_t *ctx);
  941. static pcc_thunk_chunk_t *pcc_evaluate_rule_and_expr(pascal_context_t *ctx);
  942. static pcc_thunk_chunk_t *pcc_evaluate_rule_base_expr(pascal_context_t *ctx);
  943. static pcc_thunk_chunk_t *pcc_evaluate_rule_nested_expression(pascal_context_t *ctx);
  944. static pcc_thunk_chunk_t *pcc_evaluate_rule_primary(pascal_context_t *ctx);
  945. static pcc_thunk_chunk_t *pcc_evaluate_rule_pointer_to(pascal_context_t *ctx);
  946. static pcc_thunk_chunk_t *pcc_evaluate_rule_deref(pascal_context_t *ctx);
  947. static pcc_thunk_chunk_t *pcc_evaluate_rule_identifier(pascal_context_t *ctx);
  948. static pcc_thunk_chunk_t *pcc_evaluate_rule_literal(pascal_context_t *ctx);
  949. static pcc_thunk_chunk_t *pcc_evaluate_rule_string_literal(pascal_context_t *ctx);
  950. static pcc_thunk_chunk_t *pcc_evaluate_rule_string_character(pascal_context_t *ctx);
  951. static pcc_thunk_chunk_t *pcc_evaluate_rule_boolean_literal(pascal_context_t *ctx);
  952. static pcc_thunk_chunk_t *pcc_evaluate_rule_integer_literal(pascal_context_t *ctx);
  953. static pcc_thunk_chunk_t *pcc_evaluate_rule_real_literal(pascal_context_t *ctx);
  954. static pcc_thunk_chunk_t *pcc_evaluate_rule_comment(pascal_context_t *ctx);
  955. static pcc_thunk_chunk_t *pcc_evaluate_rule_comment_character(pascal_context_t *ctx);
  956. static pcc_thunk_chunk_t *pcc_evaluate_rule__(pascal_context_t *ctx);
  957. static pcc_thunk_chunk_t *pcc_evaluate_rule___(pascal_context_t *ctx);
  958. static pcc_thunk_chunk_t *pcc_evaluate_rule_start(pascal_context_t *ctx) {
  959. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  960. chunk->pos = ctx->cur;
  961. PCC_DEBUG(PCC_DBG_EVALUATE, "start", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  962. ctx->level++;
  963. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  964. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  965. {
  966. const size_t p = ctx->cur;
  967. const size_t n = chunk->thunks.len;
  968. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_program, &chunk->thunks, NULL)) goto L0002;
  969. goto L0001;
  970. L0002:;
  971. ctx->cur = p;
  972. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  973. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_unit, &chunk->thunks, NULL)) goto L0003;
  974. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  975. {
  976. const size_t p = ctx->cur;
  977. const size_t n = chunk->thunks.len;
  978. {
  979. int u;
  980. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  981. if (n == 0) goto L0004;
  982. ctx->cur += n;
  983. }
  984. ctx->cur = p;
  985. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  986. goto L0003;
  987. L0004:;
  988. ctx->cur = p;
  989. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  990. }
  991. goto L0001;
  992. L0003:;
  993. ctx->cur = p;
  994. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  995. goto L0000;
  996. L0001:;
  997. }
  998. ctx->level--;
  999. PCC_DEBUG(PCC_DBG_MATCH, "start", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1000. return chunk;
  1001. L0000:;
  1002. ctx->level--;
  1003. PCC_DEBUG(PCC_DBG_NOMATCH, "start", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1004. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1005. return NULL;
  1006. }
  1007. static pcc_thunk_chunk_t *pcc_evaluate_rule_program(pascal_context_t *ctx) {
  1008. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1009. chunk->pos = ctx->cur;
  1010. PCC_DEBUG(PCC_DBG_EVALUATE, "program", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1011. ctx->level++;
  1012. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1013. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1014. if (
  1015. pcc_refill_buffer(ctx, 7) < 7 ||
  1016. (ctx->buffer.buf + ctx->cur)[0] != 'p' ||
  1017. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  1018. (ctx->buffer.buf + ctx->cur)[2] != 'o' ||
  1019. (ctx->buffer.buf + ctx->cur)[3] != 'g' ||
  1020. (ctx->buffer.buf + ctx->cur)[4] != 'r' ||
  1021. (ctx->buffer.buf + ctx->cur)[5] != 'a' ||
  1022. (ctx->buffer.buf + ctx->cur)[6] != 'm'
  1023. ) goto L0000;
  1024. ctx->cur += 7;
  1025. if (!pcc_apply_rule(ctx, pcc_evaluate_rule___, &chunk->thunks, NULL)) goto L0000;
  1026. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  1027. if (
  1028. pcc_refill_buffer(ctx, 1) < 1 ||
  1029. ctx->buffer.buf[ctx->cur] != ';'
  1030. ) goto L0000;
  1031. ctx->cur++;
  1032. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1033. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_block, &chunk->thunks, NULL)) goto L0000;
  1034. if (
  1035. pcc_refill_buffer(ctx, 1) < 1 ||
  1036. ctx->buffer.buf[ctx->cur] != '.'
  1037. ) goto L0000;
  1038. ctx->cur++;
  1039. ctx->level--;
  1040. PCC_DEBUG(PCC_DBG_MATCH, "program", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1041. return chunk;
  1042. L0000:;
  1043. ctx->level--;
  1044. PCC_DEBUG(PCC_DBG_NOMATCH, "program", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1045. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1046. return NULL;
  1047. }
  1048. static pcc_thunk_chunk_t *pcc_evaluate_rule_unit(pascal_context_t *ctx) {
  1049. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1050. chunk->pos = ctx->cur;
  1051. PCC_DEBUG(PCC_DBG_EVALUATE, "unit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1052. ctx->level++;
  1053. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1054. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1055. if (
  1056. pcc_refill_buffer(ctx, 4) < 4 ||
  1057. (ctx->buffer.buf + ctx->cur)[0] != 'u' ||
  1058. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  1059. (ctx->buffer.buf + ctx->cur)[2] != 'i' ||
  1060. (ctx->buffer.buf + ctx->cur)[3] != 't'
  1061. ) goto L0000;
  1062. ctx->cur += 4;
  1063. if (!pcc_apply_rule(ctx, pcc_evaluate_rule___, &chunk->thunks, NULL)) goto L0000;
  1064. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  1065. if (
  1066. pcc_refill_buffer(ctx, 1) < 1 ||
  1067. ctx->buffer.buf[ctx->cur] != ';'
  1068. ) goto L0000;
  1069. ctx->cur++;
  1070. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1071. if (
  1072. pcc_refill_buffer(ctx, 9) < 9 ||
  1073. (ctx->buffer.buf + ctx->cur)[0] != 'i' ||
  1074. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  1075. (ctx->buffer.buf + ctx->cur)[2] != 't' ||
  1076. (ctx->buffer.buf + ctx->cur)[3] != 'e' ||
  1077. (ctx->buffer.buf + ctx->cur)[4] != 'r' ||
  1078. (ctx->buffer.buf + ctx->cur)[5] != 'f' ||
  1079. (ctx->buffer.buf + ctx->cur)[6] != 'a' ||
  1080. (ctx->buffer.buf + ctx->cur)[7] != 'c' ||
  1081. (ctx->buffer.buf + ctx->cur)[8] != 'e'
  1082. ) goto L0000;
  1083. ctx->cur += 9;
  1084. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1085. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_interface_part, &chunk->thunks, NULL)) goto L0000;
  1086. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1087. if (
  1088. pcc_refill_buffer(ctx, 14) < 14 ||
  1089. (ctx->buffer.buf + ctx->cur)[0] != 'i' ||
  1090. (ctx->buffer.buf + ctx->cur)[1] != 'm' ||
  1091. (ctx->buffer.buf + ctx->cur)[2] != 'p' ||
  1092. (ctx->buffer.buf + ctx->cur)[3] != 'l' ||
  1093. (ctx->buffer.buf + ctx->cur)[4] != 'e' ||
  1094. (ctx->buffer.buf + ctx->cur)[5] != 'm' ||
  1095. (ctx->buffer.buf + ctx->cur)[6] != 'e' ||
  1096. (ctx->buffer.buf + ctx->cur)[7] != 'n' ||
  1097. (ctx->buffer.buf + ctx->cur)[8] != 't' ||
  1098. (ctx->buffer.buf + ctx->cur)[9] != 'a' ||
  1099. (ctx->buffer.buf + ctx->cur)[10] != 't' ||
  1100. (ctx->buffer.buf + ctx->cur)[11] != 'i' ||
  1101. (ctx->buffer.buf + ctx->cur)[12] != 'o' ||
  1102. (ctx->buffer.buf + ctx->cur)[13] != 'n'
  1103. ) goto L0000;
  1104. ctx->cur += 14;
  1105. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1106. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_implementation_part, &chunk->thunks, NULL)) goto L0000;
  1107. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1108. if (
  1109. pcc_refill_buffer(ctx, 3) < 3 ||
  1110. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  1111. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  1112. (ctx->buffer.buf + ctx->cur)[2] != 'd'
  1113. ) goto L0000;
  1114. ctx->cur += 3;
  1115. if (
  1116. pcc_refill_buffer(ctx, 1) < 1 ||
  1117. ctx->buffer.buf[ctx->cur] != '.'
  1118. ) goto L0000;
  1119. ctx->cur++;
  1120. ctx->level--;
  1121. PCC_DEBUG(PCC_DBG_MATCH, "unit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1122. return chunk;
  1123. L0000:;
  1124. ctx->level--;
  1125. PCC_DEBUG(PCC_DBG_NOMATCH, "unit", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1126. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1127. return NULL;
  1128. }
  1129. static pcc_thunk_chunk_t *pcc_evaluate_rule_uses(pascal_context_t *ctx) {
  1130. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1131. chunk->pos = ctx->cur;
  1132. PCC_DEBUG(PCC_DBG_EVALUATE, "uses", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1133. ctx->level++;
  1134. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1135. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1136. if (
  1137. pcc_refill_buffer(ctx, 4) < 4 ||
  1138. (ctx->buffer.buf + ctx->cur)[0] != 'u' ||
  1139. (ctx->buffer.buf + ctx->cur)[1] != 's' ||
  1140. (ctx->buffer.buf + ctx->cur)[2] != 'e' ||
  1141. (ctx->buffer.buf + ctx->cur)[3] != 's'
  1142. ) goto L0000;
  1143. ctx->cur += 4;
  1144. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1145. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  1146. {
  1147. int i;
  1148. for (i = 0;; i++) {
  1149. const size_t p = ctx->cur;
  1150. const size_t n = chunk->thunks.len;
  1151. if (
  1152. pcc_refill_buffer(ctx, 1) < 1 ||
  1153. ctx->buffer.buf[ctx->cur] != ','
  1154. ) goto L0001;
  1155. ctx->cur++;
  1156. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0001;
  1157. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0001;
  1158. if (ctx->cur == p) break;
  1159. continue;
  1160. L0001:;
  1161. ctx->cur = p;
  1162. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1163. break;
  1164. }
  1165. }
  1166. if (
  1167. pcc_refill_buffer(ctx, 1) < 1 ||
  1168. ctx->buffer.buf[ctx->cur] != ';'
  1169. ) goto L0000;
  1170. ctx->cur++;
  1171. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1172. ctx->level--;
  1173. PCC_DEBUG(PCC_DBG_MATCH, "uses", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1174. return chunk;
  1175. L0000:;
  1176. ctx->level--;
  1177. PCC_DEBUG(PCC_DBG_NOMATCH, "uses", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1178. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1179. return NULL;
  1180. }
  1181. static pcc_thunk_chunk_t *pcc_evaluate_rule_block(pascal_context_t *ctx) {
  1182. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1183. chunk->pos = ctx->cur;
  1184. PCC_DEBUG(PCC_DBG_EVALUATE, "block", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1185. ctx->level++;
  1186. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1187. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1188. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_declarations, &chunk->thunks, NULL)) goto L0000;
  1189. if (
  1190. pcc_refill_buffer(ctx, 5) < 5 ||
  1191. (ctx->buffer.buf + ctx->cur)[0] != 'b' ||
  1192. (ctx->buffer.buf + ctx->cur)[1] != 'e' ||
  1193. (ctx->buffer.buf + ctx->cur)[2] != 'g' ||
  1194. (ctx->buffer.buf + ctx->cur)[3] != 'i' ||
  1195. (ctx->buffer.buf + ctx->cur)[4] != 'n'
  1196. ) goto L0000;
  1197. ctx->cur += 5;
  1198. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1199. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statements, &chunk->thunks, NULL)) goto L0000;
  1200. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1201. if (
  1202. pcc_refill_buffer(ctx, 3) < 3 ||
  1203. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  1204. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  1205. (ctx->buffer.buf + ctx->cur)[2] != 'd'
  1206. ) goto L0000;
  1207. ctx->cur += 3;
  1208. ctx->level--;
  1209. PCC_DEBUG(PCC_DBG_MATCH, "block", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1210. return chunk;
  1211. L0000:;
  1212. ctx->level--;
  1213. PCC_DEBUG(PCC_DBG_NOMATCH, "block", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1214. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1215. return NULL;
  1216. }
  1217. static pcc_thunk_chunk_t *pcc_evaluate_rule_statements(pascal_context_t *ctx) {
  1218. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1219. chunk->pos = ctx->cur;
  1220. PCC_DEBUG(PCC_DBG_EVALUATE, "statements", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1221. ctx->level++;
  1222. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1223. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1224. {
  1225. int i;
  1226. for (i = 0;; i++) {
  1227. const size_t p = ctx->cur;
  1228. const size_t n = chunk->thunks.len;
  1229. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0001;
  1230. if (
  1231. pcc_refill_buffer(ctx, 1) < 1 ||
  1232. ctx->buffer.buf[ctx->cur] != ';'
  1233. ) goto L0001;
  1234. ctx->cur++;
  1235. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0001;
  1236. if (ctx->cur == p) break;
  1237. continue;
  1238. L0001:;
  1239. ctx->cur = p;
  1240. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1241. break;
  1242. }
  1243. }
  1244. ctx->level--;
  1245. PCC_DEBUG(PCC_DBG_MATCH, "statements", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1246. return chunk;
  1247. }
  1248. static pcc_thunk_chunk_t *pcc_evaluate_rule_declarations(pascal_context_t *ctx) {
  1249. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1250. chunk->pos = ctx->cur;
  1251. PCC_DEBUG(PCC_DBG_EVALUATE, "declarations", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1252. ctx->level++;
  1253. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1254. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1255. {
  1256. int i;
  1257. for (i = 0;; i++) {
  1258. const size_t p = ctx->cur;
  1259. const size_t n = chunk->thunks.len;
  1260. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_declaration_part, &chunk->thunks, NULL)) goto L0001;
  1261. if (ctx->cur == p) break;
  1262. continue;
  1263. L0001:;
  1264. ctx->cur = p;
  1265. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1266. break;
  1267. }
  1268. }
  1269. ctx->level--;
  1270. PCC_DEBUG(PCC_DBG_MATCH, "declarations", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1271. return chunk;
  1272. }
  1273. static pcc_thunk_chunk_t *pcc_evaluate_rule_declaration_part(pascal_context_t *ctx) {
  1274. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1275. chunk->pos = ctx->cur;
  1276. PCC_DEBUG(PCC_DBG_EVALUATE, "declaration_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1277. ctx->level++;
  1278. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1279. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1280. {
  1281. const size_t p = ctx->cur;
  1282. const size_t n = chunk->thunks.len;
  1283. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_uses, &chunk->thunks, NULL)) goto L0002;
  1284. goto L0001;
  1285. L0002:;
  1286. ctx->cur = p;
  1287. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1288. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_types, &chunk->thunks, NULL)) goto L0003;
  1289. goto L0001;
  1290. L0003:;
  1291. ctx->cur = p;
  1292. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1293. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_constants, &chunk->thunks, NULL)) goto L0004;
  1294. goto L0001;
  1295. L0004:;
  1296. ctx->cur = p;
  1297. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1298. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_vars, &chunk->thunks, NULL)) goto L0005;
  1299. goto L0001;
  1300. L0005:;
  1301. ctx->cur = p;
  1302. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1303. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_procedure_declaration, &chunk->thunks, NULL)) goto L0006;
  1304. goto L0001;
  1305. L0006:;
  1306. ctx->cur = p;
  1307. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1308. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_function_declaration, &chunk->thunks, NULL)) goto L0007;
  1309. goto L0001;
  1310. L0007:;
  1311. ctx->cur = p;
  1312. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1313. goto L0000;
  1314. L0001:;
  1315. }
  1316. ctx->level--;
  1317. PCC_DEBUG(PCC_DBG_MATCH, "declaration_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1318. return chunk;
  1319. L0000:;
  1320. ctx->level--;
  1321. PCC_DEBUG(PCC_DBG_NOMATCH, "declaration_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1322. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1323. return NULL;
  1324. }
  1325. static pcc_thunk_chunk_t *pcc_evaluate_rule_interface_part(pascal_context_t *ctx) {
  1326. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1327. chunk->pos = ctx->cur;
  1328. PCC_DEBUG(PCC_DBG_EVALUATE, "interface_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1329. ctx->level++;
  1330. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1331. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1332. {
  1333. int i;
  1334. for (i = 0;; i++) {
  1335. const size_t p = ctx->cur;
  1336. const size_t n = chunk->thunks.len;
  1337. {
  1338. const size_t p = ctx->cur;
  1339. const size_t n = chunk->thunks.len;
  1340. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_uses, &chunk->thunks, NULL)) goto L0003;
  1341. goto L0002;
  1342. L0003:;
  1343. ctx->cur = p;
  1344. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1345. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_types, &chunk->thunks, NULL)) goto L0004;
  1346. goto L0002;
  1347. L0004:;
  1348. ctx->cur = p;
  1349. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1350. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_constants, &chunk->thunks, NULL)) goto L0005;
  1351. goto L0002;
  1352. L0005:;
  1353. ctx->cur = p;
  1354. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1355. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_vars, &chunk->thunks, NULL)) goto L0006;
  1356. goto L0002;
  1357. L0006:;
  1358. ctx->cur = p;
  1359. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1360. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_procedure_header, &chunk->thunks, NULL)) goto L0007;
  1361. goto L0002;
  1362. L0007:;
  1363. ctx->cur = p;
  1364. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1365. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_function_header, &chunk->thunks, NULL)) goto L0008;
  1366. goto L0002;
  1367. L0008:;
  1368. ctx->cur = p;
  1369. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1370. goto L0001;
  1371. L0002:;
  1372. }
  1373. if (ctx->cur == p) break;
  1374. continue;
  1375. L0001:;
  1376. ctx->cur = p;
  1377. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1378. break;
  1379. }
  1380. }
  1381. ctx->level--;
  1382. PCC_DEBUG(PCC_DBG_MATCH, "interface_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1383. return chunk;
  1384. }
  1385. static pcc_thunk_chunk_t *pcc_evaluate_rule_implementation_part(pascal_context_t *ctx) {
  1386. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1387. chunk->pos = ctx->cur;
  1388. PCC_DEBUG(PCC_DBG_EVALUATE, "implementation_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1389. ctx->level++;
  1390. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1391. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1392. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_declarations, &chunk->thunks, NULL)) goto L0000;
  1393. ctx->level--;
  1394. PCC_DEBUG(PCC_DBG_MATCH, "implementation_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1395. return chunk;
  1396. L0000:;
  1397. ctx->level--;
  1398. PCC_DEBUG(PCC_DBG_NOMATCH, "implementation_part", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1399. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1400. return NULL;
  1401. }
  1402. static pcc_thunk_chunk_t *pcc_evaluate_rule_procedure_header(pascal_context_t *ctx) {
  1403. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1404. chunk->pos = ctx->cur;
  1405. PCC_DEBUG(PCC_DBG_EVALUATE, "procedure_header", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1406. ctx->level++;
  1407. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1408. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1409. {
  1410. const size_t p = ctx->cur;
  1411. const size_t n = chunk->thunks.len;
  1412. if (
  1413. pcc_refill_buffer(ctx, 9) < 9 ||
  1414. (ctx->buffer.buf + ctx->cur)[0] != 'p' ||
  1415. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  1416. (ctx->buffer.buf + ctx->cur)[2] != 'o' ||
  1417. (ctx->buffer.buf + ctx->cur)[3] != 'c' ||
  1418. (ctx->buffer.buf + ctx->cur)[4] != 'e' ||
  1419. (ctx->buffer.buf + ctx->cur)[5] != 'd' ||
  1420. (ctx->buffer.buf + ctx->cur)[6] != 'u' ||
  1421. (ctx->buffer.buf + ctx->cur)[7] != 'r' ||
  1422. (ctx->buffer.buf + ctx->cur)[8] != 'e'
  1423. ) goto L0002;
  1424. ctx->cur += 9;
  1425. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1426. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0002;
  1427. if (
  1428. pcc_refill_buffer(ctx, 1) < 1 ||
  1429. ctx->buffer.buf[ctx->cur] != '('
  1430. ) goto L0002;
  1431. ctx->cur++;
  1432. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_list_declaration, &chunk->thunks, NULL)) goto L0002;
  1433. if (
  1434. pcc_refill_buffer(ctx, 1) < 1 ||
  1435. ctx->buffer.buf[ctx->cur] != ')'
  1436. ) goto L0002;
  1437. ctx->cur++;
  1438. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1439. if (
  1440. pcc_refill_buffer(ctx, 1) < 1 ||
  1441. ctx->buffer.buf[ctx->cur] != ';'
  1442. ) goto L0002;
  1443. ctx->cur++;
  1444. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1445. goto L0001;
  1446. L0002:;
  1447. ctx->cur = p;
  1448. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1449. if (
  1450. pcc_refill_buffer(ctx, 9) < 9 ||
  1451. (ctx->buffer.buf + ctx->cur)[0] != 'p' ||
  1452. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  1453. (ctx->buffer.buf + ctx->cur)[2] != 'o' ||
  1454. (ctx->buffer.buf + ctx->cur)[3] != 'c' ||
  1455. (ctx->buffer.buf + ctx->cur)[4] != 'e' ||
  1456. (ctx->buffer.buf + ctx->cur)[5] != 'd' ||
  1457. (ctx->buffer.buf + ctx->cur)[6] != 'u' ||
  1458. (ctx->buffer.buf + ctx->cur)[7] != 'r' ||
  1459. (ctx->buffer.buf + ctx->cur)[8] != 'e'
  1460. ) goto L0003;
  1461. ctx->cur += 9;
  1462. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1463. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0003;
  1464. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1465. if (
  1466. pcc_refill_buffer(ctx, 1) < 1 ||
  1467. ctx->buffer.buf[ctx->cur] != ';'
  1468. ) goto L0003;
  1469. ctx->cur++;
  1470. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1471. goto L0001;
  1472. L0003:;
  1473. ctx->cur = p;
  1474. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1475. goto L0000;
  1476. L0001:;
  1477. }
  1478. ctx->level--;
  1479. PCC_DEBUG(PCC_DBG_MATCH, "procedure_header", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1480. return chunk;
  1481. L0000:;
  1482. ctx->level--;
  1483. PCC_DEBUG(PCC_DBG_NOMATCH, "procedure_header", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1484. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1485. return NULL;
  1486. }
  1487. static pcc_thunk_chunk_t *pcc_evaluate_rule_procedure_declaration(pascal_context_t *ctx) {
  1488. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1489. chunk->pos = ctx->cur;
  1490. PCC_DEBUG(PCC_DBG_EVALUATE, "procedure_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1491. ctx->level++;
  1492. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1493. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1494. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_procedure_header, &chunk->thunks, NULL)) goto L0000;
  1495. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1496. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_block, &chunk->thunks, NULL)) goto L0000;
  1497. if (
  1498. pcc_refill_buffer(ctx, 1) < 1 ||
  1499. ctx->buffer.buf[ctx->cur] != ';'
  1500. ) goto L0000;
  1501. ctx->cur++;
  1502. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1503. ctx->level--;
  1504. PCC_DEBUG(PCC_DBG_MATCH, "procedure_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1505. return chunk;
  1506. L0000:;
  1507. ctx->level--;
  1508. PCC_DEBUG(PCC_DBG_NOMATCH, "procedure_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1509. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1510. return NULL;
  1511. }
  1512. static pcc_thunk_chunk_t *pcc_evaluate_rule_function_header(pascal_context_t *ctx) {
  1513. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1514. chunk->pos = ctx->cur;
  1515. PCC_DEBUG(PCC_DBG_EVALUATE, "function_header", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1516. ctx->level++;
  1517. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1518. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1519. {
  1520. const size_t p = ctx->cur;
  1521. const size_t n = chunk->thunks.len;
  1522. if (
  1523. pcc_refill_buffer(ctx, 8) < 8 ||
  1524. (ctx->buffer.buf + ctx->cur)[0] != 'f' ||
  1525. (ctx->buffer.buf + ctx->cur)[1] != 'u' ||
  1526. (ctx->buffer.buf + ctx->cur)[2] != 'n' ||
  1527. (ctx->buffer.buf + ctx->cur)[3] != 'c' ||
  1528. (ctx->buffer.buf + ctx->cur)[4] != 't' ||
  1529. (ctx->buffer.buf + ctx->cur)[5] != 'i' ||
  1530. (ctx->buffer.buf + ctx->cur)[6] != 'o' ||
  1531. (ctx->buffer.buf + ctx->cur)[7] != 'n'
  1532. ) goto L0002;
  1533. ctx->cur += 8;
  1534. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1535. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0002;
  1536. if (
  1537. pcc_refill_buffer(ctx, 1) < 1 ||
  1538. ctx->buffer.buf[ctx->cur] != '('
  1539. ) goto L0002;
  1540. ctx->cur++;
  1541. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_list_declaration, &chunk->thunks, NULL)) goto L0002;
  1542. if (
  1543. pcc_refill_buffer(ctx, 1) < 1 ||
  1544. ctx->buffer.buf[ctx->cur] != ')'
  1545. ) goto L0002;
  1546. ctx->cur++;
  1547. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1548. if (
  1549. pcc_refill_buffer(ctx, 1) < 1 ||
  1550. ctx->buffer.buf[ctx->cur] != ':'
  1551. ) goto L0002;
  1552. ctx->cur++;
  1553. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1554. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0002;
  1555. if (
  1556. pcc_refill_buffer(ctx, 1) < 1 ||
  1557. ctx->buffer.buf[ctx->cur] != ';'
  1558. ) goto L0002;
  1559. ctx->cur++;
  1560. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1561. goto L0001;
  1562. L0002:;
  1563. ctx->cur = p;
  1564. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1565. if (
  1566. pcc_refill_buffer(ctx, 8) < 8 ||
  1567. (ctx->buffer.buf + ctx->cur)[0] != 'f' ||
  1568. (ctx->buffer.buf + ctx->cur)[1] != 'u' ||
  1569. (ctx->buffer.buf + ctx->cur)[2] != 'n' ||
  1570. (ctx->buffer.buf + ctx->cur)[3] != 'c' ||
  1571. (ctx->buffer.buf + ctx->cur)[4] != 't' ||
  1572. (ctx->buffer.buf + ctx->cur)[5] != 'i' ||
  1573. (ctx->buffer.buf + ctx->cur)[6] != 'o' ||
  1574. (ctx->buffer.buf + ctx->cur)[7] != 'n'
  1575. ) goto L0003;
  1576. ctx->cur += 8;
  1577. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1578. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0003;
  1579. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1580. if (
  1581. pcc_refill_buffer(ctx, 1) < 1 ||
  1582. ctx->buffer.buf[ctx->cur] != ':'
  1583. ) goto L0003;
  1584. ctx->cur++;
  1585. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1586. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0003;
  1587. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1588. if (
  1589. pcc_refill_buffer(ctx, 1) < 1 ||
  1590. ctx->buffer.buf[ctx->cur] != ';'
  1591. ) goto L0003;
  1592. ctx->cur++;
  1593. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1594. goto L0001;
  1595. L0003:;
  1596. ctx->cur = p;
  1597. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1598. goto L0000;
  1599. L0001:;
  1600. }
  1601. ctx->level--;
  1602. PCC_DEBUG(PCC_DBG_MATCH, "function_header", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1603. return chunk;
  1604. L0000:;
  1605. ctx->level--;
  1606. PCC_DEBUG(PCC_DBG_NOMATCH, "function_header", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1607. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1608. return NULL;
  1609. }
  1610. static pcc_thunk_chunk_t *pcc_evaluate_rule_function_declaration(pascal_context_t *ctx) {
  1611. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1612. chunk->pos = ctx->cur;
  1613. PCC_DEBUG(PCC_DBG_EVALUATE, "function_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1614. ctx->level++;
  1615. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1616. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1617. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_function_header, &chunk->thunks, NULL)) goto L0000;
  1618. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1619. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_block, &chunk->thunks, NULL)) goto L0000;
  1620. if (
  1621. pcc_refill_buffer(ctx, 1) < 1 ||
  1622. ctx->buffer.buf[ctx->cur] != ';'
  1623. ) goto L0000;
  1624. ctx->cur++;
  1625. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1626. ctx->level--;
  1627. PCC_DEBUG(PCC_DBG_MATCH, "function_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1628. return chunk;
  1629. L0000:;
  1630. ctx->level--;
  1631. PCC_DEBUG(PCC_DBG_NOMATCH, "function_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1632. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1633. return NULL;
  1634. }
  1635. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument_list_declaration(pascal_context_t *ctx) {
  1636. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1637. chunk->pos = ctx->cur;
  1638. PCC_DEBUG(PCC_DBG_EVALUATE, "argument_list_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1639. ctx->level++;
  1640. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1641. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1642. {
  1643. const size_t p = ctx->cur;
  1644. const size_t n = chunk->thunks.len;
  1645. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_declaration, &chunk->thunks, NULL)) goto L0001;
  1646. goto L0002;
  1647. L0001:;
  1648. ctx->cur = p;
  1649. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1650. L0002:;
  1651. }
  1652. {
  1653. int i;
  1654. for (i = 0;; i++) {
  1655. const size_t p = ctx->cur;
  1656. const size_t n = chunk->thunks.len;
  1657. if (
  1658. pcc_refill_buffer(ctx, 1) < 1 ||
  1659. ctx->buffer.buf[ctx->cur] != ';'
  1660. ) goto L0003;
  1661. ctx->cur++;
  1662. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1663. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_declaration, &chunk->thunks, NULL)) goto L0003;
  1664. if (ctx->cur == p) break;
  1665. continue;
  1666. L0003:;
  1667. ctx->cur = p;
  1668. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1669. break;
  1670. }
  1671. }
  1672. ctx->level--;
  1673. PCC_DEBUG(PCC_DBG_MATCH, "argument_list_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1674. return chunk;
  1675. }
  1676. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument_declaration(pascal_context_t *ctx) {
  1677. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1678. chunk->pos = ctx->cur;
  1679. PCC_DEBUG(PCC_DBG_EVALUATE, "argument_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1680. ctx->level++;
  1681. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1682. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1683. {
  1684. const size_t p = ctx->cur;
  1685. const size_t n = chunk->thunks.len;
  1686. if (
  1687. pcc_refill_buffer(ctx, 3) < 3 ||
  1688. (ctx->buffer.buf + ctx->cur)[0] != 'v' ||
  1689. (ctx->buffer.buf + ctx->cur)[1] != 'a' ||
  1690. (ctx->buffer.buf + ctx->cur)[2] != 'r'
  1691. ) goto L0001;
  1692. ctx->cur += 3;
  1693. goto L0002;
  1694. L0001:;
  1695. ctx->cur = p;
  1696. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1697. L0002:;
  1698. }
  1699. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1700. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  1701. {
  1702. int i;
  1703. for (i = 0;; i++) {
  1704. const size_t p = ctx->cur;
  1705. const size_t n = chunk->thunks.len;
  1706. if (
  1707. pcc_refill_buffer(ctx, 1) < 1 ||
  1708. ctx->buffer.buf[ctx->cur] != ','
  1709. ) goto L0003;
  1710. ctx->cur++;
  1711. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1712. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0003;
  1713. if (ctx->cur == p) break;
  1714. continue;
  1715. L0003:;
  1716. ctx->cur = p;
  1717. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1718. break;
  1719. }
  1720. }
  1721. if (
  1722. pcc_refill_buffer(ctx, 1) < 1 ||
  1723. ctx->buffer.buf[ctx->cur] != ':'
  1724. ) goto L0000;
  1725. ctx->cur++;
  1726. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1727. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0000;
  1728. ctx->level--;
  1729. PCC_DEBUG(PCC_DBG_MATCH, "argument_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1730. return chunk;
  1731. L0000:;
  1732. ctx->level--;
  1733. PCC_DEBUG(PCC_DBG_NOMATCH, "argument_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1734. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1735. return NULL;
  1736. }
  1737. static pcc_thunk_chunk_t *pcc_evaluate_rule_types(pascal_context_t *ctx) {
  1738. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1739. chunk->pos = ctx->cur;
  1740. PCC_DEBUG(PCC_DBG_EVALUATE, "types", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1741. ctx->level++;
  1742. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1743. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1744. if (
  1745. pcc_refill_buffer(ctx, 4) < 4 ||
  1746. (ctx->buffer.buf + ctx->cur)[0] != 't' ||
  1747. (ctx->buffer.buf + ctx->cur)[1] != 'y' ||
  1748. (ctx->buffer.buf + ctx->cur)[2] != 'p' ||
  1749. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  1750. ) goto L0000;
  1751. ctx->cur += 4;
  1752. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1753. {
  1754. const size_t p0 = ctx->cur;
  1755. const size_t n0 = chunk->thunks.len;
  1756. int i;
  1757. for (i = 0;; i++) {
  1758. const size_t p = ctx->cur;
  1759. const size_t n = chunk->thunks.len;
  1760. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type_declaration, &chunk->thunks, NULL)) goto L0001;
  1761. if (ctx->cur == p) break;
  1762. continue;
  1763. L0001:;
  1764. ctx->cur = p;
  1765. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1766. break;
  1767. }
  1768. if (i < 1) {
  1769. ctx->cur = p0;
  1770. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  1771. goto L0000;
  1772. }
  1773. }
  1774. ctx->level--;
  1775. PCC_DEBUG(PCC_DBG_MATCH, "types", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1776. return chunk;
  1777. L0000:;
  1778. ctx->level--;
  1779. PCC_DEBUG(PCC_DBG_NOMATCH, "types", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1780. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1781. return NULL;
  1782. }
  1783. static pcc_thunk_chunk_t *pcc_evaluate_rule_type_declaration(pascal_context_t *ctx) {
  1784. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1785. chunk->pos = ctx->cur;
  1786. PCC_DEBUG(PCC_DBG_EVALUATE, "type_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1787. ctx->level++;
  1788. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1789. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1790. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  1791. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1792. if (
  1793. pcc_refill_buffer(ctx, 1) < 1 ||
  1794. ctx->buffer.buf[ctx->cur] != '='
  1795. ) goto L0000;
  1796. ctx->cur++;
  1797. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1798. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0000;
  1799. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1800. if (
  1801. pcc_refill_buffer(ctx, 1) < 1 ||
  1802. ctx->buffer.buf[ctx->cur] != ';'
  1803. ) goto L0000;
  1804. ctx->cur++;
  1805. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1806. ctx->level--;
  1807. PCC_DEBUG(PCC_DBG_MATCH, "type_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1808. return chunk;
  1809. L0000:;
  1810. ctx->level--;
  1811. PCC_DEBUG(PCC_DBG_NOMATCH, "type_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1812. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1813. return NULL;
  1814. }
  1815. static pcc_thunk_chunk_t *pcc_evaluate_rule_constants(pascal_context_t *ctx) {
  1816. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1817. chunk->pos = ctx->cur;
  1818. PCC_DEBUG(PCC_DBG_EVALUATE, "constants", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1819. ctx->level++;
  1820. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1821. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1822. if (
  1823. pcc_refill_buffer(ctx, 5) < 5 ||
  1824. (ctx->buffer.buf + ctx->cur)[0] != 'c' ||
  1825. (ctx->buffer.buf + ctx->cur)[1] != 'o' ||
  1826. (ctx->buffer.buf + ctx->cur)[2] != 'n' ||
  1827. (ctx->buffer.buf + ctx->cur)[3] != 's' ||
  1828. (ctx->buffer.buf + ctx->cur)[4] != 't'
  1829. ) goto L0000;
  1830. ctx->cur += 5;
  1831. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  1832. {
  1833. const size_t p0 = ctx->cur;
  1834. const size_t n0 = chunk->thunks.len;
  1835. int i;
  1836. for (i = 0;; i++) {
  1837. const size_t p = ctx->cur;
  1838. const size_t n = chunk->thunks.len;
  1839. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_constant, &chunk->thunks, NULL)) goto L0001;
  1840. if (ctx->cur == p) break;
  1841. continue;
  1842. L0001:;
  1843. ctx->cur = p;
  1844. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1845. break;
  1846. }
  1847. if (i < 1) {
  1848. ctx->cur = p0;
  1849. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  1850. goto L0000;
  1851. }
  1852. }
  1853. ctx->level--;
  1854. PCC_DEBUG(PCC_DBG_MATCH, "constants", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1855. return chunk;
  1856. L0000:;
  1857. ctx->level--;
  1858. PCC_DEBUG(PCC_DBG_NOMATCH, "constants", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1859. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1860. return NULL;
  1861. }
  1862. static pcc_thunk_chunk_t *pcc_evaluate_rule_constant(pascal_context_t *ctx) {
  1863. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1864. chunk->pos = ctx->cur;
  1865. PCC_DEBUG(PCC_DBG_EVALUATE, "constant", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1866. ctx->level++;
  1867. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1868. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1869. {
  1870. const size_t p = ctx->cur;
  1871. const size_t n = chunk->thunks.len;
  1872. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0002;
  1873. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1874. if (
  1875. pcc_refill_buffer(ctx, 1) < 1 ||
  1876. ctx->buffer.buf[ctx->cur] != '='
  1877. ) goto L0002;
  1878. ctx->cur++;
  1879. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1880. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_const_literal, &chunk->thunks, NULL)) goto L0002;
  1881. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1882. if (
  1883. pcc_refill_buffer(ctx, 1) < 1 ||
  1884. ctx->buffer.buf[ctx->cur] != ';'
  1885. ) goto L0002;
  1886. ctx->cur++;
  1887. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  1888. goto L0001;
  1889. L0002:;
  1890. ctx->cur = p;
  1891. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1892. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0003;
  1893. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1894. if (
  1895. pcc_refill_buffer(ctx, 1) < 1 ||
  1896. ctx->buffer.buf[ctx->cur] != ':'
  1897. ) goto L0003;
  1898. ctx->cur++;
  1899. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1900. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0003;
  1901. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1902. if (
  1903. pcc_refill_buffer(ctx, 1) < 1 ||
  1904. ctx->buffer.buf[ctx->cur] != '='
  1905. ) goto L0003;
  1906. ctx->cur++;
  1907. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1908. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_const_literal, &chunk->thunks, NULL)) goto L0003;
  1909. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1910. if (
  1911. pcc_refill_buffer(ctx, 1) < 1 ||
  1912. ctx->buffer.buf[ctx->cur] != ';'
  1913. ) goto L0003;
  1914. ctx->cur++;
  1915. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1916. goto L0001;
  1917. L0003:;
  1918. ctx->cur = p;
  1919. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1920. goto L0000;
  1921. L0001:;
  1922. }
  1923. ctx->level--;
  1924. PCC_DEBUG(PCC_DBG_MATCH, "constant", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1925. return chunk;
  1926. L0000:;
  1927. ctx->level--;
  1928. PCC_DEBUG(PCC_DBG_NOMATCH, "constant", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  1929. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  1930. return NULL;
  1931. }
  1932. static pcc_thunk_chunk_t *pcc_evaluate_rule_const_literal(pascal_context_t *ctx) {
  1933. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  1934. chunk->pos = ctx->cur;
  1935. PCC_DEBUG(PCC_DBG_EVALUATE, "const_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  1936. ctx->level++;
  1937. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  1938. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  1939. {
  1940. const size_t p = ctx->cur;
  1941. const size_t n = chunk->thunks.len;
  1942. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_literal, &chunk->thunks, NULL)) goto L0002;
  1943. goto L0001;
  1944. L0002:;
  1945. ctx->cur = p;
  1946. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1947. if (
  1948. pcc_refill_buffer(ctx, 1) < 1 ||
  1949. ctx->buffer.buf[ctx->cur] != '('
  1950. ) goto L0003;
  1951. ctx->cur++;
  1952. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1953. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_list, &chunk->thunks, NULL)) goto L0003;
  1954. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  1955. if (
  1956. pcc_refill_buffer(ctx, 1) < 1 ||
  1957. ctx->buffer.buf[ctx->cur] != ')'
  1958. ) goto L0003;
  1959. ctx->cur++;
  1960. goto L0001;
  1961. L0003:;
  1962. ctx->cur = p;
  1963. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1964. if (
  1965. pcc_refill_buffer(ctx, 1) < 1 ||
  1966. ctx->buffer.buf[ctx->cur] != '('
  1967. ) goto L0004;
  1968. ctx->cur++;
  1969. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0004;
  1970. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_field_literal, &chunk->thunks, NULL)) goto L0004;
  1971. {
  1972. int i;
  1973. for (i = 0;; i++) {
  1974. const size_t p = ctx->cur;
  1975. const size_t n = chunk->thunks.len;
  1976. if (
  1977. pcc_refill_buffer(ctx, 1) < 1 ||
  1978. ctx->buffer.buf[ctx->cur] != ';'
  1979. ) goto L0005;
  1980. ctx->cur++;
  1981. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0005;
  1982. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_field_literal, &chunk->thunks, NULL)) goto L0005;
  1983. if (ctx->cur == p) break;
  1984. continue;
  1985. L0005:;
  1986. ctx->cur = p;
  1987. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  1988. break;
  1989. }
  1990. }
  1991. if (
  1992. pcc_refill_buffer(ctx, 1) < 1 ||
  1993. ctx->buffer.buf[ctx->cur] != ')'
  1994. ) goto L0004;
  1995. ctx->cur++;
  1996. goto L0001;
  1997. L0004:;
  1998. ctx->cur = p;
  1999. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2000. goto L0000;
  2001. L0001:;
  2002. }
  2003. ctx->level--;
  2004. PCC_DEBUG(PCC_DBG_MATCH, "const_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2005. return chunk;
  2006. L0000:;
  2007. ctx->level--;
  2008. PCC_DEBUG(PCC_DBG_NOMATCH, "const_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2009. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2010. return NULL;
  2011. }
  2012. static pcc_thunk_chunk_t *pcc_evaluate_rule_field_literal(pascal_context_t *ctx) {
  2013. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2014. chunk->pos = ctx->cur;
  2015. PCC_DEBUG(PCC_DBG_EVALUATE, "field_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2016. ctx->level++;
  2017. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2018. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2019. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  2020. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2021. if (
  2022. pcc_refill_buffer(ctx, 1) < 1 ||
  2023. ctx->buffer.buf[ctx->cur] != ':'
  2024. ) goto L0000;
  2025. ctx->cur++;
  2026. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2027. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_literal, &chunk->thunks, NULL)) goto L0000;
  2028. ctx->level--;
  2029. PCC_DEBUG(PCC_DBG_MATCH, "field_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2030. return chunk;
  2031. L0000:;
  2032. ctx->level--;
  2033. PCC_DEBUG(PCC_DBG_NOMATCH, "field_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2034. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2035. return NULL;
  2036. }
  2037. static pcc_thunk_chunk_t *pcc_evaluate_rule_vars(pascal_context_t *ctx) {
  2038. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2039. chunk->pos = ctx->cur;
  2040. PCC_DEBUG(PCC_DBG_EVALUATE, "vars", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2041. ctx->level++;
  2042. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2043. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2044. if (
  2045. pcc_refill_buffer(ctx, 3) < 3 ||
  2046. (ctx->buffer.buf + ctx->cur)[0] != 'v' ||
  2047. (ctx->buffer.buf + ctx->cur)[1] != 'a' ||
  2048. (ctx->buffer.buf + ctx->cur)[2] != 'r'
  2049. ) goto L0000;
  2050. ctx->cur += 3;
  2051. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2052. {
  2053. const size_t p0 = ctx->cur;
  2054. const size_t n0 = chunk->thunks.len;
  2055. int i;
  2056. for (i = 0;; i++) {
  2057. const size_t p = ctx->cur;
  2058. const size_t n = chunk->thunks.len;
  2059. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_var_declaration, &chunk->thunks, NULL)) goto L0001;
  2060. if (ctx->cur == p) break;
  2061. continue;
  2062. L0001:;
  2063. ctx->cur = p;
  2064. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2065. break;
  2066. }
  2067. if (i < 1) {
  2068. ctx->cur = p0;
  2069. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  2070. goto L0000;
  2071. }
  2072. }
  2073. ctx->level--;
  2074. PCC_DEBUG(PCC_DBG_MATCH, "vars", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2075. return chunk;
  2076. L0000:;
  2077. ctx->level--;
  2078. PCC_DEBUG(PCC_DBG_NOMATCH, "vars", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2079. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2080. return NULL;
  2081. }
  2082. static pcc_thunk_chunk_t *pcc_evaluate_rule_var_declaration(pascal_context_t *ctx) {
  2083. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2084. chunk->pos = ctx->cur;
  2085. PCC_DEBUG(PCC_DBG_EVALUATE, "var_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2086. ctx->level++;
  2087. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2088. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2089. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  2090. {
  2091. int i;
  2092. for (i = 0;; i++) {
  2093. const size_t p = ctx->cur;
  2094. const size_t n = chunk->thunks.len;
  2095. if (
  2096. pcc_refill_buffer(ctx, 1) < 1 ||
  2097. ctx->buffer.buf[ctx->cur] != ','
  2098. ) goto L0001;
  2099. ctx->cur++;
  2100. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0001;
  2101. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0001;
  2102. if (ctx->cur == p) break;
  2103. continue;
  2104. L0001:;
  2105. ctx->cur = p;
  2106. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2107. break;
  2108. }
  2109. }
  2110. if (
  2111. pcc_refill_buffer(ctx, 1) < 1 ||
  2112. ctx->buffer.buf[ctx->cur] != ':'
  2113. ) goto L0000;
  2114. ctx->cur++;
  2115. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2116. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0000;
  2117. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2118. if (
  2119. pcc_refill_buffer(ctx, 1) < 1 ||
  2120. ctx->buffer.buf[ctx->cur] != ';'
  2121. ) goto L0000;
  2122. ctx->cur++;
  2123. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2124. ctx->level--;
  2125. PCC_DEBUG(PCC_DBG_MATCH, "var_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2126. return chunk;
  2127. L0000:;
  2128. ctx->level--;
  2129. PCC_DEBUG(PCC_DBG_NOMATCH, "var_declaration", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2130. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2131. return NULL;
  2132. }
  2133. static pcc_thunk_chunk_t *pcc_evaluate_rule_type(pascal_context_t *ctx) {
  2134. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2135. chunk->pos = ctx->cur;
  2136. PCC_DEBUG(PCC_DBG_EVALUATE, "type", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2137. ctx->level++;
  2138. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2139. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2140. {
  2141. const size_t p = ctx->cur;
  2142. const size_t n = chunk->thunks.len;
  2143. if (
  2144. pcc_refill_buffer(ctx, 5) < 5 ||
  2145. (ctx->buffer.buf + ctx->cur)[0] != 'a' ||
  2146. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  2147. (ctx->buffer.buf + ctx->cur)[2] != 'r' ||
  2148. (ctx->buffer.buf + ctx->cur)[3] != 'a' ||
  2149. (ctx->buffer.buf + ctx->cur)[4] != 'y'
  2150. ) goto L0002;
  2151. ctx->cur += 5;
  2152. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2153. if (
  2154. pcc_refill_buffer(ctx, 1) < 1 ||
  2155. ctx->buffer.buf[ctx->cur] != '['
  2156. ) goto L0002;
  2157. ctx->cur++;
  2158. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_integer_literal, &chunk->thunks, NULL)) goto L0002;
  2159. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2160. if (
  2161. pcc_refill_buffer(ctx, 2) < 2 ||
  2162. (ctx->buffer.buf + ctx->cur)[0] != '.' ||
  2163. (ctx->buffer.buf + ctx->cur)[1] != '.'
  2164. ) goto L0002;
  2165. ctx->cur += 2;
  2166. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2167. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_integer_literal, &chunk->thunks, NULL)) goto L0002;
  2168. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2169. if (
  2170. pcc_refill_buffer(ctx, 1) < 1 ||
  2171. ctx->buffer.buf[ctx->cur] != ']'
  2172. ) goto L0002;
  2173. ctx->cur++;
  2174. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2175. if (
  2176. pcc_refill_buffer(ctx, 2) < 2 ||
  2177. (ctx->buffer.buf + ctx->cur)[0] != 'o' ||
  2178. (ctx->buffer.buf + ctx->cur)[1] != 'f'
  2179. ) goto L0002;
  2180. ctx->cur += 2;
  2181. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2182. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0002;
  2183. goto L0001;
  2184. L0002:;
  2185. ctx->cur = p;
  2186. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2187. if (
  2188. pcc_refill_buffer(ctx, 6) < 6 ||
  2189. (ctx->buffer.buf + ctx->cur)[0] != 'r' ||
  2190. (ctx->buffer.buf + ctx->cur)[1] != 'e' ||
  2191. (ctx->buffer.buf + ctx->cur)[2] != 'c' ||
  2192. (ctx->buffer.buf + ctx->cur)[3] != 'o' ||
  2193. (ctx->buffer.buf + ctx->cur)[4] != 'r' ||
  2194. (ctx->buffer.buf + ctx->cur)[5] != 'd'
  2195. ) goto L0003;
  2196. ctx->cur += 6;
  2197. if (!pcc_apply_rule(ctx, pcc_evaluate_rule___, &chunk->thunks, NULL)) goto L0003;
  2198. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_list_declaration, &chunk->thunks, NULL)) goto L0003;
  2199. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  2200. {
  2201. const size_t p = ctx->cur;
  2202. const size_t n = chunk->thunks.len;
  2203. if (
  2204. pcc_refill_buffer(ctx, 1) < 1 ||
  2205. ctx->buffer.buf[ctx->cur] != ';'
  2206. ) goto L0004;
  2207. ctx->cur++;
  2208. goto L0005;
  2209. L0004:;
  2210. ctx->cur = p;
  2211. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2212. L0005:;
  2213. }
  2214. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  2215. if (
  2216. pcc_refill_buffer(ctx, 3) < 3 ||
  2217. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  2218. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  2219. (ctx->buffer.buf + ctx->cur)[2] != 'd'
  2220. ) goto L0003;
  2221. ctx->cur += 3;
  2222. goto L0001;
  2223. L0003:;
  2224. ctx->cur = p;
  2225. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2226. if (
  2227. pcc_refill_buffer(ctx, 1) < 1 ||
  2228. ctx->buffer.buf[ctx->cur] != '^'
  2229. ) goto L0006;
  2230. ctx->cur++;
  2231. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_type, &chunk->thunks, NULL)) goto L0006;
  2232. goto L0001;
  2233. L0006:;
  2234. ctx->cur = p;
  2235. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2236. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0007;
  2237. goto L0001;
  2238. L0007:;
  2239. ctx->cur = p;
  2240. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2241. goto L0000;
  2242. L0001:;
  2243. }
  2244. ctx->level--;
  2245. PCC_DEBUG(PCC_DBG_MATCH, "type", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2246. return chunk;
  2247. L0000:;
  2248. ctx->level--;
  2249. PCC_DEBUG(PCC_DBG_NOMATCH, "type", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2250. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2251. return NULL;
  2252. }
  2253. static pcc_thunk_chunk_t *pcc_evaluate_rule_statement(pascal_context_t *ctx) {
  2254. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2255. chunk->pos = ctx->cur;
  2256. PCC_DEBUG(PCC_DBG_EVALUATE, "statement", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2257. ctx->level++;
  2258. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2259. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2260. {
  2261. const size_t p = ctx->cur;
  2262. const size_t n = chunk->thunks.len;
  2263. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_compound, &chunk->thunks, NULL)) goto L0002;
  2264. goto L0001;
  2265. L0002:;
  2266. ctx->cur = p;
  2267. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2268. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_procedure_call, &chunk->thunks, NULL)) goto L0003;
  2269. goto L0001;
  2270. L0003:;
  2271. ctx->cur = p;
  2272. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2273. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_assignment, &chunk->thunks, NULL)) goto L0004;
  2274. goto L0001;
  2275. L0004:;
  2276. ctx->cur = p;
  2277. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2278. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_if_else, &chunk->thunks, NULL)) goto L0005;
  2279. goto L0001;
  2280. L0005:;
  2281. ctx->cur = p;
  2282. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2283. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_if, &chunk->thunks, NULL)) goto L0006;
  2284. goto L0001;
  2285. L0006:;
  2286. ctx->cur = p;
  2287. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2288. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_for, &chunk->thunks, NULL)) goto L0007;
  2289. goto L0001;
  2290. L0007:;
  2291. ctx->cur = p;
  2292. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2293. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_while, &chunk->thunks, NULL)) goto L0008;
  2294. goto L0001;
  2295. L0008:;
  2296. ctx->cur = p;
  2297. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2298. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_repeat, &chunk->thunks, NULL)) goto L0009;
  2299. goto L0001;
  2300. L0009:;
  2301. ctx->cur = p;
  2302. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2303. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_with, &chunk->thunks, NULL)) goto L0010;
  2304. goto L0001;
  2305. L0010:;
  2306. ctx->cur = p;
  2307. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2308. goto L0000;
  2309. L0001:;
  2310. }
  2311. ctx->level--;
  2312. PCC_DEBUG(PCC_DBG_MATCH, "statement", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2313. return chunk;
  2314. L0000:;
  2315. ctx->level--;
  2316. PCC_DEBUG(PCC_DBG_NOMATCH, "statement", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2317. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2318. return NULL;
  2319. }
  2320. static pcc_thunk_chunk_t *pcc_evaluate_rule_compound(pascal_context_t *ctx) {
  2321. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2322. chunk->pos = ctx->cur;
  2323. PCC_DEBUG(PCC_DBG_EVALUATE, "compound", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2324. ctx->level++;
  2325. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2326. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2327. if (
  2328. pcc_refill_buffer(ctx, 5) < 5 ||
  2329. (ctx->buffer.buf + ctx->cur)[0] != 'b' ||
  2330. (ctx->buffer.buf + ctx->cur)[1] != 'e' ||
  2331. (ctx->buffer.buf + ctx->cur)[2] != 'g' ||
  2332. (ctx->buffer.buf + ctx->cur)[3] != 'i' ||
  2333. (ctx->buffer.buf + ctx->cur)[4] != 'n'
  2334. ) goto L0000;
  2335. ctx->cur += 5;
  2336. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2337. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statements, &chunk->thunks, NULL)) goto L0000;
  2338. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2339. if (
  2340. pcc_refill_buffer(ctx, 3) < 3 ||
  2341. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  2342. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  2343. (ctx->buffer.buf + ctx->cur)[2] != 'd'
  2344. ) goto L0000;
  2345. ctx->cur += 3;
  2346. ctx->level--;
  2347. PCC_DEBUG(PCC_DBG_MATCH, "compound", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2348. return chunk;
  2349. L0000:;
  2350. ctx->level--;
  2351. PCC_DEBUG(PCC_DBG_NOMATCH, "compound", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2352. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2353. return NULL;
  2354. }
  2355. static pcc_thunk_chunk_t *pcc_evaluate_rule_assignment(pascal_context_t *ctx) {
  2356. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2357. chunk->pos = ctx->cur;
  2358. PCC_DEBUG(PCC_DBG_EVALUATE, "assignment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2359. ctx->level++;
  2360. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2361. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2362. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_lvalue, &chunk->thunks, NULL)) goto L0000;
  2363. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2364. if (
  2365. pcc_refill_buffer(ctx, 2) < 2 ||
  2366. (ctx->buffer.buf + ctx->cur)[0] != ':' ||
  2367. (ctx->buffer.buf + ctx->cur)[1] != '='
  2368. ) goto L0000;
  2369. ctx->cur += 2;
  2370. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2371. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2372. ctx->level--;
  2373. PCC_DEBUG(PCC_DBG_MATCH, "assignment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2374. return chunk;
  2375. L0000:;
  2376. ctx->level--;
  2377. PCC_DEBUG(PCC_DBG_NOMATCH, "assignment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2378. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2379. return NULL;
  2380. }
  2381. static pcc_thunk_chunk_t *pcc_evaluate_rule_lvalue(pascal_context_t *ctx) {
  2382. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2383. chunk->pos = ctx->cur;
  2384. PCC_DEBUG(PCC_DBG_EVALUATE, "lvalue", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2385. ctx->level++;
  2386. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2387. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2388. {
  2389. const size_t p = ctx->cur;
  2390. const size_t n = chunk->thunks.len;
  2391. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_field_access, &chunk->thunks, NULL)) goto L0002;
  2392. goto L0001;
  2393. L0002:;
  2394. ctx->cur = p;
  2395. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2396. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_array_accesses, &chunk->thunks, NULL)) goto L0003;
  2397. goto L0001;
  2398. L0003:;
  2399. ctx->cur = p;
  2400. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2401. goto L0000;
  2402. L0001:;
  2403. }
  2404. ctx->level--;
  2405. PCC_DEBUG(PCC_DBG_MATCH, "lvalue", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2406. return chunk;
  2407. L0000:;
  2408. ctx->level--;
  2409. PCC_DEBUG(PCC_DBG_NOMATCH, "lvalue", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2410. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2411. return NULL;
  2412. }
  2413. static pcc_thunk_chunk_t *pcc_evaluate_rule_field_access(pascal_context_t *ctx) {
  2414. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2415. chunk->pos = ctx->cur;
  2416. PCC_DEBUG(PCC_DBG_EVALUATE, "field_access", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2417. ctx->level++;
  2418. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2419. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2420. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_array_accesses, &chunk->thunks, NULL)) goto L0000;
  2421. if (
  2422. pcc_refill_buffer(ctx, 1) < 1 ||
  2423. ctx->buffer.buf[ctx->cur] != '.'
  2424. ) goto L0000;
  2425. ctx->cur++;
  2426. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_lvalue, &chunk->thunks, NULL)) goto L0000;
  2427. ctx->level--;
  2428. PCC_DEBUG(PCC_DBG_MATCH, "field_access", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2429. return chunk;
  2430. L0000:;
  2431. ctx->level--;
  2432. PCC_DEBUG(PCC_DBG_NOMATCH, "field_access", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2433. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2434. return NULL;
  2435. }
  2436. static pcc_thunk_chunk_t *pcc_evaluate_rule_array_accesses(pascal_context_t *ctx) {
  2437. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2438. chunk->pos = ctx->cur;
  2439. PCC_DEBUG(PCC_DBG_EVALUATE, "array_accesses", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2440. ctx->level++;
  2441. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2442. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2443. {
  2444. const size_t p = ctx->cur;
  2445. const size_t n = chunk->thunks.len;
  2446. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_array_access, &chunk->thunks, NULL)) goto L0002;
  2447. goto L0001;
  2448. L0002:;
  2449. ctx->cur = p;
  2450. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2451. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0003;
  2452. goto L0001;
  2453. L0003:;
  2454. ctx->cur = p;
  2455. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2456. goto L0000;
  2457. L0001:;
  2458. }
  2459. ctx->level--;
  2460. PCC_DEBUG(PCC_DBG_MATCH, "array_accesses", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2461. return chunk;
  2462. L0000:;
  2463. ctx->level--;
  2464. PCC_DEBUG(PCC_DBG_NOMATCH, "array_accesses", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2465. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2466. return NULL;
  2467. }
  2468. static pcc_thunk_chunk_t *pcc_evaluate_rule_array_access(pascal_context_t *ctx) {
  2469. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2470. chunk->pos = ctx->cur;
  2471. PCC_DEBUG(PCC_DBG_EVALUATE, "array_access", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2472. ctx->level++;
  2473. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2474. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2475. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  2476. if (
  2477. pcc_refill_buffer(ctx, 1) < 1 ||
  2478. ctx->buffer.buf[ctx->cur] != '['
  2479. ) goto L0000;
  2480. ctx->cur++;
  2481. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2482. if (
  2483. pcc_refill_buffer(ctx, 1) < 1 ||
  2484. ctx->buffer.buf[ctx->cur] != ']'
  2485. ) goto L0000;
  2486. ctx->cur++;
  2487. ctx->level--;
  2488. PCC_DEBUG(PCC_DBG_MATCH, "array_access", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2489. return chunk;
  2490. L0000:;
  2491. ctx->level--;
  2492. PCC_DEBUG(PCC_DBG_NOMATCH, "array_access", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2493. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2494. return NULL;
  2495. }
  2496. static pcc_thunk_chunk_t *pcc_evaluate_rule_procedure_call(pascal_context_t *ctx) {
  2497. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2498. chunk->pos = ctx->cur;
  2499. PCC_DEBUG(PCC_DBG_EVALUATE, "procedure_call", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2500. ctx->level++;
  2501. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2502. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2503. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  2504. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2505. if (
  2506. pcc_refill_buffer(ctx, 1) < 1 ||
  2507. ctx->buffer.buf[ctx->cur] != '('
  2508. ) goto L0000;
  2509. ctx->cur++;
  2510. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_list, &chunk->thunks, NULL)) goto L0000;
  2511. if (
  2512. pcc_refill_buffer(ctx, 1) < 1 ||
  2513. ctx->buffer.buf[ctx->cur] != ')'
  2514. ) goto L0000;
  2515. ctx->cur++;
  2516. ctx->level--;
  2517. PCC_DEBUG(PCC_DBG_MATCH, "procedure_call", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2518. return chunk;
  2519. L0000:;
  2520. ctx->level--;
  2521. PCC_DEBUG(PCC_DBG_NOMATCH, "procedure_call", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2522. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2523. return NULL;
  2524. }
  2525. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument_list(pascal_context_t *ctx) {
  2526. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2527. chunk->pos = ctx->cur;
  2528. PCC_DEBUG(PCC_DBG_EVALUATE, "argument_list", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2529. ctx->level++;
  2530. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2531. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2532. {
  2533. const size_t p = ctx->cur;
  2534. const size_t n = chunk->thunks.len;
  2535. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument, &chunk->thunks, NULL)) goto L0001;
  2536. goto L0002;
  2537. L0001:;
  2538. ctx->cur = p;
  2539. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2540. L0002:;
  2541. }
  2542. {
  2543. int i;
  2544. for (i = 0;; i++) {
  2545. const size_t p = ctx->cur;
  2546. const size_t n = chunk->thunks.len;
  2547. if (
  2548. pcc_refill_buffer(ctx, 1) < 1 ||
  2549. ctx->buffer.buf[ctx->cur] != ','
  2550. ) goto L0003;
  2551. ctx->cur++;
  2552. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  2553. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument, &chunk->thunks, NULL)) goto L0003;
  2554. if (ctx->cur == p) break;
  2555. continue;
  2556. L0003:;
  2557. ctx->cur = p;
  2558. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2559. break;
  2560. }
  2561. }
  2562. ctx->level--;
  2563. PCC_DEBUG(PCC_DBG_MATCH, "argument_list", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2564. return chunk;
  2565. }
  2566. static pcc_thunk_chunk_t *pcc_evaluate_rule_argument(pascal_context_t *ctx) {
  2567. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2568. chunk->pos = ctx->cur;
  2569. PCC_DEBUG(PCC_DBG_EVALUATE, "argument", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2570. ctx->level++;
  2571. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2572. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2573. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2574. ctx->level--;
  2575. PCC_DEBUG(PCC_DBG_MATCH, "argument", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2576. return chunk;
  2577. L0000:;
  2578. ctx->level--;
  2579. PCC_DEBUG(PCC_DBG_NOMATCH, "argument", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2580. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2581. return NULL;
  2582. }
  2583. static pcc_thunk_chunk_t *pcc_evaluate_rule_if_else(pascal_context_t *ctx) {
  2584. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2585. chunk->pos = ctx->cur;
  2586. PCC_DEBUG(PCC_DBG_EVALUATE, "if_else", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2587. ctx->level++;
  2588. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2589. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2590. if (
  2591. pcc_refill_buffer(ctx, 2) < 2 ||
  2592. (ctx->buffer.buf + ctx->cur)[0] != 'i' ||
  2593. (ctx->buffer.buf + ctx->cur)[1] != 'f'
  2594. ) goto L0000;
  2595. ctx->cur += 2;
  2596. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2597. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2598. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2599. if (
  2600. pcc_refill_buffer(ctx, 4) < 4 ||
  2601. (ctx->buffer.buf + ctx->cur)[0] != 't' ||
  2602. (ctx->buffer.buf + ctx->cur)[1] != 'h' ||
  2603. (ctx->buffer.buf + ctx->cur)[2] != 'e' ||
  2604. (ctx->buffer.buf + ctx->cur)[3] != 'n'
  2605. ) goto L0000;
  2606. ctx->cur += 4;
  2607. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2608. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0000;
  2609. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2610. if (
  2611. pcc_refill_buffer(ctx, 4) < 4 ||
  2612. (ctx->buffer.buf + ctx->cur)[0] != 'e' ||
  2613. (ctx->buffer.buf + ctx->cur)[1] != 'l' ||
  2614. (ctx->buffer.buf + ctx->cur)[2] != 's' ||
  2615. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  2616. ) goto L0000;
  2617. ctx->cur += 4;
  2618. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2619. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0000;
  2620. ctx->level--;
  2621. PCC_DEBUG(PCC_DBG_MATCH, "if_else", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2622. return chunk;
  2623. L0000:;
  2624. ctx->level--;
  2625. PCC_DEBUG(PCC_DBG_NOMATCH, "if_else", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2626. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2627. return NULL;
  2628. }
  2629. static pcc_thunk_chunk_t *pcc_evaluate_rule_if(pascal_context_t *ctx) {
  2630. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2631. chunk->pos = ctx->cur;
  2632. PCC_DEBUG(PCC_DBG_EVALUATE, "if", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2633. ctx->level++;
  2634. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2635. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2636. if (
  2637. pcc_refill_buffer(ctx, 2) < 2 ||
  2638. (ctx->buffer.buf + ctx->cur)[0] != 'i' ||
  2639. (ctx->buffer.buf + ctx->cur)[1] != 'f'
  2640. ) goto L0000;
  2641. ctx->cur += 2;
  2642. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2643. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2644. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2645. if (
  2646. pcc_refill_buffer(ctx, 4) < 4 ||
  2647. (ctx->buffer.buf + ctx->cur)[0] != 't' ||
  2648. (ctx->buffer.buf + ctx->cur)[1] != 'h' ||
  2649. (ctx->buffer.buf + ctx->cur)[2] != 'e' ||
  2650. (ctx->buffer.buf + ctx->cur)[3] != 'n'
  2651. ) goto L0000;
  2652. ctx->cur += 4;
  2653. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2654. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0000;
  2655. ctx->level--;
  2656. PCC_DEBUG(PCC_DBG_MATCH, "if", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2657. return chunk;
  2658. L0000:;
  2659. ctx->level--;
  2660. PCC_DEBUG(PCC_DBG_NOMATCH, "if", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2661. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2662. return NULL;
  2663. }
  2664. static pcc_thunk_chunk_t *pcc_evaluate_rule_for(pascal_context_t *ctx) {
  2665. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2666. chunk->pos = ctx->cur;
  2667. PCC_DEBUG(PCC_DBG_EVALUATE, "for", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2668. ctx->level++;
  2669. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2670. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2671. if (
  2672. pcc_refill_buffer(ctx, 3) < 3 ||
  2673. (ctx->buffer.buf + ctx->cur)[0] != 'f' ||
  2674. (ctx->buffer.buf + ctx->cur)[1] != 'o' ||
  2675. (ctx->buffer.buf + ctx->cur)[2] != 'r'
  2676. ) goto L0000;
  2677. ctx->cur += 3;
  2678. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2679. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  2680. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2681. if (
  2682. pcc_refill_buffer(ctx, 2) < 2 ||
  2683. (ctx->buffer.buf + ctx->cur)[0] != ':' ||
  2684. (ctx->buffer.buf + ctx->cur)[1] != '='
  2685. ) goto L0000;
  2686. ctx->cur += 2;
  2687. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2688. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2689. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2690. {
  2691. const size_t p = ctx->cur;
  2692. const size_t n = chunk->thunks.len;
  2693. if (
  2694. pcc_refill_buffer(ctx, 2) < 2 ||
  2695. (ctx->buffer.buf + ctx->cur)[0] != 't' ||
  2696. (ctx->buffer.buf + ctx->cur)[1] != 'o'
  2697. ) goto L0002;
  2698. ctx->cur += 2;
  2699. goto L0001;
  2700. L0002:;
  2701. ctx->cur = p;
  2702. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2703. if (
  2704. pcc_refill_buffer(ctx, 6) < 6 ||
  2705. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  2706. (ctx->buffer.buf + ctx->cur)[1] != 'o' ||
  2707. (ctx->buffer.buf + ctx->cur)[2] != 'w' ||
  2708. (ctx->buffer.buf + ctx->cur)[3] != 'n' ||
  2709. (ctx->buffer.buf + ctx->cur)[4] != 't' ||
  2710. (ctx->buffer.buf + ctx->cur)[5] != 'o'
  2711. ) goto L0003;
  2712. ctx->cur += 6;
  2713. goto L0001;
  2714. L0003:;
  2715. ctx->cur = p;
  2716. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2717. goto L0000;
  2718. L0001:;
  2719. }
  2720. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2721. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2722. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2723. if (
  2724. pcc_refill_buffer(ctx, 2) < 2 ||
  2725. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  2726. (ctx->buffer.buf + ctx->cur)[1] != 'o'
  2727. ) goto L0000;
  2728. ctx->cur += 2;
  2729. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2730. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0000;
  2731. ctx->level--;
  2732. PCC_DEBUG(PCC_DBG_MATCH, "for", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2733. return chunk;
  2734. L0000:;
  2735. ctx->level--;
  2736. PCC_DEBUG(PCC_DBG_NOMATCH, "for", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2737. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2738. return NULL;
  2739. }
  2740. static pcc_thunk_chunk_t *pcc_evaluate_rule_while(pascal_context_t *ctx) {
  2741. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2742. chunk->pos = ctx->cur;
  2743. PCC_DEBUG(PCC_DBG_EVALUATE, "while", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2744. ctx->level++;
  2745. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2746. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2747. if (
  2748. pcc_refill_buffer(ctx, 5) < 5 ||
  2749. (ctx->buffer.buf + ctx->cur)[0] != 'w' ||
  2750. (ctx->buffer.buf + ctx->cur)[1] != 'h' ||
  2751. (ctx->buffer.buf + ctx->cur)[2] != 'i' ||
  2752. (ctx->buffer.buf + ctx->cur)[3] != 'l' ||
  2753. (ctx->buffer.buf + ctx->cur)[4] != 'e'
  2754. ) goto L0000;
  2755. ctx->cur += 5;
  2756. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2757. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2758. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2759. if (
  2760. pcc_refill_buffer(ctx, 2) < 2 ||
  2761. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  2762. (ctx->buffer.buf + ctx->cur)[1] != 'o'
  2763. ) goto L0000;
  2764. ctx->cur += 2;
  2765. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2766. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0000;
  2767. ctx->level--;
  2768. PCC_DEBUG(PCC_DBG_MATCH, "while", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2769. return chunk;
  2770. L0000:;
  2771. ctx->level--;
  2772. PCC_DEBUG(PCC_DBG_NOMATCH, "while", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2773. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2774. return NULL;
  2775. }
  2776. static pcc_thunk_chunk_t *pcc_evaluate_rule_repeat(pascal_context_t *ctx) {
  2777. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2778. chunk->pos = ctx->cur;
  2779. PCC_DEBUG(PCC_DBG_EVALUATE, "repeat", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2780. ctx->level++;
  2781. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2782. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2783. if (
  2784. pcc_refill_buffer(ctx, 6) < 6 ||
  2785. (ctx->buffer.buf + ctx->cur)[0] != 'r' ||
  2786. (ctx->buffer.buf + ctx->cur)[1] != 'e' ||
  2787. (ctx->buffer.buf + ctx->cur)[2] != 'p' ||
  2788. (ctx->buffer.buf + ctx->cur)[3] != 'e' ||
  2789. (ctx->buffer.buf + ctx->cur)[4] != 'a' ||
  2790. (ctx->buffer.buf + ctx->cur)[5] != 't'
  2791. ) goto L0000;
  2792. ctx->cur += 6;
  2793. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2794. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statements, &chunk->thunks, NULL)) goto L0000;
  2795. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2796. if (
  2797. pcc_refill_buffer(ctx, 5) < 5 ||
  2798. (ctx->buffer.buf + ctx->cur)[0] != 'u' ||
  2799. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  2800. (ctx->buffer.buf + ctx->cur)[2] != 't' ||
  2801. (ctx->buffer.buf + ctx->cur)[3] != 'i' ||
  2802. (ctx->buffer.buf + ctx->cur)[4] != 'l'
  2803. ) goto L0000;
  2804. ctx->cur += 5;
  2805. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2806. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2807. ctx->level--;
  2808. PCC_DEBUG(PCC_DBG_MATCH, "repeat", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2809. return chunk;
  2810. L0000:;
  2811. ctx->level--;
  2812. PCC_DEBUG(PCC_DBG_NOMATCH, "repeat", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2813. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2814. return NULL;
  2815. }
  2816. static pcc_thunk_chunk_t *pcc_evaluate_rule_with(pascal_context_t *ctx) {
  2817. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2818. chunk->pos = ctx->cur;
  2819. PCC_DEBUG(PCC_DBG_EVALUATE, "with", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2820. ctx->level++;
  2821. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2822. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2823. if (
  2824. pcc_refill_buffer(ctx, 4) < 4 ||
  2825. (ctx->buffer.buf + ctx->cur)[0] != 'w' ||
  2826. (ctx->buffer.buf + ctx->cur)[1] != 'i' ||
  2827. (ctx->buffer.buf + ctx->cur)[2] != 't' ||
  2828. (ctx->buffer.buf + ctx->cur)[3] != 'h'
  2829. ) goto L0000;
  2830. ctx->cur += 4;
  2831. if (!pcc_apply_rule(ctx, pcc_evaluate_rule___, &chunk->thunks, NULL)) goto L0000;
  2832. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_lvalue, &chunk->thunks, NULL)) goto L0000;
  2833. if (!pcc_apply_rule(ctx, pcc_evaluate_rule___, &chunk->thunks, NULL)) goto L0000;
  2834. if (
  2835. pcc_refill_buffer(ctx, 2) < 2 ||
  2836. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  2837. (ctx->buffer.buf + ctx->cur)[1] != 'o'
  2838. ) goto L0000;
  2839. ctx->cur += 2;
  2840. if (!pcc_apply_rule(ctx, pcc_evaluate_rule___, &chunk->thunks, NULL)) goto L0000;
  2841. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_statement, &chunk->thunks, NULL)) goto L0000;
  2842. ctx->level--;
  2843. PCC_DEBUG(PCC_DBG_MATCH, "with", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2844. return chunk;
  2845. L0000:;
  2846. ctx->level--;
  2847. PCC_DEBUG(PCC_DBG_NOMATCH, "with", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2848. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2849. return NULL;
  2850. }
  2851. static pcc_thunk_chunk_t *pcc_evaluate_rule_function_call(pascal_context_t *ctx) {
  2852. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2853. chunk->pos = ctx->cur;
  2854. PCC_DEBUG(PCC_DBG_EVALUATE, "function_call", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2855. ctx->level++;
  2856. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2857. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2858. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  2859. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2860. if (
  2861. pcc_refill_buffer(ctx, 1) < 1 ||
  2862. ctx->buffer.buf[ctx->cur] != '('
  2863. ) goto L0000;
  2864. ctx->cur++;
  2865. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_argument_list, &chunk->thunks, NULL)) goto L0000;
  2866. if (
  2867. pcc_refill_buffer(ctx, 1) < 1 ||
  2868. ctx->buffer.buf[ctx->cur] != ')'
  2869. ) goto L0000;
  2870. ctx->cur++;
  2871. ctx->level--;
  2872. PCC_DEBUG(PCC_DBG_MATCH, "function_call", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2873. return chunk;
  2874. L0000:;
  2875. ctx->level--;
  2876. PCC_DEBUG(PCC_DBG_NOMATCH, "function_call", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2877. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2878. return NULL;
  2879. }
  2880. static pcc_thunk_chunk_t *pcc_evaluate_rule_expression(pascal_context_t *ctx) {
  2881. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2882. chunk->pos = ctx->cur;
  2883. PCC_DEBUG(PCC_DBG_EVALUATE, "expression", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2884. ctx->level++;
  2885. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2886. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2887. {
  2888. const size_t p = ctx->cur;
  2889. const size_t n = chunk->thunks.len;
  2890. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_negation, &chunk->thunks, NULL)) goto L0002;
  2891. goto L0001;
  2892. L0002:;
  2893. ctx->cur = p;
  2894. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2895. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_comparision, &chunk->thunks, NULL)) goto L0003;
  2896. goto L0001;
  2897. L0003:;
  2898. ctx->cur = p;
  2899. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2900. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0004;
  2901. goto L0001;
  2902. L0004:;
  2903. ctx->cur = p;
  2904. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2905. goto L0000;
  2906. L0001:;
  2907. }
  2908. ctx->level--;
  2909. PCC_DEBUG(PCC_DBG_MATCH, "expression", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2910. return chunk;
  2911. L0000:;
  2912. ctx->level--;
  2913. PCC_DEBUG(PCC_DBG_NOMATCH, "expression", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2914. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2915. return NULL;
  2916. }
  2917. static pcc_thunk_chunk_t *pcc_evaluate_rule_negation(pascal_context_t *ctx) {
  2918. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2919. chunk->pos = ctx->cur;
  2920. PCC_DEBUG(PCC_DBG_EVALUATE, "negation", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2921. ctx->level++;
  2922. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2923. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2924. if (
  2925. pcc_refill_buffer(ctx, 3) < 3 ||
  2926. (ctx->buffer.buf + ctx->cur)[0] != 'n' ||
  2927. (ctx->buffer.buf + ctx->cur)[1] != 'o' ||
  2928. (ctx->buffer.buf + ctx->cur)[2] != 't'
  2929. ) goto L0000;
  2930. ctx->cur += 3;
  2931. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  2932. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  2933. ctx->level--;
  2934. PCC_DEBUG(PCC_DBG_MATCH, "negation", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2935. return chunk;
  2936. L0000:;
  2937. ctx->level--;
  2938. PCC_DEBUG(PCC_DBG_NOMATCH, "negation", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  2939. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  2940. return NULL;
  2941. }
  2942. static pcc_thunk_chunk_t *pcc_evaluate_rule_comparision(pascal_context_t *ctx) {
  2943. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  2944. chunk->pos = ctx->cur;
  2945. PCC_DEBUG(PCC_DBG_EVALUATE, "comparision", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  2946. ctx->level++;
  2947. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  2948. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  2949. {
  2950. const size_t p = ctx->cur;
  2951. const size_t n = chunk->thunks.len;
  2952. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0002;
  2953. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2954. if (
  2955. pcc_refill_buffer(ctx, 1) < 1 ||
  2956. ctx->buffer.buf[ctx->cur] != '='
  2957. ) goto L0002;
  2958. ctx->cur++;
  2959. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0002;
  2960. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0002;
  2961. goto L0001;
  2962. L0002:;
  2963. ctx->cur = p;
  2964. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2965. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0003;
  2966. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  2967. if (
  2968. pcc_refill_buffer(ctx, 2) < 2 ||
  2969. (ctx->buffer.buf + ctx->cur)[0] != '<' ||
  2970. (ctx->buffer.buf + ctx->cur)[1] != '>'
  2971. ) goto L0003;
  2972. ctx->cur += 2;
  2973. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0003;
  2974. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0003;
  2975. goto L0001;
  2976. L0003:;
  2977. ctx->cur = p;
  2978. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2979. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0004;
  2980. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0004;
  2981. if (
  2982. pcc_refill_buffer(ctx, 2) < 2 ||
  2983. (ctx->buffer.buf + ctx->cur)[0] != '>' ||
  2984. (ctx->buffer.buf + ctx->cur)[1] != '='
  2985. ) goto L0004;
  2986. ctx->cur += 2;
  2987. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0004;
  2988. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0004;
  2989. goto L0001;
  2990. L0004:;
  2991. ctx->cur = p;
  2992. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  2993. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0005;
  2994. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0005;
  2995. if (
  2996. pcc_refill_buffer(ctx, 2) < 2 ||
  2997. (ctx->buffer.buf + ctx->cur)[0] != '<' ||
  2998. (ctx->buffer.buf + ctx->cur)[1] != '='
  2999. ) goto L0005;
  3000. ctx->cur += 2;
  3001. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0005;
  3002. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0005;
  3003. goto L0001;
  3004. L0005:;
  3005. ctx->cur = p;
  3006. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3007. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0006;
  3008. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0006;
  3009. if (
  3010. pcc_refill_buffer(ctx, 1) < 1 ||
  3011. ctx->buffer.buf[ctx->cur] != '>'
  3012. ) goto L0006;
  3013. ctx->cur++;
  3014. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0006;
  3015. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0006;
  3016. goto L0001;
  3017. L0006:;
  3018. ctx->cur = p;
  3019. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3020. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0007;
  3021. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0007;
  3022. if (
  3023. pcc_refill_buffer(ctx, 1) < 1 ||
  3024. ctx->buffer.buf[ctx->cur] != '<'
  3025. ) goto L0007;
  3026. ctx->cur++;
  3027. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0007;
  3028. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0007;
  3029. goto L0001;
  3030. L0007:;
  3031. ctx->cur = p;
  3032. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3033. goto L0000;
  3034. L0001:;
  3035. }
  3036. ctx->level--;
  3037. PCC_DEBUG(PCC_DBG_MATCH, "comparision", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3038. return chunk;
  3039. L0000:;
  3040. ctx->level--;
  3041. PCC_DEBUG(PCC_DBG_NOMATCH, "comparision", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3042. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3043. return NULL;
  3044. }
  3045. static pcc_thunk_chunk_t *pcc_evaluate_rule_or_binary(pascal_context_t *ctx) {
  3046. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3047. chunk->pos = ctx->cur;
  3048. PCC_DEBUG(PCC_DBG_EVALUATE, "or_binary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3049. ctx->level++;
  3050. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3051. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3052. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_and_expr, &chunk->thunks, NULL)) goto L0000;
  3053. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  3054. {
  3055. const size_t p = ctx->cur;
  3056. const size_t n = chunk->thunks.len;
  3057. if (
  3058. pcc_refill_buffer(ctx, 2) < 2 ||
  3059. (ctx->buffer.buf + ctx->cur)[0] != 'o' ||
  3060. (ctx->buffer.buf + ctx->cur)[1] != 'r'
  3061. ) goto L0002;
  3062. ctx->cur += 2;
  3063. goto L0001;
  3064. L0002:;
  3065. ctx->cur = p;
  3066. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3067. if (
  3068. pcc_refill_buffer(ctx, 1) < 1 ||
  3069. ctx->buffer.buf[ctx->cur] != '+'
  3070. ) goto L0003;
  3071. ctx->cur++;
  3072. goto L0001;
  3073. L0003:;
  3074. ctx->cur = p;
  3075. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3076. if (
  3077. pcc_refill_buffer(ctx, 1) < 1 ||
  3078. ctx->buffer.buf[ctx->cur] != '-'
  3079. ) goto L0004;
  3080. ctx->cur++;
  3081. goto L0001;
  3082. L0004:;
  3083. ctx->cur = p;
  3084. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3085. goto L0000;
  3086. L0001:;
  3087. }
  3088. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  3089. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_expr, &chunk->thunks, NULL)) goto L0000;
  3090. ctx->level--;
  3091. PCC_DEBUG(PCC_DBG_MATCH, "or_binary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3092. return chunk;
  3093. L0000:;
  3094. ctx->level--;
  3095. PCC_DEBUG(PCC_DBG_NOMATCH, "or_binary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3096. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3097. return NULL;
  3098. }
  3099. static pcc_thunk_chunk_t *pcc_evaluate_rule_or_expr(pascal_context_t *ctx) {
  3100. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3101. chunk->pos = ctx->cur;
  3102. PCC_DEBUG(PCC_DBG_EVALUATE, "or_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3103. ctx->level++;
  3104. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3105. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3106. {
  3107. const size_t p = ctx->cur;
  3108. const size_t n = chunk->thunks.len;
  3109. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_or_binary, &chunk->thunks, NULL)) goto L0002;
  3110. goto L0001;
  3111. L0002:;
  3112. ctx->cur = p;
  3113. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3114. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_and_expr, &chunk->thunks, NULL)) goto L0003;
  3115. goto L0001;
  3116. L0003:;
  3117. ctx->cur = p;
  3118. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3119. goto L0000;
  3120. L0001:;
  3121. }
  3122. ctx->level--;
  3123. PCC_DEBUG(PCC_DBG_MATCH, "or_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3124. return chunk;
  3125. L0000:;
  3126. ctx->level--;
  3127. PCC_DEBUG(PCC_DBG_NOMATCH, "or_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3128. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3129. return NULL;
  3130. }
  3131. static pcc_thunk_chunk_t *pcc_evaluate_rule_and_binary(pascal_context_t *ctx) {
  3132. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3133. chunk->pos = ctx->cur;
  3134. PCC_DEBUG(PCC_DBG_EVALUATE, "and_binary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3135. ctx->level++;
  3136. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3137. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3138. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_base_expr, &chunk->thunks, NULL)) goto L0000;
  3139. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  3140. {
  3141. const size_t p = ctx->cur;
  3142. const size_t n = chunk->thunks.len;
  3143. if (
  3144. pcc_refill_buffer(ctx, 3) < 3 ||
  3145. (ctx->buffer.buf + ctx->cur)[0] != 'a' ||
  3146. (ctx->buffer.buf + ctx->cur)[1] != 'n' ||
  3147. (ctx->buffer.buf + ctx->cur)[2] != 'd'
  3148. ) goto L0002;
  3149. ctx->cur += 3;
  3150. goto L0001;
  3151. L0002:;
  3152. ctx->cur = p;
  3153. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3154. if (
  3155. pcc_refill_buffer(ctx, 1) < 1 ||
  3156. ctx->buffer.buf[ctx->cur] != '*'
  3157. ) goto L0003;
  3158. ctx->cur++;
  3159. goto L0001;
  3160. L0003:;
  3161. ctx->cur = p;
  3162. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3163. if (
  3164. pcc_refill_buffer(ctx, 1) < 1 ||
  3165. ctx->buffer.buf[ctx->cur] != '/'
  3166. ) goto L0004;
  3167. ctx->cur++;
  3168. goto L0001;
  3169. L0004:;
  3170. ctx->cur = p;
  3171. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3172. if (
  3173. pcc_refill_buffer(ctx, 3) < 3 ||
  3174. (ctx->buffer.buf + ctx->cur)[0] != 'd' ||
  3175. (ctx->buffer.buf + ctx->cur)[1] != 'i' ||
  3176. (ctx->buffer.buf + ctx->cur)[2] != 'v'
  3177. ) goto L0005;
  3178. ctx->cur += 3;
  3179. goto L0001;
  3180. L0005:;
  3181. ctx->cur = p;
  3182. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3183. if (
  3184. pcc_refill_buffer(ctx, 3) < 3 ||
  3185. (ctx->buffer.buf + ctx->cur)[0] != 'm' ||
  3186. (ctx->buffer.buf + ctx->cur)[1] != 'o' ||
  3187. (ctx->buffer.buf + ctx->cur)[2] != 'd'
  3188. ) goto L0006;
  3189. ctx->cur += 3;
  3190. goto L0001;
  3191. L0006:;
  3192. ctx->cur = p;
  3193. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3194. goto L0000;
  3195. L0001:;
  3196. }
  3197. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  3198. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_and_expr, &chunk->thunks, NULL)) goto L0000;
  3199. ctx->level--;
  3200. PCC_DEBUG(PCC_DBG_MATCH, "and_binary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3201. return chunk;
  3202. L0000:;
  3203. ctx->level--;
  3204. PCC_DEBUG(PCC_DBG_NOMATCH, "and_binary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3205. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3206. return NULL;
  3207. }
  3208. static pcc_thunk_chunk_t *pcc_evaluate_rule_and_expr(pascal_context_t *ctx) {
  3209. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3210. chunk->pos = ctx->cur;
  3211. PCC_DEBUG(PCC_DBG_EVALUATE, "and_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3212. ctx->level++;
  3213. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3214. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3215. {
  3216. const size_t p = ctx->cur;
  3217. const size_t n = chunk->thunks.len;
  3218. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_and_binary, &chunk->thunks, NULL)) goto L0002;
  3219. goto L0001;
  3220. L0002:;
  3221. ctx->cur = p;
  3222. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3223. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_base_expr, &chunk->thunks, NULL)) goto L0003;
  3224. goto L0001;
  3225. L0003:;
  3226. ctx->cur = p;
  3227. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3228. goto L0000;
  3229. L0001:;
  3230. }
  3231. ctx->level--;
  3232. PCC_DEBUG(PCC_DBG_MATCH, "and_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3233. return chunk;
  3234. L0000:;
  3235. ctx->level--;
  3236. PCC_DEBUG(PCC_DBG_NOMATCH, "and_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3237. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3238. return NULL;
  3239. }
  3240. static pcc_thunk_chunk_t *pcc_evaluate_rule_base_expr(pascal_context_t *ctx) {
  3241. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3242. chunk->pos = ctx->cur;
  3243. PCC_DEBUG(PCC_DBG_EVALUATE, "base_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3244. ctx->level++;
  3245. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3246. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3247. {
  3248. const size_t p = ctx->cur;
  3249. const size_t n = chunk->thunks.len;
  3250. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_primary, &chunk->thunks, NULL)) goto L0002;
  3251. goto L0001;
  3252. L0002:;
  3253. ctx->cur = p;
  3254. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3255. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_nested_expression, &chunk->thunks, NULL)) goto L0003;
  3256. goto L0001;
  3257. L0003:;
  3258. ctx->cur = p;
  3259. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3260. goto L0000;
  3261. L0001:;
  3262. }
  3263. ctx->level--;
  3264. PCC_DEBUG(PCC_DBG_MATCH, "base_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3265. return chunk;
  3266. L0000:;
  3267. ctx->level--;
  3268. PCC_DEBUG(PCC_DBG_NOMATCH, "base_expr", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3269. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3270. return NULL;
  3271. }
  3272. static pcc_thunk_chunk_t *pcc_evaluate_rule_nested_expression(pascal_context_t *ctx) {
  3273. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3274. chunk->pos = ctx->cur;
  3275. PCC_DEBUG(PCC_DBG_EVALUATE, "nested_expression", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3276. ctx->level++;
  3277. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3278. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3279. if (
  3280. pcc_refill_buffer(ctx, 1) < 1 ||
  3281. ctx->buffer.buf[ctx->cur] != '('
  3282. ) goto L0000;
  3283. ctx->cur++;
  3284. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  3285. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_expression, &chunk->thunks, NULL)) goto L0000;
  3286. if (!pcc_apply_rule(ctx, pcc_evaluate_rule__, &chunk->thunks, NULL)) goto L0000;
  3287. if (
  3288. pcc_refill_buffer(ctx, 1) < 1 ||
  3289. ctx->buffer.buf[ctx->cur] != ')'
  3290. ) goto L0000;
  3291. ctx->cur++;
  3292. ctx->level--;
  3293. PCC_DEBUG(PCC_DBG_MATCH, "nested_expression", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3294. return chunk;
  3295. L0000:;
  3296. ctx->level--;
  3297. PCC_DEBUG(PCC_DBG_NOMATCH, "nested_expression", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3298. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3299. return NULL;
  3300. }
  3301. static pcc_thunk_chunk_t *pcc_evaluate_rule_primary(pascal_context_t *ctx) {
  3302. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3303. chunk->pos = ctx->cur;
  3304. PCC_DEBUG(PCC_DBG_EVALUATE, "primary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3305. ctx->level++;
  3306. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3307. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3308. {
  3309. const size_t p = ctx->cur;
  3310. const size_t n = chunk->thunks.len;
  3311. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_function_call, &chunk->thunks, NULL)) goto L0002;
  3312. goto L0001;
  3313. L0002:;
  3314. ctx->cur = p;
  3315. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3316. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_pointer_to, &chunk->thunks, NULL)) goto L0003;
  3317. goto L0001;
  3318. L0003:;
  3319. ctx->cur = p;
  3320. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3321. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_deref, &chunk->thunks, NULL)) goto L0004;
  3322. goto L0001;
  3323. L0004:;
  3324. ctx->cur = p;
  3325. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3326. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_literal, &chunk->thunks, NULL)) goto L0005;
  3327. goto L0001;
  3328. L0005:;
  3329. ctx->cur = p;
  3330. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3331. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_lvalue, &chunk->thunks, NULL)) goto L0006;
  3332. goto L0001;
  3333. L0006:;
  3334. ctx->cur = p;
  3335. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3336. goto L0000;
  3337. L0001:;
  3338. }
  3339. ctx->level--;
  3340. PCC_DEBUG(PCC_DBG_MATCH, "primary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3341. return chunk;
  3342. L0000:;
  3343. ctx->level--;
  3344. PCC_DEBUG(PCC_DBG_NOMATCH, "primary", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3345. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3346. return NULL;
  3347. }
  3348. static pcc_thunk_chunk_t *pcc_evaluate_rule_pointer_to(pascal_context_t *ctx) {
  3349. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3350. chunk->pos = ctx->cur;
  3351. PCC_DEBUG(PCC_DBG_EVALUATE, "pointer_to", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3352. ctx->level++;
  3353. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3354. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3355. if (
  3356. pcc_refill_buffer(ctx, 1) < 1 ||
  3357. ctx->buffer.buf[ctx->cur] != '@'
  3358. ) goto L0000;
  3359. ctx->cur++;
  3360. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  3361. ctx->level--;
  3362. PCC_DEBUG(PCC_DBG_MATCH, "pointer_to", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3363. return chunk;
  3364. L0000:;
  3365. ctx->level--;
  3366. PCC_DEBUG(PCC_DBG_NOMATCH, "pointer_to", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3367. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3368. return NULL;
  3369. }
  3370. static pcc_thunk_chunk_t *pcc_evaluate_rule_deref(pascal_context_t *ctx) {
  3371. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3372. chunk->pos = ctx->cur;
  3373. PCC_DEBUG(PCC_DBG_EVALUATE, "deref", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3374. ctx->level++;
  3375. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3376. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3377. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_identifier, &chunk->thunks, NULL)) goto L0000;
  3378. if (
  3379. pcc_refill_buffer(ctx, 1) < 1 ||
  3380. ctx->buffer.buf[ctx->cur] != '^'
  3381. ) goto L0000;
  3382. ctx->cur++;
  3383. ctx->level--;
  3384. PCC_DEBUG(PCC_DBG_MATCH, "deref", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3385. return chunk;
  3386. L0000:;
  3387. ctx->level--;
  3388. PCC_DEBUG(PCC_DBG_NOMATCH, "deref", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3389. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3390. return NULL;
  3391. }
  3392. static pcc_thunk_chunk_t *pcc_evaluate_rule_identifier(pascal_context_t *ctx) {
  3393. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3394. chunk->pos = ctx->cur;
  3395. PCC_DEBUG(PCC_DBG_EVALUATE, "identifier", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3396. ctx->level++;
  3397. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3398. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3399. {
  3400. int u;
  3401. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3402. if (n == 0) goto L0000;
  3403. if (!(
  3404. (u >= 0x000041 && u <= 0x00005a) ||
  3405. (u >= 0x000061 && u <= 0x00007a)
  3406. )) goto L0000;
  3407. ctx->cur += n;
  3408. }
  3409. {
  3410. int i;
  3411. for (i = 0;; i++) {
  3412. const size_t p = ctx->cur;
  3413. const size_t n = chunk->thunks.len;
  3414. {
  3415. int u;
  3416. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3417. if (n == 0) goto L0001;
  3418. if (!(
  3419. (u >= 0x000041 && u <= 0x00005a) ||
  3420. (u >= 0x000061 && u <= 0x00007a) ||
  3421. (u >= 0x000030 && u <= 0x000039) ||
  3422. u == 0x00005f
  3423. )) goto L0001;
  3424. ctx->cur += n;
  3425. }
  3426. if (ctx->cur == p) break;
  3427. continue;
  3428. L0001:;
  3429. ctx->cur = p;
  3430. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3431. break;
  3432. }
  3433. }
  3434. ctx->level--;
  3435. PCC_DEBUG(PCC_DBG_MATCH, "identifier", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3436. return chunk;
  3437. L0000:;
  3438. ctx->level--;
  3439. PCC_DEBUG(PCC_DBG_NOMATCH, "identifier", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3440. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3441. return NULL;
  3442. }
  3443. static pcc_thunk_chunk_t *pcc_evaluate_rule_literal(pascal_context_t *ctx) {
  3444. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3445. chunk->pos = ctx->cur;
  3446. PCC_DEBUG(PCC_DBG_EVALUATE, "literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3447. ctx->level++;
  3448. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3449. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3450. {
  3451. const size_t p = ctx->cur;
  3452. const size_t n = chunk->thunks.len;
  3453. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_string_literal, &chunk->thunks, NULL)) goto L0002;
  3454. goto L0001;
  3455. L0002:;
  3456. ctx->cur = p;
  3457. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3458. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_boolean_literal, &chunk->thunks, NULL)) goto L0003;
  3459. goto L0001;
  3460. L0003:;
  3461. ctx->cur = p;
  3462. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3463. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_real_literal, &chunk->thunks, NULL)) goto L0004;
  3464. goto L0001;
  3465. L0004:;
  3466. ctx->cur = p;
  3467. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3468. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_integer_literal, &chunk->thunks, NULL)) goto L0005;
  3469. goto L0001;
  3470. L0005:;
  3471. ctx->cur = p;
  3472. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3473. goto L0000;
  3474. L0001:;
  3475. }
  3476. ctx->level--;
  3477. PCC_DEBUG(PCC_DBG_MATCH, "literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3478. return chunk;
  3479. L0000:;
  3480. ctx->level--;
  3481. PCC_DEBUG(PCC_DBG_NOMATCH, "literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3482. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3483. return NULL;
  3484. }
  3485. static pcc_thunk_chunk_t *pcc_evaluate_rule_string_literal(pascal_context_t *ctx) {
  3486. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3487. chunk->pos = ctx->cur;
  3488. PCC_DEBUG(PCC_DBG_EVALUATE, "string_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3489. ctx->level++;
  3490. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3491. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3492. if (
  3493. pcc_refill_buffer(ctx, 1) < 1 ||
  3494. ctx->buffer.buf[ctx->cur] != '\''
  3495. ) goto L0000;
  3496. ctx->cur++;
  3497. {
  3498. int i;
  3499. for (i = 0;; i++) {
  3500. const size_t p = ctx->cur;
  3501. const size_t n = chunk->thunks.len;
  3502. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_string_character, &chunk->thunks, NULL)) goto L0001;
  3503. if (ctx->cur == p) break;
  3504. continue;
  3505. L0001:;
  3506. ctx->cur = p;
  3507. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3508. break;
  3509. }
  3510. }
  3511. if (
  3512. pcc_refill_buffer(ctx, 1) < 1 ||
  3513. ctx->buffer.buf[ctx->cur] != '\''
  3514. ) goto L0000;
  3515. ctx->cur++;
  3516. ctx->level--;
  3517. PCC_DEBUG(PCC_DBG_MATCH, "string_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3518. return chunk;
  3519. L0000:;
  3520. ctx->level--;
  3521. PCC_DEBUG(PCC_DBG_NOMATCH, "string_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3522. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3523. return NULL;
  3524. }
  3525. static pcc_thunk_chunk_t *pcc_evaluate_rule_string_character(pascal_context_t *ctx) {
  3526. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3527. chunk->pos = ctx->cur;
  3528. PCC_DEBUG(PCC_DBG_EVALUATE, "string_character", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3529. ctx->level++;
  3530. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3531. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3532. {
  3533. const size_t p = ctx->cur;
  3534. const size_t n = chunk->thunks.len;
  3535. if (
  3536. pcc_refill_buffer(ctx, 1) < 1 ||
  3537. ctx->buffer.buf[ctx->cur] != '\''
  3538. ) goto L0001;
  3539. ctx->cur++;
  3540. ctx->cur = p;
  3541. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3542. goto L0000;
  3543. L0001:;
  3544. ctx->cur = p;
  3545. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3546. }
  3547. {
  3548. int u;
  3549. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3550. if (n == 0) goto L0000;
  3551. ctx->cur += n;
  3552. }
  3553. ctx->level--;
  3554. PCC_DEBUG(PCC_DBG_MATCH, "string_character", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3555. return chunk;
  3556. L0000:;
  3557. ctx->level--;
  3558. PCC_DEBUG(PCC_DBG_NOMATCH, "string_character", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3559. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3560. return NULL;
  3561. }
  3562. static pcc_thunk_chunk_t *pcc_evaluate_rule_boolean_literal(pascal_context_t *ctx) {
  3563. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3564. chunk->pos = ctx->cur;
  3565. PCC_DEBUG(PCC_DBG_EVALUATE, "boolean_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3566. ctx->level++;
  3567. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3568. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3569. {
  3570. const size_t p = ctx->cur;
  3571. const size_t n = chunk->thunks.len;
  3572. if (
  3573. pcc_refill_buffer(ctx, 4) < 4 ||
  3574. (ctx->buffer.buf + ctx->cur)[0] != 't' ||
  3575. (ctx->buffer.buf + ctx->cur)[1] != 'r' ||
  3576. (ctx->buffer.buf + ctx->cur)[2] != 'u' ||
  3577. (ctx->buffer.buf + ctx->cur)[3] != 'e'
  3578. ) goto L0002;
  3579. ctx->cur += 4;
  3580. goto L0001;
  3581. L0002:;
  3582. ctx->cur = p;
  3583. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3584. if (
  3585. pcc_refill_buffer(ctx, 5) < 5 ||
  3586. (ctx->buffer.buf + ctx->cur)[0] != 'f' ||
  3587. (ctx->buffer.buf + ctx->cur)[1] != 'a' ||
  3588. (ctx->buffer.buf + ctx->cur)[2] != 'l' ||
  3589. (ctx->buffer.buf + ctx->cur)[3] != 's' ||
  3590. (ctx->buffer.buf + ctx->cur)[4] != 'e'
  3591. ) goto L0003;
  3592. ctx->cur += 5;
  3593. goto L0001;
  3594. L0003:;
  3595. ctx->cur = p;
  3596. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3597. goto L0000;
  3598. L0001:;
  3599. }
  3600. ctx->level--;
  3601. PCC_DEBUG(PCC_DBG_MATCH, "boolean_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3602. return chunk;
  3603. L0000:;
  3604. ctx->level--;
  3605. PCC_DEBUG(PCC_DBG_NOMATCH, "boolean_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3606. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3607. return NULL;
  3608. }
  3609. static pcc_thunk_chunk_t *pcc_evaluate_rule_integer_literal(pascal_context_t *ctx) {
  3610. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3611. chunk->pos = ctx->cur;
  3612. PCC_DEBUG(PCC_DBG_EVALUATE, "integer_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3613. ctx->level++;
  3614. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3615. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3616. {
  3617. const size_t p = ctx->cur;
  3618. const size_t n = chunk->thunks.len;
  3619. if (
  3620. pcc_refill_buffer(ctx, 1) < 1 ||
  3621. ctx->buffer.buf[ctx->cur] != '$'
  3622. ) goto L0002;
  3623. ctx->cur++;
  3624. {
  3625. const size_t p0 = ctx->cur;
  3626. const size_t n0 = chunk->thunks.len;
  3627. int i;
  3628. for (i = 0;; i++) {
  3629. const size_t p = ctx->cur;
  3630. const size_t n = chunk->thunks.len;
  3631. {
  3632. int u;
  3633. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3634. if (n == 0) goto L0003;
  3635. if (!(
  3636. (u >= 0x000030 && u <= 0x000039) ||
  3637. (u >= 0x000041 && u <= 0x000046) ||
  3638. (u >= 0x000061 && u <= 0x000066)
  3639. )) goto L0003;
  3640. ctx->cur += n;
  3641. }
  3642. if (ctx->cur == p) break;
  3643. continue;
  3644. L0003:;
  3645. ctx->cur = p;
  3646. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3647. break;
  3648. }
  3649. if (i < 1) {
  3650. ctx->cur = p0;
  3651. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  3652. goto L0002;
  3653. }
  3654. }
  3655. goto L0001;
  3656. L0002:;
  3657. ctx->cur = p;
  3658. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3659. {
  3660. const size_t p0 = ctx->cur;
  3661. const size_t n0 = chunk->thunks.len;
  3662. int i;
  3663. for (i = 0;; i++) {
  3664. const size_t p = ctx->cur;
  3665. const size_t n = chunk->thunks.len;
  3666. {
  3667. int u;
  3668. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3669. if (n == 0) goto L0005;
  3670. if (!(
  3671. (u >= 0x000030 && u <= 0x000039)
  3672. )) goto L0005;
  3673. ctx->cur += n;
  3674. }
  3675. if (ctx->cur == p) break;
  3676. continue;
  3677. L0005:;
  3678. ctx->cur = p;
  3679. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3680. break;
  3681. }
  3682. if (i < 1) {
  3683. ctx->cur = p0;
  3684. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  3685. goto L0004;
  3686. }
  3687. }
  3688. goto L0001;
  3689. L0004:;
  3690. ctx->cur = p;
  3691. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3692. goto L0000;
  3693. L0001:;
  3694. }
  3695. ctx->level--;
  3696. PCC_DEBUG(PCC_DBG_MATCH, "integer_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3697. return chunk;
  3698. L0000:;
  3699. ctx->level--;
  3700. PCC_DEBUG(PCC_DBG_NOMATCH, "integer_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3701. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3702. return NULL;
  3703. }
  3704. static pcc_thunk_chunk_t *pcc_evaluate_rule_real_literal(pascal_context_t *ctx) {
  3705. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3706. chunk->pos = ctx->cur;
  3707. PCC_DEBUG(PCC_DBG_EVALUATE, "real_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3708. ctx->level++;
  3709. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3710. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3711. {
  3712. const size_t p0 = ctx->cur;
  3713. const size_t n0 = chunk->thunks.len;
  3714. int i;
  3715. for (i = 0;; i++) {
  3716. const size_t p = ctx->cur;
  3717. const size_t n = chunk->thunks.len;
  3718. {
  3719. int u;
  3720. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3721. if (n == 0) goto L0001;
  3722. if (!(
  3723. (u >= 0x000030 && u <= 0x000039)
  3724. )) goto L0001;
  3725. ctx->cur += n;
  3726. }
  3727. if (ctx->cur == p) break;
  3728. continue;
  3729. L0001:;
  3730. ctx->cur = p;
  3731. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3732. break;
  3733. }
  3734. if (i < 1) {
  3735. ctx->cur = p0;
  3736. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  3737. goto L0000;
  3738. }
  3739. }
  3740. if (
  3741. pcc_refill_buffer(ctx, 1) < 1 ||
  3742. ctx->buffer.buf[ctx->cur] != '.'
  3743. ) goto L0000;
  3744. ctx->cur++;
  3745. {
  3746. const size_t p0 = ctx->cur;
  3747. const size_t n0 = chunk->thunks.len;
  3748. int i;
  3749. for (i = 0;; i++) {
  3750. const size_t p = ctx->cur;
  3751. const size_t n = chunk->thunks.len;
  3752. {
  3753. int u;
  3754. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3755. if (n == 0) goto L0002;
  3756. if (!(
  3757. (u >= 0x000030 && u <= 0x000039)
  3758. )) goto L0002;
  3759. ctx->cur += n;
  3760. }
  3761. if (ctx->cur == p) break;
  3762. continue;
  3763. L0002:;
  3764. ctx->cur = p;
  3765. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3766. break;
  3767. }
  3768. if (i < 1) {
  3769. ctx->cur = p0;
  3770. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  3771. goto L0000;
  3772. }
  3773. }
  3774. ctx->level--;
  3775. PCC_DEBUG(PCC_DBG_MATCH, "real_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3776. return chunk;
  3777. L0000:;
  3778. ctx->level--;
  3779. PCC_DEBUG(PCC_DBG_NOMATCH, "real_literal", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3780. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3781. return NULL;
  3782. }
  3783. static pcc_thunk_chunk_t *pcc_evaluate_rule_comment(pascal_context_t *ctx) {
  3784. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3785. chunk->pos = ctx->cur;
  3786. PCC_DEBUG(PCC_DBG_EVALUATE, "comment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3787. ctx->level++;
  3788. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3789. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3790. if (
  3791. pcc_refill_buffer(ctx, 1) < 1 ||
  3792. ctx->buffer.buf[ctx->cur] != '{'
  3793. ) goto L0000;
  3794. ctx->cur++;
  3795. {
  3796. int i;
  3797. for (i = 0;; i++) {
  3798. const size_t p = ctx->cur;
  3799. const size_t n = chunk->thunks.len;
  3800. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_comment_character, &chunk->thunks, NULL)) goto L0001;
  3801. if (ctx->cur == p) break;
  3802. continue;
  3803. L0001:;
  3804. ctx->cur = p;
  3805. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3806. break;
  3807. }
  3808. }
  3809. if (
  3810. pcc_refill_buffer(ctx, 1) < 1 ||
  3811. ctx->buffer.buf[ctx->cur] != '}'
  3812. ) goto L0000;
  3813. ctx->cur++;
  3814. ctx->level--;
  3815. PCC_DEBUG(PCC_DBG_MATCH, "comment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3816. return chunk;
  3817. L0000:;
  3818. ctx->level--;
  3819. PCC_DEBUG(PCC_DBG_NOMATCH, "comment", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3820. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3821. return NULL;
  3822. }
  3823. static pcc_thunk_chunk_t *pcc_evaluate_rule_comment_character(pascal_context_t *ctx) {
  3824. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3825. chunk->pos = ctx->cur;
  3826. PCC_DEBUG(PCC_DBG_EVALUATE, "comment_character", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3827. ctx->level++;
  3828. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3829. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3830. {
  3831. const size_t p = ctx->cur;
  3832. const size_t n = chunk->thunks.len;
  3833. if (
  3834. pcc_refill_buffer(ctx, 1) < 1 ||
  3835. ctx->buffer.buf[ctx->cur] != '}'
  3836. ) goto L0001;
  3837. ctx->cur++;
  3838. ctx->cur = p;
  3839. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3840. goto L0000;
  3841. L0001:;
  3842. ctx->cur = p;
  3843. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3844. }
  3845. {
  3846. int u;
  3847. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3848. if (n == 0) goto L0000;
  3849. ctx->cur += n;
  3850. }
  3851. ctx->level--;
  3852. PCC_DEBUG(PCC_DBG_MATCH, "comment_character", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3853. return chunk;
  3854. L0000:;
  3855. ctx->level--;
  3856. PCC_DEBUG(PCC_DBG_NOMATCH, "comment_character", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3857. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3858. return NULL;
  3859. }
  3860. static pcc_thunk_chunk_t *pcc_evaluate_rule__(pascal_context_t *ctx) {
  3861. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3862. chunk->pos = ctx->cur;
  3863. PCC_DEBUG(PCC_DBG_EVALUATE, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3864. ctx->level++;
  3865. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3866. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3867. {
  3868. int i;
  3869. for (i = 0;; i++) {
  3870. const size_t p = ctx->cur;
  3871. const size_t n = chunk->thunks.len;
  3872. {
  3873. const size_t p = ctx->cur;
  3874. const size_t n = chunk->thunks.len;
  3875. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_comment, &chunk->thunks, NULL)) goto L0003;
  3876. goto L0002;
  3877. L0003:;
  3878. ctx->cur = p;
  3879. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3880. {
  3881. int u;
  3882. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3883. if (n == 0) goto L0004;
  3884. if (!(
  3885. u == 0x000020 ||
  3886. u == 0x000009 ||
  3887. u == 0x00000a ||
  3888. u == 0x00000d
  3889. )) goto L0004;
  3890. ctx->cur += n;
  3891. }
  3892. goto L0002;
  3893. L0004:;
  3894. ctx->cur = p;
  3895. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3896. goto L0001;
  3897. L0002:;
  3898. }
  3899. if (ctx->cur == p) break;
  3900. continue;
  3901. L0001:;
  3902. ctx->cur = p;
  3903. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3904. break;
  3905. }
  3906. }
  3907. ctx->level--;
  3908. PCC_DEBUG(PCC_DBG_MATCH, "_", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3909. return chunk;
  3910. }
  3911. static pcc_thunk_chunk_t *pcc_evaluate_rule___(pascal_context_t *ctx) {
  3912. pcc_thunk_chunk_t *const chunk = pcc_thunk_chunk__create(ctx->auxil);
  3913. chunk->pos = ctx->cur;
  3914. PCC_DEBUG(PCC_DBG_EVALUATE, "__", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->buffer.len - chunk->pos));
  3915. ctx->level++;
  3916. pcc_value_table__resize(ctx->auxil, &chunk->values, 0);
  3917. pcc_capture_table__resize(ctx->auxil, &chunk->capts, 0);
  3918. {
  3919. const size_t p0 = ctx->cur;
  3920. const size_t n0 = chunk->thunks.len;
  3921. int i;
  3922. for (i = 0;; i++) {
  3923. const size_t p = ctx->cur;
  3924. const size_t n = chunk->thunks.len;
  3925. {
  3926. const size_t p = ctx->cur;
  3927. const size_t n = chunk->thunks.len;
  3928. if (!pcc_apply_rule(ctx, pcc_evaluate_rule_comment, &chunk->thunks, NULL)) goto L0003;
  3929. goto L0002;
  3930. L0003:;
  3931. ctx->cur = p;
  3932. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3933. {
  3934. int u;
  3935. const size_t n = pcc_get_char_as_utf32(ctx, &u);
  3936. if (n == 0) goto L0004;
  3937. if (!(
  3938. u == 0x000020 ||
  3939. u == 0x000009 ||
  3940. u == 0x00000a ||
  3941. u == 0x00000d
  3942. )) goto L0004;
  3943. ctx->cur += n;
  3944. }
  3945. goto L0002;
  3946. L0004:;
  3947. ctx->cur = p;
  3948. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3949. goto L0001;
  3950. L0002:;
  3951. }
  3952. if (ctx->cur == p) break;
  3953. continue;
  3954. L0001:;
  3955. ctx->cur = p;
  3956. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n);
  3957. break;
  3958. }
  3959. if (i < 1) {
  3960. ctx->cur = p0;
  3961. pcc_thunk_array__revert(ctx->auxil, &chunk->thunks, n0);
  3962. goto L0000;
  3963. }
  3964. }
  3965. ctx->level--;
  3966. PCC_DEBUG(PCC_DBG_MATCH, "__", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3967. return chunk;
  3968. L0000:;
  3969. ctx->level--;
  3970. PCC_DEBUG(PCC_DBG_NOMATCH, "__", ctx->level, chunk->pos, (ctx->buffer.buf + chunk->pos), (ctx->cur - chunk->pos));
  3971. pcc_thunk_chunk__destroy(ctx->auxil, chunk);
  3972. return NULL;
  3973. }
  3974. pascal_context_t *pascal_create(void *auxil) {
  3975. return pcc_context__create(auxil);
  3976. }
  3977. int pascal_parse(pascal_context_t *ctx, int *ret) {
  3978. pcc_thunk_array_t thunks;
  3979. pcc_thunk_array__init(ctx->auxil, &thunks, PCC_ARRAYSIZE);
  3980. if (pcc_apply_rule(ctx, pcc_evaluate_rule_start, &thunks, ret))
  3981. pcc_do_action(ctx, &thunks, ret);
  3982. else
  3983. PCC_ERROR(ctx->auxil);
  3984. pcc_commit_buffer(ctx);
  3985. pcc_thunk_array__term(ctx->auxil, &thunks);
  3986. return pcc_refill_buffer(ctx, 1) >= 1;
  3987. }
  3988. void pascal_destroy(pascal_context_t *ctx) {
  3989. pcc_context__destroy(ctx);
  3990. }
  3991. int main() {
  3992. pascal_context_t *ctx=pascal_create(NULL);
  3993. while (pascal_parse(ctx, NULL)){;}
  3994. pascal_destroy(ctx);
  3995. return 0;
  3996. }