antlr.c 96 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565
  1. /*
  2. * A n t l r T r a n s l a t i o n H e a d e r
  3. *
  4. * Terence Parr, Will Cohen, and Hank Dietz: 1989-2001
  5. * Purdue University Electrical Engineering
  6. * With AHPCRC, University of Minnesota
  7. * ANTLR Version 1.33MR33
  8. *
  9. * ..\bin\antlr -gh antlr.g
  10. *
  11. */
  12. #define ANTLR_VERSION 13333
  13. #include "pcctscfg.h"
  14. #include "pccts_stdio.h"
  15. #include "pcctscfg.h"
  16. #include "set.h"
  17. #include <ctype.h>
  18. #include "syn.h"
  19. #include "hash.h"
  20. #include "generic.h"
  21. #define zzcr_attr(attr,tok,t)
  22. #define zzSET_SIZE 20
  23. #include "antlr.h"
  24. #include "tokens.h"
  25. #include "dlgdef.h"
  26. #include "mode.h"
  27. /* MR23 In order to remove calls to PURIFY use the antlr -nopurify option */
  28. #ifndef PCCTS_PURIFY
  29. #define PCCTS_PURIFY(r,s) memset((char *) &(r),'\0',(s));
  30. #endif
  31. ANTLR_INFO
  32. /* MR20 G. Hobbelt For Borland C++ 4.x & 5.x compiling with ALL warnings enabled */
  33. #if defined(__TURBOC__)
  34. #pragma warn -aus /* unused assignment of 'xxx' */
  35. #endif
  36. #pragma clang diagnostic ignored "-Wparentheses-equality"
  37. #ifdef __USE_PROTOS
  38. static void chkToken(char *, char *, char *, int);
  39. #else
  40. static void chkToken();
  41. #endif
  42. #ifdef __USE_PROTOS
  43. static int isDLGmaxToken(char *Token); /* MR3 */
  44. #else
  45. static int isDLGmaxToken(); /* MR3 */
  46. #endif
  47. static int class_nest_level = 0;
  48. /* MR20 G. Hobbelt extern definitions moved to antlr.h */
  49. void
  50. #ifdef __USE_PROTOS
  51. grammar(void)
  52. #else
  53. grammar()
  54. #endif
  55. {
  56. zzRULE;
  57. zzBLOCK(zztasp1);
  58. zzMake0;
  59. {
  60. Graph g;
  61. {
  62. zzBLOCK(zztasp2);
  63. zzMake0;
  64. {
  65. for (;;) {
  66. if ( !((setwd1[LA(1)]&0x1))) break;
  67. if ( (LA(1)==94) ) {
  68. zzmatch(94); zzCONSUME;
  69. zzmatch(Action);
  70. if ( HdrAction==NULL ) {
  71. HdrAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  72. require(HdrAction!=NULL, "rule grammar: cannot allocate header action");
  73. strcpy(HdrAction, LATEXT(1));
  74. }
  75. else warn("additional #header statement ignored");
  76. zzCONSUME;
  77. }
  78. else {
  79. if ( (LA(1)==95) ) {
  80. zzmatch(95); zzCONSUME;
  81. zzmatch(Action);
  82. if ( FirstAction==NULL ) {
  83. FirstAction = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  84. require(FirstAction!=NULL, "rule grammar: cannot allocate #first action");
  85. strcpy(FirstAction, LATEXT(1));
  86. } else {
  87. warn("additional #first statement ignored");
  88. };
  89. zzCONSUME;
  90. }
  91. else {
  92. if ( (LA(1)==96) ) {
  93. zzmatch(96); zzCONSUME;
  94. zzmatch(QuotedTerm);
  95. if ( GenCC ) {
  96. warn("#parser meta-op incompatible with -CC; ignored");
  97. }
  98. else {
  99. if ( strcmp(ParserName,"zzparser")==0 ) {
  100. ParserName=StripQuotes(mystrdup(LATEXT(1)));
  101. if ( RulePrefix[0]!='\0' )
  102. {
  103. warn("#parser meta-op incompatible with '-gp prefix'; '-gp' ignored");
  104. RulePrefix[0]='\0';
  105. }
  106. }
  107. else warn("additional #parser statement ignored");
  108. }
  109. zzCONSUME;
  110. }
  111. else {
  112. if ( (LA(1)==97) ) {
  113. zzmatch(97); zzCONSUME;
  114. zzmatch(QuotedTerm);
  115. {
  116. char *fname;
  117. zzantlr_state st; FILE *f; struct zzdlg_state dst;
  118. UserTokenDefsFile = mystrdup(LATEXT(1));
  119. zzsave_antlr_state(&st);
  120. zzsave_dlg_state(&dst);
  121. fname = mystrdup(LATEXT(1));
  122. f = fopen(StripQuotes(fname), "r");
  123. if ( f==NULL ) {warn(eMsg1("cannot open token defs file '%s'", fname+1));}
  124. else {
  125. ANTLRm(enum_file(fname+1), f, PARSE_ENUM_FILE);
  126. UserDefdTokens = 1;
  127. }
  128. zzrestore_antlr_state(&st);
  129. zzrestore_dlg_state(&dst);
  130. }
  131. zzCONSUME;
  132. }
  133. else break; /* MR6 code for exiting loop "for sure" */
  134. }
  135. }
  136. }
  137. zzLOOP(zztasp2);
  138. }
  139. zzEXIT(zztasp2);
  140. }
  141. }
  142. {
  143. zzBLOCK(zztasp2);
  144. zzMake0;
  145. {
  146. for (;;) {
  147. if ( !((setwd1[LA(1)]&0x2))) break;
  148. if ( (LA(1)==Action) ) {
  149. zzmatch(Action);
  150. {
  151. UserAction *ua = newUserAction(LATEXT(1));
  152. ua->file = action_file; ua->line = action_line;
  153. if ( class_nest_level>0 ) list_add(&class_before_actions, ua);
  154. else list_add(&BeforeActions, ua);
  155. }
  156. zzCONSUME;
  157. }
  158. else {
  159. if ( (LA(1)==108) ) {
  160. laction();
  161. }
  162. else {
  163. if ( (LA(1)==109) ) {
  164. lmember();
  165. }
  166. else {
  167. if ( (LA(1)==110) ) {
  168. lprefix();
  169. }
  170. else {
  171. if ( (LA(1)==116) ) {
  172. aLexclass();
  173. }
  174. else {
  175. if ( (LA(1)==120) ) {
  176. token();
  177. }
  178. else {
  179. if ( (LA(1)==117) ) {
  180. error();
  181. }
  182. else {
  183. if ( (LA(1)==118) ) {
  184. tclass();
  185. }
  186. else {
  187. if ( (LA(1)==111) ) {
  188. aPred();
  189. }
  190. else {
  191. if ( (LA(1)==133) ) {
  192. default_exception_handler();
  193. }
  194. else {
  195. if ( (LA(1)==99) ) {
  196. class_def();
  197. }
  198. else {
  199. if ( (LA(1)==98) ) {
  200. zzmatch(98);
  201. if ( class_nest_level==0 )
  202. warn("missing class definition for trailing '}'");
  203. class_nest_level--;
  204. zzCONSUME;
  205. }
  206. else break; /* MR6 code for exiting loop "for sure" */
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. zzLOOP(zztasp2);
  219. }
  220. zzEXIT(zztasp2);
  221. }
  222. }
  223. rule();
  224. g=zzaArg(zztasp1,3); SynDiag = (Junction *) zzaArg(zztasp1,3 ).left;
  225. {
  226. zzBLOCK(zztasp2);
  227. zzMake0;
  228. {
  229. for (;;) {
  230. if ( !((setwd1[LA(1)]&0x4))) break;
  231. if ( (LA(1)==NonTerminal) ) {
  232. rule();
  233. if ( zzaArg(zztasp2,1 ).left!=NULL ) {
  234. g.right = NULL;
  235. /* MR21a */ /* Avoid use of a malformed graph when CannotContinue */
  236. /* MR21a */ /* is already set */
  237. /* MR21a */
  238. /* MR21a */ if (! (CannotContinue && g.left == NULL)) {
  239. /* MR21a */ g = Or(g, zzaArg(zztasp2,1));
  240. /* MR21a */ }
  241. /* MR21a */ }
  242. }
  243. else {
  244. if ( (LA(1)==116) ) {
  245. aLexclass();
  246. }
  247. else {
  248. if ( (LA(1)==120) ) {
  249. token();
  250. }
  251. else {
  252. if ( (LA(1)==117) ) {
  253. error();
  254. }
  255. else {
  256. if ( (LA(1)==118) ) {
  257. tclass();
  258. }
  259. else {
  260. if ( (LA(1)==111) ) {
  261. aPred();
  262. }
  263. else {
  264. if ( (LA(1)==99) ) {
  265. class_def();
  266. }
  267. else {
  268. if ( (LA(1)==98) ) {
  269. zzmatch(98);
  270. if ( class_nest_level==0 )
  271. warn("missing class definition for trailing '}'");
  272. class_nest_level--;
  273. zzCONSUME;
  274. }
  275. else break; /* MR6 code for exiting loop "for sure" */
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. zzLOOP(zztasp2);
  284. }
  285. zzEXIT(zztasp2);
  286. }
  287. }
  288. {
  289. zzBLOCK(zztasp2);
  290. zzMake0;
  291. {
  292. for (;;) {
  293. if ( !((setwd1[LA(1)]&0x8))) break;
  294. if ( (LA(1)==Action) ) {
  295. zzmatch(Action);
  296. {
  297. UserAction *ua = newUserAction(LATEXT(1));
  298. ua->file = action_file; ua->line = action_line;
  299. if ( class_nest_level>0 ) list_add(&class_after_actions, ua);
  300. else list_add(&AfterActions, ua);
  301. }
  302. zzCONSUME;
  303. }
  304. else {
  305. if ( (LA(1)==108) ) {
  306. laction();
  307. }
  308. else {
  309. if ( (LA(1)==109) ) {
  310. lmember();
  311. }
  312. else {
  313. if ( (LA(1)==110) ) {
  314. lprefix();
  315. }
  316. else {
  317. if ( (LA(1)==117) ) {
  318. error();
  319. }
  320. else {
  321. if ( (LA(1)==118) ) {
  322. tclass();
  323. }
  324. else {
  325. if ( (LA(1)==99) ) {
  326. class_def();
  327. }
  328. else {
  329. if ( (LA(1)==111) ) {
  330. aPred();
  331. }
  332. else {
  333. if ( (LA(1)==98) ) {
  334. zzmatch(98);
  335. if ( class_nest_level==0 )
  336. warn("missing class definition for trailing '}'");
  337. class_nest_level--;
  338. zzCONSUME;
  339. }
  340. else break; /* MR6 code for exiting loop "for sure" */
  341. }
  342. }
  343. }
  344. }
  345. }
  346. }
  347. }
  348. }
  349. zzLOOP(zztasp2);
  350. }
  351. zzEXIT(zztasp2);
  352. }
  353. }
  354. zzmatch(Eof); zzCONSUME;
  355. zzEXIT(zztasp1);
  356. return;
  357. fail:
  358. zzEXIT(zztasp1);
  359. CannotContinue=TRUE;
  360. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  361. zzresynch(setwd1, 0x10);
  362. }
  363. }
  364. void
  365. #ifdef __USE_PROTOS
  366. class_def(void)
  367. #else
  368. class_def()
  369. #endif
  370. {
  371. zzRULE;
  372. zzBLOCK(zztasp1);
  373. zzMake0;
  374. {
  375. int go=1; char name[MaxRuleName+1];
  376. zzmatch(99); zzCONSUME;
  377. {
  378. zzBLOCK(zztasp2);
  379. zzMake0;
  380. {
  381. if ( (LA(1)==NonTerminal) ) {
  382. zzmatch(NonTerminal);
  383. if(go) strncpy(name,LATEXT(1),MaxRuleName);
  384. zzCONSUME;
  385. }
  386. else {
  387. if ( (LA(1)==TokenTerm) ) {
  388. zzmatch(TokenTerm);
  389. if(go) strncpy(name,LATEXT(1),MaxRuleName);
  390. zzCONSUME;
  391. }
  392. else {zzFAIL(1,zzerr1,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  393. }
  394. zzEXIT(zztasp2);
  395. }
  396. }
  397. if ( CurrentClassName[0]!='\0' && strcmp(CurrentClassName,name)!=0
  398. && GenCC ) {
  399. err("only one grammar class allowed in this release");
  400. go = 0;
  401. }
  402. else strcpy(CurrentClassName, name);
  403. if ( !GenCC ) { err("class meta-op used without C++ option"); }
  404. {
  405. zzBLOCK(zztasp2);
  406. zzMake0;
  407. {
  408. while ( (setwd1[LA(1)]&0x20) ) {
  409. zzsetmatch(zzerr2, zzerr3);
  410. if (ClassDeclStuff == NULL) {
  411. /* MR10 */ ClassDeclStuff=(char *)calloc(MaxClassDeclStuff+1,sizeof(char));
  412. /* MR10 */ };
  413. /* MR10 */ strncat(ClassDeclStuff," ",MaxClassDeclStuff);
  414. /* MR10 */ strncat(ClassDeclStuff,LATEXT(1),MaxClassDeclStuff);
  415. /* MR22 */ do {
  416. /* MR22 */ if (0 == strcmp(LATEXT(1),"public")) break;
  417. /* MR22 */ if (0 == strcmp(LATEXT(1),"private")) break;
  418. /* MR22 */ if (0 == strcmp(LATEXT(1),"protected")) break;
  419. /* MR22 */ if (0 == strcmp(LATEXT(1),"virtual")) break;
  420. /* MR22 */ if (0 == strcmp(LATEXT(1),",")) break;
  421. /* MR22 */ if (0 == strcmp(LATEXT(1),":")) break;
  422. /* MR22 */ if (BaseClassName != NULL) break;
  423. /* MR22 */ BaseClassName=(char *)calloc(strlen(LATEXT(1))+1,sizeof(char));
  424. /* MR22 */ require(BaseClassName!=NULL, "rule grammar: cannot allocate base class name");
  425. /* MR22 */ strcpy(BaseClassName,LATEXT(1));
  426. /* MR22 */ } while (0);
  427. /* MR10 */
  428. zzCONSUME;
  429. zzLOOP(zztasp2);
  430. }
  431. zzEXIT(zztasp2);
  432. }
  433. }
  434. zzmatch(102);
  435. no_classes_found = 0;
  436. if ( class_nest_level>=1 ) {warn("cannot have nested classes");}
  437. else class_nest_level++;
  438. zzCONSUME;
  439. zzEXIT(zztasp1);
  440. return;
  441. fail:
  442. zzEXIT(zztasp1);
  443. CannotContinue=TRUE;
  444. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  445. zzresynch(setwd1, 0x40);
  446. }
  447. }
  448. void
  449. #ifdef __USE_PROTOS
  450. rule(void)
  451. #else
  452. rule()
  453. #endif
  454. {
  455. zzRULE;
  456. zzBLOCK(zztasp1);
  457. zzMake0;
  458. {
  459. ExceptionGroup *eg;
  460. RuleEntry *q; Junction *p; Graph r; int f, l; ECnode *e;
  461. set toksrefd, rulesrefd;
  462. char *pdecl=NULL, *ret=NULL, *a; CurRetDef = CurParmDef = NULL;
  463. CurExGroups = NULL;
  464. CurElementLabels = NULL;
  465. CurAstLabelsInActions = NULL; /* MR27 */
  466. /* We want a new element label hash table for each rule */
  467. if ( Elabel!=NULL ) killHashTable(Elabel);
  468. Elabel = newHashTable();
  469. attribsRefdFromAction = empty;
  470. zzmatch(NonTerminal);
  471. q=NULL;
  472. if ( hash_get(Rname, LATEXT(1))!=NULL ) {
  473. err(eMsg1("duplicate rule definition: '%s'",LATEXT(1)));
  474. CannotContinue=TRUE;
  475. }
  476. else
  477. {
  478. q = (RuleEntry *)hash_add(Rname,
  479. LATEXT(1),
  480. (Entry *)newRuleEntry(LATEXT(1)));
  481. CurRule = q->str;
  482. }
  483. CurRuleNode = q;
  484. f = CurFile; l = zzline;
  485. NumRules++;
  486. zzCONSUME;
  487. {
  488. zzBLOCK(zztasp2);
  489. zzMake0;
  490. {
  491. if ( (LA(1)==103) ) {
  492. zzmatch(103);
  493. if ( q!=NULL ) q->noAST = TRUE;
  494. zzCONSUME;
  495. }
  496. else {
  497. if ( (setwd1[LA(1)]&0x80) ) {
  498. }
  499. else {zzFAIL(1,zzerr4,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  500. }
  501. zzEXIT(zztasp2);
  502. }
  503. }
  504. {
  505. zzBLOCK(zztasp2);
  506. zzMake0;
  507. {
  508. ;
  509. if ( (setwd2[LA(1)]&0x1) ) {
  510. {
  511. zzBLOCK(zztasp3);
  512. zzMake0;
  513. {
  514. if ( (LA(1)==104) ) {
  515. zzmatch(104); zzCONSUME;
  516. }
  517. else {
  518. if ( (LA(1)==PassAction) ) {
  519. }
  520. else {zzFAIL(1,zzerr5,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  521. }
  522. zzEXIT(zztasp3);
  523. }
  524. }
  525. zzmatch(PassAction);
  526. pdecl = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  527. require(pdecl!=NULL, "rule rule: cannot allocate param decl");
  528. strcpy(pdecl, LATEXT(1));
  529. CurParmDef = pdecl;
  530. zzCONSUME;
  531. }
  532. else {
  533. if ( (setwd2[LA(1)]&0x2) ) {
  534. }
  535. else {zzFAIL(1,zzerr6,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  536. }
  537. zzEXIT(zztasp2);
  538. }
  539. }
  540. {
  541. zzBLOCK(zztasp2);
  542. zzMake0;
  543. {
  544. if ( (LA(1)==105) ) {
  545. zzmatch(105); zzCONSUME;
  546. zzmatch(PassAction);
  547. ret = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  548. require(ret!=NULL, "rule rule: cannot allocate ret type");
  549. strcpy(ret, LATEXT(1));
  550. CurRetDef = ret;
  551. zzCONSUME;
  552. }
  553. else {
  554. if ( (setwd2[LA(1)]&0x4) ) {
  555. }
  556. else {zzFAIL(1,zzerr7,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  557. }
  558. zzEXIT(zztasp2);
  559. }
  560. }
  561. {
  562. zzBLOCK(zztasp2);
  563. zzMake0;
  564. {
  565. if ( (LA(1)==QuotedTerm) ) {
  566. zzmatch(QuotedTerm);
  567. if ( q!=NULL ) q->egroup=mystrdup(LATEXT(1));
  568. zzCONSUME;
  569. }
  570. else {
  571. if ( (LA(1)==106) ) {
  572. }
  573. else {zzFAIL(1,zzerr8,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  574. }
  575. zzEXIT(zztasp2);
  576. }
  577. }
  578. if ( GenEClasseForRules && q!=NULL ) {
  579. e = newECnode;
  580. require(e!=NULL, "cannot allocate error class node");
  581. if ( q->egroup == NULL ) {a = q->str; a[0] = (char)toupper(a[0]);}
  582. else a = q->egroup;
  583. if ( Tnum( a ) == 0 )
  584. {
  585. e->tok = addTname( a );
  586. list_add(&eclasses, (char *)e);
  587. if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
  588. /* refers to itself */
  589. list_add(&(e->elist), mystrdup(q->str));
  590. }
  591. else {
  592. warn(eMsg1("default errclass for '%s' would conflict with token/errclass/tokclass",a));
  593. if ( q->egroup == NULL ) a[0] = (char)tolower(a[0]);
  594. free((char *)e);
  595. }
  596. }
  597. BlkLevel++;
  598. if (BlkLevel >= MAX_BLK_LEVEL) fatal("Blocks nested too deeply");
  599. /* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
  600. /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
  601. zzmatch(106);
  602. inAlt=1;
  603. zzCONSUME;
  604. block( &toksrefd, &rulesrefd );
  605. r = makeBlk(zzaArg(zztasp1,7),0, NULL /* pFirstSetSymbol */ );
  606. CurRuleBlk = (Junction *)r.left;
  607. CurRuleBlk->blockid = CurBlockID;
  608. CurRuleBlk->jtype = RuleBlk;
  609. if ( q!=NULL ) CurRuleBlk->rname = q->str;
  610. CurRuleBlk->file = f;
  611. CurRuleBlk->line = l;
  612. CurRuleBlk->pdecl = pdecl;
  613. CurRuleBlk->ret = ret;
  614. CurRuleBlk->lock = makelocks();
  615. CurRuleBlk->pred_lock = makelocks();
  616. CurRuleBlk->tokrefs = toksrefd;
  617. CurRuleBlk->rulerefs = rulesrefd;
  618. p = newJunction(); /* add EndRule Node */
  619. ((Junction *)r.right)->p1 = (Node *)p;
  620. r.right = (Node *) p;
  621. p->jtype = EndRule;
  622. p->lock = makelocks();
  623. p->pred_lock = makelocks();
  624. CurRuleBlk->end = p;
  625. if ( q!=NULL ) q->rulenum = NumRules;
  626. zzaArg(zztasp1,7) = r;
  627. /* MR23 */ CurBlockID_array[BlkLevel] = (-1);
  628. /* MR23 */ CurAltNum_array[BlkLevel] = (-1);
  629. --BlkLevel;
  630. altFixup();leFixup();egFixup();
  631. zzmatch(107);
  632. inAlt=0;
  633. zzCONSUME;
  634. {
  635. zzBLOCK(zztasp2);
  636. zzMake0;
  637. {
  638. if ( (LA(1)==Action) ) {
  639. zzmatch(Action);
  640. a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  641. require(a!=NULL, "rule rule: cannot allocate error action");
  642. strcpy(a, LATEXT(1));
  643. CurRuleBlk->erraction = a;
  644. zzCONSUME;
  645. }
  646. else {
  647. if ( (setwd2[LA(1)]&0x8) ) {
  648. }
  649. else {zzFAIL(1,zzerr9,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  650. }
  651. zzEXIT(zztasp2);
  652. }
  653. }
  654. {
  655. zzBLOCK(zztasp2);
  656. zzMake0;
  657. {
  658. while ( (LA(1)==133) ) {
  659. eg = exception_group();
  660. if ( eg!=NULL ) {
  661. list_add(&CurExGroups, (void *)eg);
  662. if (eg->label == NULL || *eg->label=='\0' ) q->has_rule_exception = 1;
  663. }
  664. zzLOOP(zztasp2);
  665. }
  666. zzEXIT(zztasp2);
  667. }
  668. }
  669. if ( q==NULL ) zzaArg(zztasp1,0 ).left = NULL; else zzaArg(zztasp1,0) = zzaArg(zztasp1,7);
  670. CurRuleBlk->exceptions = CurExGroups;
  671. CurRuleBlk->el_labels = CurElementLabels;
  672. CurRuleNode->ast_labels_in_actions = CurAstLabelsInActions;
  673. CurRuleNode = NULL;
  674. zzEXIT(zztasp1);
  675. return;
  676. fail:
  677. zzEXIT(zztasp1);
  678. CannotContinue=TRUE;
  679. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  680. zzresynch(setwd2, 0x10);
  681. }
  682. }
  683. void
  684. #ifdef __USE_PROTOS
  685. laction(void)
  686. #else
  687. laction()
  688. #endif
  689. {
  690. zzRULE;
  691. zzBLOCK(zztasp1);
  692. zzMake0;
  693. {
  694. char *a;
  695. zzmatch(108); zzCONSUME;
  696. zzmatch(Action);
  697. a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  698. require(a!=NULL, "rule laction: cannot allocate action");
  699. strcpy(a, LATEXT(1));
  700. list_add(&LexActions, a);
  701. zzCONSUME;
  702. zzEXIT(zztasp1);
  703. return;
  704. fail:
  705. zzEXIT(zztasp1);
  706. CannotContinue=TRUE;
  707. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  708. zzresynch(setwd2, 0x20);
  709. }
  710. }
  711. void
  712. #ifdef __USE_PROTOS
  713. lmember(void)
  714. #else
  715. lmember()
  716. #endif
  717. {
  718. zzRULE;
  719. zzBLOCK(zztasp1);
  720. zzMake0;
  721. {
  722. char *a;
  723. zzmatch(109); zzCONSUME;
  724. zzmatch(Action);
  725. /* MR1 */ if (! GenCC) {
  726. /* MR1 */ err("Use #lexmember only in C++ mode (to insert code in DLG class header");
  727. /* MR1 */ } else {
  728. /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  729. /* MR1 */ require(a!=NULL, "rule lmember: cannot allocate action");
  730. /* MR1 */ strcpy(a, LATEXT(1));
  731. /* MR1 */ list_add(&LexMemberActions, a);
  732. /* MR1 */ };
  733. /* MR1 */
  734. zzCONSUME;
  735. zzEXIT(zztasp1);
  736. return;
  737. fail:
  738. zzEXIT(zztasp1);
  739. CannotContinue=TRUE;
  740. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  741. zzresynch(setwd2, 0x40);
  742. }
  743. }
  744. void
  745. #ifdef __USE_PROTOS
  746. lprefix(void)
  747. #else
  748. lprefix()
  749. #endif
  750. {
  751. zzRULE;
  752. zzBLOCK(zztasp1);
  753. zzMake0;
  754. {
  755. char *a;
  756. zzmatch(110); zzCONSUME;
  757. zzmatch(Action);
  758. /* MR1 */ if (! GenCC) {
  759. /* MR1 */ err("Use #lexprefix only in C++ mode (to insert code in DLG class header");
  760. /* MR1 */ } else {
  761. /* MR1 */ a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  762. /* MR1 */ require(a!=NULL, "rule lprefix: cannot allocate action");
  763. /* MR1 */ strcpy(a, LATEXT(1));
  764. /* MR1 */ list_add(&LexPrefixActions, a);
  765. /* MR1 */ };
  766. /* MR1 */
  767. zzCONSUME;
  768. zzEXIT(zztasp1);
  769. return;
  770. fail:
  771. zzEXIT(zztasp1);
  772. CannotContinue=TRUE;
  773. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  774. zzresynch(setwd2, 0x80);
  775. }
  776. }
  777. void
  778. #ifdef __USE_PROTOS
  779. aPred(void)
  780. #else
  781. aPred()
  782. #endif
  783. {
  784. zzRULE;
  785. zzBLOCK(zztasp1);
  786. zzMake0;
  787. {
  788. PredEntry *predEntry=NULL;
  789. char *name=NULL;
  790. Predicate *predExpr=NULL;
  791. char *predLiteral=NULL;
  792. int save_file;
  793. int save_line;
  794. int predExprPresent=0;
  795. zzmatch(111);
  796. MR_usingPredNames=1; /* will need to use -mrhoist version of genPredTree */
  797. zzCONSUME;
  798. zzmatch(TokenTerm);
  799. name=mystrdup(LATEXT(1));
  800. zzCONSUME;
  801. /* don't free - referenced in predicates */
  802. CurPredName=(char *)calloc(1,strlen(name) + 10);
  803. strcat(CurPredName,"#pred ");
  804. strcat(CurPredName,name);
  805. predEntry=(PredEntry *) hash_get(Pname,name);
  806. if (predEntry != NULL) {
  807. warnFL(eMsg1("#pred %s previously defined - ignored",name),
  808. FileStr[action_file],action_line);
  809. name=NULL;
  810. };
  811. {
  812. zzBLOCK(zztasp2);
  813. zzMake0;
  814. {
  815. if ( (LA(1)==Pred) ) {
  816. zzmatch(Pred);
  817. predLiteral=mystrdup(LATEXT(1));
  818. save_line=action_line;
  819. save_file=action_file;
  820. zzCONSUME;
  821. {
  822. zzBLOCK(zztasp3);
  823. zzMake0;
  824. {
  825. if ( (setwd3[LA(1)]&0x1) ) {
  826. predExpr = predOrExpr();
  827. predExprPresent=1;
  828. }
  829. else {
  830. if ( (setwd3[LA(1)]&0x2) ) {
  831. }
  832. else {zzFAIL(1,zzerr10,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  833. }
  834. zzEXIT(zztasp3);
  835. }
  836. }
  837. if (predLiteral != NULL && name != NULL) {
  838. /*
  839. * predExpr may be NULL due to syntax errors
  840. * or simply omitted by the user
  841. */
  842. predEntry=newPredEntry(name);
  843. predEntry->file=save_file;
  844. predEntry->line=save_line;
  845. predExpr=MR_predFlatten(predExpr);
  846. predEntry->predLiteral=predLiteral;
  847. if (! predExprPresent || predExpr == NULL) {
  848. predExpr=new_pred();
  849. predExpr->expr=predLiteral;
  850. predExpr->source=newActionNode();
  851. predExpr->source->action=predExpr->expr;
  852. predExpr->source->rname=CurPredName;
  853. predExpr->source->line=action_line;
  854. predExpr->source->file=action_file;
  855. predExpr->source->is_predicate=1;
  856. predExpr->k=predicateLookaheadDepth(predExpr->source);
  857. };
  858. predEntry->pred=predExpr;
  859. hash_add(Pname,name,(Entry *)predEntry);
  860. predExpr=NULL;
  861. };
  862. predicate_free(predExpr);
  863. }
  864. else {
  865. if ( (setwd3[LA(1)]&0x4) ) {
  866. save_line=zzline; save_file=CurFile;
  867. predExpr = predOrExpr();
  868. if (predExpr != NULL && name != NULL) {
  869. predEntry=newPredEntry(name);
  870. predEntry->file=CurFile;
  871. predEntry->line=zzline;
  872. predExpr=MR_predFlatten(predExpr);
  873. predEntry->pred=predExpr;
  874. hash_add(Pname,name,(Entry *)predEntry);
  875. predExpr=NULL;
  876. };
  877. predicate_free(predExpr);
  878. }
  879. else {zzFAIL(1,zzerr11,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  880. }
  881. zzEXIT(zztasp2);
  882. }
  883. }
  884. {
  885. zzBLOCK(zztasp2);
  886. zzMake0;
  887. {
  888. if ( (LA(1)==107) ) {
  889. zzmatch(107); zzCONSUME;
  890. }
  891. else {
  892. if ( (setwd3[LA(1)]&0x8) ) {
  893. }
  894. else {zzFAIL(1,zzerr12,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  895. }
  896. zzEXIT(zztasp2);
  897. }
  898. }
  899. zzEXIT(zztasp1);
  900. return;
  901. fail:
  902. zzEXIT(zztasp1);
  903. predicate_free(predExpr);
  904. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  905. zzresynch(setwd3, 0x10);
  906. }
  907. }
  908. Predicate *
  909. #ifdef __USE_PROTOS
  910. predOrExpr(void)
  911. #else
  912. predOrExpr()
  913. #endif
  914. {
  915. Predicate * _retv;
  916. zzRULE;
  917. zzBLOCK(zztasp1);
  918. PCCTS_PURIFY(_retv,sizeof(Predicate * ))
  919. zzMake0;
  920. {
  921. Predicate *ORnode;
  922. Predicate *predExpr;
  923. Predicate **tail=NULL;
  924. predExpr = predAndExpr();
  925. ORnode=new_pred();
  926. ORnode->expr=PRED_OR_LIST;
  927. if (predExpr != NULL) {
  928. ORnode->down=predExpr;
  929. tail=&predExpr->right;
  930. };
  931. {
  932. zzBLOCK(zztasp2);
  933. zzMake0;
  934. {
  935. while ( (LA(1)==112) ) {
  936. zzmatch(112); zzCONSUME;
  937. predExpr = predAndExpr();
  938. if (predExpr != NULL) {
  939. *tail=predExpr;
  940. tail=&predExpr->right;
  941. };
  942. zzLOOP(zztasp2);
  943. }
  944. zzEXIT(zztasp2);
  945. }
  946. }
  947. _retv=ORnode;
  948. ORnode=NULL;
  949. zzEXIT(zztasp1);
  950. return _retv;
  951. fail:
  952. zzEXIT(zztasp1);
  953. predicate_free(ORnode);
  954. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  955. zzresynch(setwd3, 0x20);
  956. return _retv;
  957. }
  958. }
  959. Predicate *
  960. #ifdef __USE_PROTOS
  961. predAndExpr(void)
  962. #else
  963. predAndExpr()
  964. #endif
  965. {
  966. Predicate * _retv;
  967. zzRULE;
  968. zzBLOCK(zztasp1);
  969. PCCTS_PURIFY(_retv,sizeof(Predicate * ))
  970. zzMake0;
  971. {
  972. Predicate *ANDnode;
  973. Predicate *predExpr;
  974. Predicate **tail=NULL;
  975. predExpr = predPrimary();
  976. ANDnode=new_pred();
  977. ANDnode->expr=PRED_AND_LIST;
  978. if (predExpr != NULL) {
  979. ANDnode->down=predExpr;
  980. tail=&predExpr->right;
  981. };
  982. {
  983. zzBLOCK(zztasp2);
  984. zzMake0;
  985. {
  986. while ( (LA(1)==113) ) {
  987. zzmatch(113); zzCONSUME;
  988. predExpr = predPrimary();
  989. if (predExpr != NULL) {
  990. *tail=predExpr;
  991. tail=&predExpr->right;
  992. };
  993. zzLOOP(zztasp2);
  994. }
  995. zzEXIT(zztasp2);
  996. }
  997. }
  998. _retv=ANDnode;
  999. ANDnode=NULL;
  1000. zzEXIT(zztasp1);
  1001. return _retv;
  1002. fail:
  1003. zzEXIT(zztasp1);
  1004. predicate_free(ANDnode);
  1005. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1006. zzresynch(setwd3, 0x40);
  1007. return _retv;
  1008. }
  1009. }
  1010. Predicate *
  1011. #ifdef __USE_PROTOS
  1012. predPrimary(void)
  1013. #else
  1014. predPrimary()
  1015. #endif
  1016. {
  1017. Predicate * _retv;
  1018. zzRULE;
  1019. zzBLOCK(zztasp1);
  1020. PCCTS_PURIFY(_retv,sizeof(Predicate * ))
  1021. zzMake0;
  1022. {
  1023. char *name=NULL;
  1024. PredEntry *predEntry=NULL;
  1025. Predicate *predExpr=NULL;
  1026. if ( (LA(1)==TokenTerm) ) {
  1027. zzmatch(TokenTerm);
  1028. name=mystrdup(LATEXT(1));
  1029. zzCONSUME;
  1030. predEntry=(PredEntry *) hash_get(Pname,name);
  1031. if (predEntry == NULL) {
  1032. warnFL(eMsg1("no previously defined #pred with name \"%s\"",name),
  1033. FileStr[CurFile],zzline);
  1034. name=NULL;
  1035. _retv=NULL;
  1036. } else {
  1037. predExpr=predicate_dup(predEntry->pred);
  1038. predExpr->predEntry=predEntry;
  1039. _retv=predExpr;
  1040. };
  1041. }
  1042. else {
  1043. if ( (LA(1)==114) ) {
  1044. zzmatch(114); zzCONSUME;
  1045. predExpr = predOrExpr();
  1046. zzmatch(115);
  1047. _retv=predExpr;
  1048. zzCONSUME;
  1049. }
  1050. else {
  1051. if ( (LA(1)==103) ) {
  1052. zzmatch(103); zzCONSUME;
  1053. predExpr = predPrimary();
  1054. predExpr->inverted=!predExpr->inverted;
  1055. _retv=predExpr;
  1056. }
  1057. else {zzFAIL(1,zzerr13,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1058. }
  1059. }
  1060. zzEXIT(zztasp1);
  1061. return _retv;
  1062. fail:
  1063. zzEXIT(zztasp1);
  1064. predicate_free(predExpr);
  1065. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1066. zzresynch(setwd3, 0x80);
  1067. return _retv;
  1068. }
  1069. }
  1070. void
  1071. #ifdef __USE_PROTOS
  1072. aLexclass(void)
  1073. #else
  1074. aLexclass()
  1075. #endif
  1076. {
  1077. zzRULE;
  1078. zzBLOCK(zztasp1);
  1079. zzMake0;
  1080. {
  1081. zzmatch(116); zzCONSUME;
  1082. zzmatch(TokenTerm);
  1083. lexclass(mystrdup(LATEXT(1)));
  1084. zzCONSUME;
  1085. zzEXIT(zztasp1);
  1086. return;
  1087. fail:
  1088. zzEXIT(zztasp1);
  1089. CannotContinue=TRUE;
  1090. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1091. zzresynch(setwd4, 0x1);
  1092. }
  1093. }
  1094. void
  1095. #ifdef __USE_PROTOS
  1096. error(void)
  1097. #else
  1098. error()
  1099. #endif
  1100. {
  1101. zzRULE;
  1102. zzBLOCK(zztasp1);
  1103. zzMake0;
  1104. {
  1105. char *t=NULL; ECnode *e; int go=1; TermEntry *p;
  1106. zzmatch(117); zzCONSUME;
  1107. {
  1108. zzBLOCK(zztasp2);
  1109. zzMake0;
  1110. {
  1111. ;
  1112. if ( (LA(1)==TokenTerm) ) {
  1113. zzmatch(TokenTerm);
  1114. t=mystrdup(LATEXT(1));
  1115. zzCONSUME;
  1116. }
  1117. else {
  1118. if ( (LA(1)==QuotedTerm) ) {
  1119. zzmatch(QuotedTerm);
  1120. t=mystrdup(LATEXT(1));
  1121. zzCONSUME;
  1122. }
  1123. else {zzFAIL(1,zzerr14,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1124. }
  1125. zzEXIT(zztasp2);
  1126. }
  1127. }
  1128. e = newECnode;
  1129. require(e!=NULL, "cannot allocate error class node");
  1130. e->lexclass = CurrentLexClass;
  1131. if ( Tnum( (t=StripQuotes(t)) ) == 0 )
  1132. {
  1133. if ( hash_get(Texpr, t) != NULL )
  1134. warn(eMsg1("errclass name conflicts with regular expression '%s'",t));
  1135. e->tok = addTname( t );
  1136. set_orel(e->tok, &imag_tokens);
  1137. require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
  1138. "hash table mechanism is broken");
  1139. p->classname = 1; /* entry is errclass name, not token */
  1140. list_add(&eclasses, (char *)e);
  1141. }
  1142. else
  1143. {
  1144. warn(eMsg1("redefinition of errclass or conflict w/token or tokclass '%s'; ignored",t));
  1145. free( (char *)e );
  1146. go=0;
  1147. }
  1148. zzmatch(102); zzCONSUME;
  1149. {
  1150. zzBLOCK(zztasp2);
  1151. zzMake0;
  1152. {
  1153. if ( (LA(1)==NonTerminal) ) {
  1154. zzmatch(NonTerminal);
  1155. if ( go ) t=mystrdup(LATEXT(1));
  1156. zzCONSUME;
  1157. }
  1158. else {
  1159. if ( (LA(1)==TokenTerm) ) {
  1160. zzmatch(TokenTerm);
  1161. if ( go ) t=mystrdup(LATEXT(1));
  1162. zzCONSUME;
  1163. }
  1164. else {
  1165. if ( (LA(1)==QuotedTerm) ) {
  1166. zzmatch(QuotedTerm);
  1167. if ( go ) t=mystrdup(LATEXT(1));
  1168. zzCONSUME;
  1169. }
  1170. else {zzFAIL(1,zzerr15,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1171. }
  1172. }
  1173. zzEXIT(zztasp2);
  1174. }
  1175. }
  1176. if ( go ) list_add(&(e->elist), t);
  1177. {
  1178. zzBLOCK(zztasp2);
  1179. zzMake0;
  1180. {
  1181. while ( (setwd4[LA(1)]&0x2) ) {
  1182. {
  1183. zzBLOCK(zztasp3);
  1184. zzMake0;
  1185. {
  1186. if ( (LA(1)==NonTerminal) ) {
  1187. zzmatch(NonTerminal);
  1188. if ( go ) t=mystrdup(LATEXT(1));
  1189. zzCONSUME;
  1190. }
  1191. else {
  1192. if ( (LA(1)==TokenTerm) ) {
  1193. zzmatch(TokenTerm);
  1194. if ( go ) t=mystrdup(LATEXT(1));
  1195. zzCONSUME;
  1196. }
  1197. else {
  1198. if ( (LA(1)==QuotedTerm) ) {
  1199. zzmatch(QuotedTerm);
  1200. if ( go ) t=mystrdup(LATEXT(1));
  1201. zzCONSUME;
  1202. }
  1203. else {zzFAIL(1,zzerr16,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1204. }
  1205. }
  1206. zzEXIT(zztasp3);
  1207. }
  1208. }
  1209. if ( go ) list_add(&(e->elist), t);
  1210. zzLOOP(zztasp2);
  1211. }
  1212. zzEXIT(zztasp2);
  1213. }
  1214. }
  1215. zzmatch(98); zzCONSUME;
  1216. zzEXIT(zztasp1);
  1217. return;
  1218. fail:
  1219. zzEXIT(zztasp1);
  1220. CannotContinue=TRUE;
  1221. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1222. zzresynch(setwd4, 0x4);
  1223. }
  1224. }
  1225. void
  1226. #ifdef __USE_PROTOS
  1227. tclass(void)
  1228. #else
  1229. tclass()
  1230. #endif
  1231. {
  1232. zzRULE;
  1233. zzBLOCK(zztasp1);
  1234. zzMake0;
  1235. {
  1236. char *t=NULL; TCnode *e; int go=1,tok,totok; TermEntry *p, *term, *toterm;
  1237. char *akaString=NULL; int save_file; int save_line;
  1238. char *totext=NULL;
  1239. zzmatch(118); zzCONSUME;
  1240. zzmatch(TokenTerm);
  1241. t=mystrdup(LATEXT(1));
  1242. zzCONSUME;
  1243. e = newTCnode;
  1244. require(e!=NULL, "cannot allocate token class node");
  1245. e->lexclass = CurrentLexClass;
  1246. if ( Tnum( t ) == 0 )
  1247. {
  1248. e->tok = addTname( t );
  1249. set_orel(e->tok, &imag_tokens);
  1250. set_orel(e->tok, &tokclasses);
  1251. require((p=(TermEntry *)hash_get(Tname, t)) != NULL,
  1252. "hash table mechanism is broken");
  1253. p->classname = 1; /* entry is class name, not token */
  1254. p->tclass = e; /* save ptr to this tclass def */
  1255. list_add(&tclasses, (char *)e);
  1256. }
  1257. else
  1258. {
  1259. warn(eMsg1("redefinition of tokclass or conflict w/token '%s'; ignored",t));
  1260. free( (char *)e );
  1261. go=0;
  1262. }
  1263. {
  1264. zzBLOCK(zztasp2);
  1265. zzMake0;
  1266. {
  1267. if ( (LA(1)==114) ) {
  1268. zzmatch(114); zzCONSUME;
  1269. zzmatch(QuotedTerm);
  1270. akaString=mystrdup(StripQuotes(LATEXT(1)));
  1271. /* MR11 */ save_file=CurFile;save_line=zzline;
  1272. /* MR23 */
  1273. zzCONSUME;
  1274. zzmatch(115); zzCONSUME;
  1275. }
  1276. else {
  1277. if ( (LA(1)==102) ) {
  1278. }
  1279. else {zzFAIL(1,zzerr17,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1280. }
  1281. zzEXIT(zztasp2);
  1282. }
  1283. }
  1284. /* MR23 */ if (p!= NULL && akaString != NULL) {
  1285. /* MR23 */ if (p->akaString != NULL) {
  1286. /* MR23 */ if (strcmp(p->akaString,akaString) != 0) {
  1287. /* MR23 */ warnFL(eMsg2("this #tokclass statement conflicts with a previous #tokclass %s(\"%s\") statement",
  1288. /* MR23 */ t,p->akaString),
  1289. /* MR23 */ FileStr[save_file],save_line);
  1290. /* MR23 */ };
  1291. /* MR23 */ } else {
  1292. /* MR23 */ p->akaString=akaString;
  1293. /* MR23 */ };
  1294. /* MR23 */ };
  1295. /* MR23 */
  1296. zzmatch(102); zzCONSUME;
  1297. {
  1298. zzBLOCK(zztasp2);
  1299. int zzcnt=1;
  1300. zzMake0;
  1301. {
  1302. do {
  1303. {
  1304. zzBLOCK(zztasp3);
  1305. zzMake0;
  1306. {
  1307. if ( (LA(1)==TokenTerm) ) {
  1308. zzmatch(TokenTerm);
  1309. if ( go ) {
  1310. term = (TermEntry *) hash_get(Tname, LATEXT(1));
  1311. if ( term==NULL && UserDefdTokens ) {
  1312. err("implicit token definition not allowed with #tokdefs");
  1313. go = 0;
  1314. }
  1315. else {t=mystrdup(LATEXT(1)); tok=addTname(LATEXT(1));}
  1316. }
  1317. zzCONSUME;
  1318. {
  1319. zzBLOCK(zztasp4);
  1320. zzMake0;
  1321. {
  1322. if ( (LA(1)==119) ) {
  1323. zzmatch(119); zzCONSUME;
  1324. zzmatch(TokenTerm);
  1325. if ( go ) {
  1326. toterm = (TermEntry *) hash_get(Tname, LATEXT(1));
  1327. if ( toterm==NULL && UserDefdTokens ) {
  1328. err("implicit token definition not allowed with #tokdefs");
  1329. go = 0;
  1330. } else {
  1331. totext=mystrdup(LATEXT(1)); totok=addTname(LATEXT(1));
  1332. }
  1333. }
  1334. zzCONSUME;
  1335. }
  1336. else {
  1337. if ( (setwd4[LA(1)]&0x8) ) {
  1338. }
  1339. else {zzFAIL(1,zzerr18,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1340. }
  1341. zzEXIT(zztasp4);
  1342. }
  1343. }
  1344. }
  1345. else {
  1346. if ( (LA(1)==QuotedTerm) ) {
  1347. zzmatch(QuotedTerm);
  1348. if ( go ) {
  1349. term = (TermEntry *) hash_get(Texpr, LATEXT(1));
  1350. if ( term==NULL && UserDefdTokens ) {
  1351. err("implicit token definition not allowed with #tokdefs");
  1352. go = 0;
  1353. }
  1354. else {t=mystrdup(LATEXT(1)); tok=addTexpr(LATEXT(1));}
  1355. }
  1356. zzCONSUME;
  1357. }
  1358. else {zzFAIL(1,zzerr19,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1359. }
  1360. zzEXIT(zztasp3);
  1361. }
  1362. }
  1363. if ( go ) {
  1364. if (totext == NULL) {
  1365. list_add(&(e->tlist), t);
  1366. } else {
  1367. list_add(&(e->tlist),"..");
  1368. list_add(&(e->tlist),t);
  1369. list_add(&(e->tlist),totext);
  1370. }
  1371. totext=NULL;
  1372. }
  1373. zzLOOP(zztasp2);
  1374. } while ( (setwd4[LA(1)]&0x10) );
  1375. zzEXIT(zztasp2);
  1376. }
  1377. }
  1378. zzmatch(98); zzCONSUME;
  1379. zzEXIT(zztasp1);
  1380. return;
  1381. fail:
  1382. zzEXIT(zztasp1);
  1383. CannotContinue=TRUE;
  1384. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1385. zzresynch(setwd4, 0x20);
  1386. }
  1387. }
  1388. void
  1389. #ifdef __USE_PROTOS
  1390. token(void)
  1391. #else
  1392. token()
  1393. #endif
  1394. {
  1395. zzRULE;
  1396. zzBLOCK(zztasp1);
  1397. zzMake0;
  1398. {
  1399. char *t=NULL, *e=NULL, *a=NULL; int tnum=0;
  1400. char *akaString=NULL; TermEntry *te;int save_file=0,save_line=0;
  1401. zzmatch(120);
  1402. tokenActionActive=1;
  1403. zzCONSUME;
  1404. {
  1405. zzBLOCK(zztasp2);
  1406. zzMake0;
  1407. {
  1408. if ( (LA(1)==TokenTerm) ) {
  1409. zzmatch(TokenTerm);
  1410. t=mystrdup(LATEXT(1));
  1411. zzCONSUME;
  1412. {
  1413. zzBLOCK(zztasp3);
  1414. zzMake0;
  1415. {
  1416. if ( (LA(1)==114) ) {
  1417. zzmatch(114); zzCONSUME;
  1418. zzmatch(QuotedTerm);
  1419. akaString=mystrdup(StripQuotes(LATEXT(1)));
  1420. /* MR11 */ save_file=CurFile;save_line=zzline;
  1421. /* MR11 */
  1422. zzCONSUME;
  1423. zzmatch(115); zzCONSUME;
  1424. }
  1425. else {
  1426. if ( (setwd4[LA(1)]&0x40) ) {
  1427. }
  1428. else {zzFAIL(1,zzerr20,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1429. }
  1430. zzEXIT(zztasp3);
  1431. }
  1432. }
  1433. {
  1434. zzBLOCK(zztasp3);
  1435. zzMake0;
  1436. {
  1437. if ( (LA(1)==121) ) {
  1438. zzmatch(121); zzCONSUME;
  1439. zzmatch(122);
  1440. tnum = atoi(LATEXT(1));
  1441. zzCONSUME;
  1442. }
  1443. else {
  1444. if ( (setwd4[LA(1)]&0x80) ) {
  1445. }
  1446. else {zzFAIL(1,zzerr21,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1447. }
  1448. zzEXIT(zztasp3);
  1449. }
  1450. }
  1451. }
  1452. else {
  1453. if ( (setwd5[LA(1)]&0x1) ) {
  1454. }
  1455. else {zzFAIL(1,zzerr22,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1456. }
  1457. zzEXIT(zztasp2);
  1458. }
  1459. }
  1460. {
  1461. zzBLOCK(zztasp2);
  1462. zzMake0;
  1463. {
  1464. if ( (LA(1)==QuotedTerm) ) {
  1465. zzmatch(QuotedTerm);
  1466. e=mystrdup(LATEXT(1));
  1467. zzCONSUME;
  1468. }
  1469. else {
  1470. if ( (setwd5[LA(1)]&0x2) ) {
  1471. }
  1472. else {zzFAIL(1,zzerr23,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1473. }
  1474. zzEXIT(zztasp2);
  1475. }
  1476. }
  1477. {
  1478. zzBLOCK(zztasp2);
  1479. zzMake0;
  1480. {
  1481. if ( (LA(1)==Action) ) {
  1482. zzmatch(Action);
  1483. a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  1484. require(a!=NULL, "rule token: cannot allocate action");
  1485. strcpy(a, LATEXT(1));
  1486. zzCONSUME;
  1487. }
  1488. else {
  1489. if ( (setwd5[LA(1)]&0x4) ) {
  1490. }
  1491. else {zzFAIL(1,zzerr24,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1492. }
  1493. zzEXIT(zztasp2);
  1494. }
  1495. }
  1496. {
  1497. zzBLOCK(zztasp2);
  1498. zzMake0;
  1499. {
  1500. if ( (LA(1)==107) ) {
  1501. zzmatch(107); zzCONSUME;
  1502. }
  1503. else {
  1504. if ( (setwd5[LA(1)]&0x8) ) {
  1505. }
  1506. else {zzFAIL(1,zzerr25,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1507. }
  1508. zzEXIT(zztasp2);
  1509. }
  1510. }
  1511. chkToken(t, e, a, tnum);
  1512. if (t != NULL) {
  1513. te=(TermEntry *)hash_get(Tname,t);
  1514. if (te != NULL && akaString != NULL) {
  1515. if (te->akaString != NULL) {
  1516. if (strcmp(te->akaString,akaString) != 0) {
  1517. warnFL(eMsg2("this #token statement conflicts with a previous #token %s(\"%s\") statement",
  1518. t,te->akaString),
  1519. FileStr[save_file],save_line);
  1520. };
  1521. } else {
  1522. te->akaString=akaString;
  1523. };
  1524. };
  1525. };
  1526. zzEXIT(zztasp1);
  1527. return;
  1528. fail:
  1529. zzEXIT(zztasp1);
  1530. CannotContinue=TRUE;
  1531. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1532. zzresynch(setwd5, 0x10);
  1533. }
  1534. }
  1535. void
  1536. #ifdef __USE_PROTOS
  1537. block(set * toksrefd,set * rulesrefd)
  1538. #else
  1539. block(toksrefd,rulesrefd)
  1540. set *toksrefd;
  1541. set *rulesrefd ;
  1542. #endif
  1543. {
  1544. zzRULE;
  1545. zzBLOCK(zztasp1);
  1546. zzMake0;
  1547. {
  1548. Graph g, b;
  1549. set saveblah;
  1550. int saveinalt = inAlt;
  1551. ExceptionGroup *eg;
  1552. * toksrefd = empty;
  1553. * rulesrefd = empty;
  1554. set_clr(AST_nodes_refd_in_actions);
  1555. CurBlockID++;
  1556. /* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
  1557. CurAltNum = 1;
  1558. /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
  1559. saveblah = attribsRefdFromAction;
  1560. attribsRefdFromAction = empty;
  1561. alt( toksrefd,rulesrefd );
  1562. b = g = zzaArg(zztasp1,1);
  1563. if ( ((Junction *)g.left)->p1->ntype == nAction )
  1564. {
  1565. ActionNode *actionNode=(ActionNode *)
  1566. ( ( (Junction *)g.left) ->p1);
  1567. if (!actionNode->is_predicate )
  1568. {
  1569. actionNode->init_action = TRUE;
  1570. /* MR12c */ if (actionNode->noHoist) {
  1571. /* MR12c */ errFL("<<nohoist>> appears as init-action - use <<>> <<nohoist>>",
  1572. /* MR12c */ FileStr[actionNode->file],actionNode->line);
  1573. /* MR12c */ };
  1574. }
  1575. }
  1576. ((Junction *)g.left)->blockid = CurBlockID;
  1577. {
  1578. zzBLOCK(zztasp2);
  1579. zzMake0;
  1580. {
  1581. while ( (LA(1)==133) ) {
  1582. eg = exception_group();
  1583. if ( eg!=NULL ) {
  1584. /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
  1585. /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
  1586. list_add(&CurExGroups, (void *)eg);
  1587. }
  1588. zzLOOP(zztasp2);
  1589. }
  1590. zzEXIT(zztasp2);
  1591. }
  1592. }
  1593. CurAltNum++;
  1594. /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
  1595. {
  1596. zzBLOCK(zztasp2);
  1597. zzMake0;
  1598. {
  1599. while ( (LA(1)==123) ) {
  1600. zzmatch(123);
  1601. inAlt=1;
  1602. zzCONSUME;
  1603. alt( toksrefd,rulesrefd );
  1604. g = Or(g, zzaArg(zztasp2,2));
  1605. ((Junction *)g.left)->blockid = CurBlockID;
  1606. {
  1607. zzBLOCK(zztasp3);
  1608. zzMake0;
  1609. {
  1610. while ( (LA(1)==133) ) {
  1611. eg = exception_group();
  1612. if ( eg!=NULL ) {
  1613. /* MR7 ***** eg->altID = makeAltID(CurBlockID,CurAltNum); *****/
  1614. /* MR7 ***** CurAltStart->exception_label = eg->altID; *****/
  1615. list_add(&CurExGroups, (void *)eg);
  1616. }
  1617. zzLOOP(zztasp3);
  1618. }
  1619. zzEXIT(zztasp3);
  1620. }
  1621. }
  1622. CurAltNum++;
  1623. /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
  1624. zzLOOP(zztasp2);
  1625. }
  1626. zzEXIT(zztasp2);
  1627. }
  1628. }
  1629. zzaArg(zztasp1,0) = b;
  1630. attribsRefdFromAction = saveblah; inAlt = saveinalt;
  1631. zzEXIT(zztasp1);
  1632. return;
  1633. fail:
  1634. zzEXIT(zztasp1);
  1635. CannotContinue=TRUE;
  1636. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1637. zzresynch(setwd5, 0x20);
  1638. }
  1639. }
  1640. void
  1641. #ifdef __USE_PROTOS
  1642. alt(set * toksrefd,set * rulesrefd)
  1643. #else
  1644. alt(toksrefd,rulesrefd)
  1645. set *toksrefd;
  1646. set *rulesrefd ;
  1647. #endif
  1648. {
  1649. zzRULE;
  1650. zzBLOCK(zztasp1);
  1651. zzMake0;
  1652. {
  1653. int n=0; Graph g; int e_num=0, old_not=0; Node *node; set elems, dif;
  1654. int first_on_line = 1, use_def_MT_handler = 0;
  1655. g.left=NULL; g.right=NULL;
  1656. CurAltStart = NULL;
  1657. elems = empty;
  1658. inAlt = 1;
  1659. {
  1660. zzBLOCK(zztasp2);
  1661. zzMake0;
  1662. {
  1663. if ( (LA(1)==88) ) {
  1664. zzmatch(88);
  1665. use_def_MT_handler = 1;
  1666. zzCONSUME;
  1667. }
  1668. else {
  1669. if ( (setwd5[LA(1)]&0x40) ) {
  1670. }
  1671. else {zzFAIL(1,zzerr26,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1672. }
  1673. zzEXIT(zztasp2);
  1674. }
  1675. }
  1676. {
  1677. zzBLOCK(zztasp2);
  1678. zzMake0;
  1679. {
  1680. ;
  1681. while ( (setwd5[LA(1)]&0x80) ) {
  1682. {
  1683. zzBLOCK(zztasp3);
  1684. zzMake0;
  1685. {
  1686. old_not=0;
  1687. if ( (LA(1)==124) ) {
  1688. zzmatch(124);
  1689. old_not=1;
  1690. zzCONSUME;
  1691. }
  1692. else {
  1693. if ( (setwd6[LA(1)]&0x1) ) {
  1694. }
  1695. else {zzFAIL(1,zzerr27,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1696. }
  1697. zzEXIT(zztasp3);
  1698. }
  1699. }
  1700. node = element( old_not, first_on_line, use_def_MT_handler );
  1701. if ( node!=NULL && node->ntype!=nAction ) first_on_line = 0;
  1702. if ( zzaArg(zztasp2,2 ).left!=NULL ) {
  1703. g = Cat(g, zzaArg(zztasp2,2));
  1704. n++;
  1705. if ( node!=NULL ) {
  1706. if ( node->ntype!=nAction ) e_num++;
  1707. /* record record number of all rule and token refs */
  1708. if ( node->ntype==nToken ) {
  1709. TokNode *tk = (TokNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1;
  1710. tk->elnum = e_num;
  1711. set_orel(e_num, &elems);
  1712. }
  1713. else if ( node->ntype==nRuleRef ) {
  1714. RuleRefNode *rn = (RuleRefNode *)((Junction *)zzaArg(zztasp2,2 ).left)->p1;
  1715. rn->elnum = e_num;
  1716. set_orel(e_num, rulesrefd);
  1717. }
  1718. }
  1719. }
  1720. zzLOOP(zztasp2);
  1721. }
  1722. zzEXIT(zztasp2);
  1723. }
  1724. }
  1725. if ( n == 0 ) g = emptyAlt();
  1726. zzaArg(zztasp1,0) = g;
  1727. /* We want to reduce number of LT(i) calls and the number of
  1728. * local attribute variables in C++ mode (for moment, later we'll
  1729. * do for C also). However, if trees are being built, they
  1730. * require most of the attrib variables to create the tree nodes
  1731. * with; therefore, we gen a token ptr for each token ref in C++
  1732. */
  1733. if ( GenCC && !GenAST )
  1734. {
  1735. /* This now free's the temp set -ATG 5/6/95 */
  1736. set temp;
  1737. temp = set_and(elems, attribsRefdFromAction);
  1738. set_orin( toksrefd, temp);
  1739. set_free(temp);
  1740. }
  1741. else set_orin( toksrefd, elems);
  1742. if ( GenCC ) {
  1743. dif = set_dif(attribsRefdFromAction, elems);
  1744. if ( set_deg(dif)>0 )
  1745. err("one or more $i in action(s) refer to non-token elements");
  1746. set_free(dif);
  1747. }
  1748. set_free(elems);
  1749. set_free(attribsRefdFromAction);
  1750. inAlt = 0;
  1751. zzEXIT(zztasp1);
  1752. return;
  1753. fail:
  1754. zzEXIT(zztasp1);
  1755. CannotContinue=TRUE;
  1756. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1757. zzresynch(setwd6, 0x2);
  1758. }
  1759. }
  1760. LabelEntry *
  1761. #ifdef __USE_PROTOS
  1762. element_label(void)
  1763. #else
  1764. element_label()
  1765. #endif
  1766. {
  1767. LabelEntry * _retv;
  1768. zzRULE;
  1769. zzBLOCK(zztasp1);
  1770. PCCTS_PURIFY(_retv,sizeof(LabelEntry * ))
  1771. zzMake0;
  1772. {
  1773. TermEntry *t=NULL; LabelEntry *l=NULL; RuleEntry *r=NULL; char *lab;
  1774. zzmatch(LABEL);
  1775. lab = mystrdup(LATEXT(1));
  1776. zzCONSUME;
  1777. UsedNewStyleLabel = 1;
  1778. if ( UsedOldStyleAttrib ) err("cannot mix with new-style labels with old-style $i");
  1779. t = (TermEntry *) hash_get(Tname, lab);
  1780. if ( t==NULL ) t = (TermEntry *) hash_get(Texpr, lab);
  1781. if ( t==NULL ) r = (RuleEntry *) hash_get(Rname, lab);
  1782. if ( t!=NULL ) {
  1783. err(eMsg1("label definition clashes with token/tokclass definition: '%s'", lab));
  1784. _retv = NULL;
  1785. }
  1786. else if ( r!=NULL ) {
  1787. err(eMsg1("label definition clashes with rule definition: '%s'", lab));
  1788. _retv = NULL;
  1789. }
  1790. else {
  1791. /* we don't clash with anybody else */
  1792. l = (LabelEntry *) hash_get(Elabel, lab);
  1793. if ( l==NULL ) { /* ok to add new element label */
  1794. l = (LabelEntry *)hash_add(Elabel,
  1795. lab,
  1796. (Entry *)newLabelEntry(lab));
  1797. /* add to list of element labels for this rule */
  1798. list_add(&CurElementLabels, (void *)lab);
  1799. /* MR7 */ leAdd(l); /* list of labels waiting for exception group definitions */
  1800. _retv = l;
  1801. }
  1802. else {
  1803. err(eMsg1("label definitions must be unique per rule: '%s'", lab));
  1804. _retv = NULL;
  1805. }
  1806. }
  1807. zzmatch(106); zzCONSUME;
  1808. zzEXIT(zztasp1);
  1809. return _retv;
  1810. fail:
  1811. zzEXIT(zztasp1);
  1812. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  1813. zzresynch(setwd6, 0x4);
  1814. return _retv;
  1815. }
  1816. }
  1817. Node *
  1818. #ifdef __USE_PROTOS
  1819. element(int old_not,int first_on_line,int use_def_MT_handler)
  1820. #else
  1821. element(old_not,first_on_line,use_def_MT_handler)
  1822. int old_not;
  1823. int first_on_line;
  1824. int use_def_MT_handler ;
  1825. #endif
  1826. {
  1827. Node * _retv;
  1828. zzRULE;
  1829. zzBLOCK(zztasp1);
  1830. PCCTS_PURIFY(_retv,sizeof(Node * ))
  1831. zzMake0;
  1832. {
  1833. Attrib blk;
  1834. Predicate *pred = NULL;
  1835. int local_use_def_MT_handler=0;
  1836. ActionNode *act;
  1837. RuleRefNode *rr;
  1838. set toksrefd, rulesrefd;
  1839. TermEntry *term;
  1840. TokNode *p=NULL; RuleRefNode *q; int approx=0;
  1841. LabelEntry *label=NULL;
  1842. int predMsgDone=0;
  1843. int semDepth=0;
  1844. int ampersandStyle;
  1845. int height; /* MR11 */
  1846. int equal_height; /* MR11 */
  1847. char* pFirstSetSymbol = NULL; /* MR21 */
  1848. _retv = NULL;
  1849. if ( (setwd6[LA(1)]&0x8) ) {
  1850. {
  1851. zzBLOCK(zztasp2);
  1852. zzMake0;
  1853. {
  1854. if ( (LA(1)==LABEL) ) {
  1855. label = element_label();
  1856. }
  1857. else {
  1858. if ( (setwd6[LA(1)]&0x10) ) {
  1859. }
  1860. else {zzFAIL(1,zzerr28,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1861. }
  1862. zzEXIT(zztasp2);
  1863. }
  1864. }
  1865. {
  1866. zzBLOCK(zztasp2);
  1867. zzMake0;
  1868. {
  1869. if ( (LA(1)==TokenTerm) ) {
  1870. zzmatch(TokenTerm);
  1871. term = (TermEntry *) hash_get(Tname, LATEXT(1));
  1872. if ( term==NULL && UserDefdTokens ) {
  1873. err("implicit token definition not allowed with #tokdefs");
  1874. zzaRet.left = zzaRet.right = NULL;
  1875. }
  1876. else {
  1877. zzaRet = buildToken(LATEXT(1));
  1878. p=((TokNode *)((Junction *)zzaRet.left)->p1);
  1879. term = (TermEntry *) hash_get(Tname, LATEXT(1));
  1880. require( term!= NULL, "hash table mechanism is broken");
  1881. p->tclass = term->tclass;
  1882. p->complement = old_not;
  1883. if ( label!=NULL ) {
  1884. p->el_label = label->str;
  1885. label->elem = (Node *)p;
  1886. }
  1887. }
  1888. zzCONSUME;
  1889. {
  1890. zzBLOCK(zztasp3);
  1891. zzMake0;
  1892. {
  1893. if ( (LA(1)==119) ) {
  1894. zzmatch(119); zzCONSUME;
  1895. {
  1896. zzBLOCK(zztasp4);
  1897. zzMake0;
  1898. {
  1899. if ( (LA(1)==QuotedTerm) ) {
  1900. zzmatch(QuotedTerm);
  1901. if ( p!=NULL ) setUpperRange(p, LATEXT(1));
  1902. zzCONSUME;
  1903. }
  1904. else {
  1905. if ( (LA(1)==TokenTerm) ) {
  1906. zzmatch(TokenTerm);
  1907. if ( p!=NULL ) setUpperRange(p, LATEXT(1));
  1908. zzCONSUME;
  1909. }
  1910. else {zzFAIL(1,zzerr29,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1911. }
  1912. zzEXIT(zztasp4);
  1913. }
  1914. }
  1915. }
  1916. else {
  1917. if ( (setwd6[LA(1)]&0x20) ) {
  1918. }
  1919. else {zzFAIL(1,zzerr30,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1920. }
  1921. zzEXIT(zztasp3);
  1922. }
  1923. }
  1924. if ( p!=NULL && (p->upper_range!=0 || p->tclass || old_not) )
  1925. list_add(&MetaTokenNodes, (void *)p);
  1926. {
  1927. zzBLOCK(zztasp3);
  1928. zzMake0;
  1929. {
  1930. if ( (LA(1)==125) ) {
  1931. zzmatch(125);
  1932. if ( p!=NULL ) p->astnode=ASTroot;
  1933. zzCONSUME;
  1934. }
  1935. else {
  1936. if ( (setwd6[LA(1)]&0x40) ) {
  1937. if ( p!=NULL ) p->astnode=ASTchild;
  1938. }
  1939. else {
  1940. if ( (LA(1)==103) ) {
  1941. zzmatch(103);
  1942. if ( p!=NULL ) p->astnode=ASTexclude;
  1943. zzCONSUME;
  1944. }
  1945. else {zzFAIL(1,zzerr31,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1946. }
  1947. }
  1948. zzEXIT(zztasp3);
  1949. }
  1950. }
  1951. {
  1952. zzBLOCK(zztasp3);
  1953. zzMake0;
  1954. {
  1955. if ( (LA(1)==88) ) {
  1956. zzmatch(88);
  1957. local_use_def_MT_handler = 1;
  1958. zzCONSUME;
  1959. }
  1960. else {
  1961. if ( (setwd6[LA(1)]&0x80) ) {
  1962. }
  1963. else {zzFAIL(1,zzerr32,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  1964. }
  1965. zzEXIT(zztasp3);
  1966. }
  1967. }
  1968. if ( p!=NULL && first_on_line ) {
  1969. CurAltStart = (Junction *)zzaRet.left;
  1970. altAdd(CurAltStart); /* MR7 */
  1971. p->altstart = CurAltStart;
  1972. }
  1973. if ( p!=NULL )
  1974. p->use_def_MT_handler = use_def_MT_handler || local_use_def_MT_handler;
  1975. _retv = (Node *)p;
  1976. }
  1977. else {
  1978. if ( (LA(1)==QuotedTerm) ) {
  1979. zzmatch(QuotedTerm);
  1980. term = (TermEntry *) hash_get(Texpr, LATEXT(1));
  1981. if ( term==NULL && UserDefdTokens ) {
  1982. err("implicit token definition not allowed with #tokdefs");
  1983. zzaRet.left = zzaRet.right = NULL;
  1984. }
  1985. else {
  1986. zzaRet = buildToken(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1);
  1987. p->complement = old_not;
  1988. if ( label!=NULL ) {
  1989. p->el_label = label->str;
  1990. label->elem = (Node *)p;
  1991. }
  1992. }
  1993. zzCONSUME;
  1994. {
  1995. zzBLOCK(zztasp3);
  1996. zzMake0;
  1997. {
  1998. if ( (LA(1)==119) ) {
  1999. zzmatch(119); zzCONSUME;
  2000. {
  2001. zzBLOCK(zztasp4);
  2002. zzMake0;
  2003. {
  2004. if ( (LA(1)==QuotedTerm) ) {
  2005. zzmatch(QuotedTerm);
  2006. if ( p!=NULL ) setUpperRange(p, LATEXT(1));
  2007. zzCONSUME;
  2008. }
  2009. else {
  2010. if ( (LA(1)==TokenTerm) ) {
  2011. zzmatch(TokenTerm);
  2012. if ( p!=NULL ) setUpperRange(p, LATEXT(1));
  2013. zzCONSUME;
  2014. }
  2015. else {zzFAIL(1,zzerr33,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2016. }
  2017. zzEXIT(zztasp4);
  2018. }
  2019. }
  2020. }
  2021. else {
  2022. if ( (setwd7[LA(1)]&0x1) ) {
  2023. }
  2024. else {zzFAIL(1,zzerr34,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2025. }
  2026. zzEXIT(zztasp3);
  2027. }
  2028. }
  2029. {
  2030. zzBLOCK(zztasp3);
  2031. zzMake0;
  2032. {
  2033. if ( (LA(1)==125) ) {
  2034. zzmatch(125);
  2035. if ( p!=NULL ) p->astnode=ASTroot;
  2036. zzCONSUME;
  2037. }
  2038. else {
  2039. if ( (setwd7[LA(1)]&0x2) ) {
  2040. if ( p!=NULL ) p->astnode=ASTchild;
  2041. }
  2042. else {
  2043. if ( (LA(1)==103) ) {
  2044. zzmatch(103);
  2045. if ( p!=NULL ) p->astnode=ASTexclude;
  2046. zzCONSUME;
  2047. }
  2048. else {zzFAIL(1,zzerr35,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2049. }
  2050. }
  2051. zzEXIT(zztasp3);
  2052. }
  2053. }
  2054. {
  2055. zzBLOCK(zztasp3);
  2056. zzMake0;
  2057. {
  2058. if ( (LA(1)==88) ) {
  2059. zzmatch(88);
  2060. local_use_def_MT_handler = 1;
  2061. zzCONSUME;
  2062. }
  2063. else {
  2064. if ( (setwd7[LA(1)]&0x4) ) {
  2065. }
  2066. else {zzFAIL(1,zzerr36,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2067. }
  2068. zzEXIT(zztasp3);
  2069. }
  2070. }
  2071. if ( p!=NULL && (p->upper_range!=0 || p->tclass || old_not) )
  2072. list_add(&MetaTokenNodes, (void *)p);
  2073. if ( first_on_line ) {
  2074. CurAltStart = (Junction *)zzaRet.left;
  2075. altAdd(CurAltStart); /* MR7 */
  2076. p->altstart = CurAltStart;
  2077. }
  2078. if ( p!=NULL )
  2079. p->use_def_MT_handler = use_def_MT_handler || local_use_def_MT_handler;
  2080. _retv = (Node *)p;
  2081. }
  2082. else {
  2083. if ( (LA(1)==WildCard) ) {
  2084. if ( old_not ) warn("~ WILDCARD is an undefined operation (implies 'nothing')");
  2085. zzmatch(WildCard);
  2086. zzaRet = buildWildCard(LATEXT(1)); p=((TokNode *)((Junction *)zzaRet.left)->p1);
  2087. zzCONSUME;
  2088. {
  2089. zzBLOCK(zztasp3);
  2090. zzMake0;
  2091. {
  2092. if ( (LA(1)==125) ) {
  2093. zzmatch(125);
  2094. p->astnode=ASTroot;
  2095. zzCONSUME;
  2096. }
  2097. else {
  2098. if ( (setwd7[LA(1)]&0x8) ) {
  2099. p->astnode=ASTchild;
  2100. }
  2101. else {
  2102. if ( (LA(1)==103) ) {
  2103. zzmatch(103);
  2104. p->astnode=ASTexclude;
  2105. zzCONSUME;
  2106. }
  2107. else {zzFAIL(1,zzerr37,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2108. }
  2109. }
  2110. zzEXIT(zztasp3);
  2111. }
  2112. }
  2113. list_add(&MetaTokenNodes, (void *)p);
  2114. if ( first_on_line ) {
  2115. CurAltStart = (Junction *)zzaRet.left;
  2116. altAdd(CurAltStart); /* MR7 */
  2117. p->altstart = CurAltStart;
  2118. if ( label!=NULL ) {
  2119. p->el_label = label->str;
  2120. label->elem = (Node *)p;
  2121. }
  2122. }
  2123. _retv = (Node *)p;
  2124. }
  2125. else {
  2126. if ( (LA(1)==NonTerminal) ) {
  2127. if ( old_not ) warn("~ NONTERMINAL is an undefined operation");
  2128. zzmatch(NonTerminal);
  2129. zzaRet = buildRuleRef(LATEXT(1));
  2130. zzCONSUME;
  2131. {
  2132. zzBLOCK(zztasp3);
  2133. zzMake0;
  2134. {
  2135. if ( (LA(1)==103) ) {
  2136. zzmatch(103);
  2137. q = (RuleRefNode *) ((Junction *)zzaRet.left)->p1;
  2138. q->astnode=ASTexclude;
  2139. zzCONSUME;
  2140. }
  2141. else {
  2142. if ( (setwd7[LA(1)]&0x10) ) {
  2143. }
  2144. else {zzFAIL(1,zzerr38,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2145. }
  2146. zzEXIT(zztasp3);
  2147. }
  2148. }
  2149. {
  2150. zzBLOCK(zztasp3);
  2151. zzMake0;
  2152. {
  2153. if ( (setwd7[LA(1)]&0x20) ) {
  2154. {
  2155. zzBLOCK(zztasp4);
  2156. zzMake0;
  2157. {
  2158. if ( (LA(1)==104) ) {
  2159. zzmatch(104); zzCONSUME;
  2160. }
  2161. else {
  2162. if ( (LA(1)==PassAction) ) {
  2163. }
  2164. else {zzFAIL(1,zzerr39,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2165. }
  2166. zzEXIT(zztasp4);
  2167. }
  2168. }
  2169. zzmatch(PassAction);
  2170. addParm(((Junction *)zzaRet.left)->p1, LATEXT(1));
  2171. zzCONSUME;
  2172. }
  2173. else {
  2174. if ( (setwd7[LA(1)]&0x40) ) {
  2175. }
  2176. else {zzFAIL(1,zzerr40,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2177. }
  2178. zzEXIT(zztasp3);
  2179. }
  2180. }
  2181. rr=(RuleRefNode *) ((Junction *)zzaRet.left)->p1;
  2182. {
  2183. zzBLOCK(zztasp3);
  2184. zzMake0;
  2185. {
  2186. char *a;
  2187. if ( (LA(1)==105) ) {
  2188. zzmatch(105); zzCONSUME;
  2189. zzmatch(PassAction);
  2190. a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  2191. require(a!=NULL, "rule element: cannot allocate assignment");
  2192. strcpy(a, LATEXT(1));
  2193. rr->assign = a;
  2194. zzCONSUME;
  2195. }
  2196. else {
  2197. if ( (setwd7[LA(1)]&0x80) ) {
  2198. }
  2199. else {zzFAIL(1,zzerr41,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2200. }
  2201. zzEXIT(zztasp3);
  2202. }
  2203. }
  2204. if ( label!=NULL ) {
  2205. rr->el_label = label->str;
  2206. label->elem = (Node *)rr;
  2207. }
  2208. if ( first_on_line ) {
  2209. CurAltStart = (Junction *)zzaRet.left;
  2210. altAdd(CurAltStart); /* MR7 */
  2211. ((RuleRefNode *)((Junction *)zzaRet.left)->p1)->altstart = CurAltStart;
  2212. }
  2213. _retv = (Node *)rr;
  2214. }
  2215. else {zzFAIL(1,zzerr42,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2216. }
  2217. }
  2218. }
  2219. zzEXIT(zztasp2);
  2220. }
  2221. }
  2222. }
  2223. else {
  2224. if ( (LA(1)==Action) ) {
  2225. if ( old_not ) warn("~ ACTION is an undefined operation");
  2226. zzmatch(Action);
  2227. zzaArg(zztasp1,0) = buildAction(LATEXT(1),action_file,action_line, 0);
  2228. zzCONSUME;
  2229. if ( first_on_line ) { /* MR7 */
  2230. CurAltStart = (Junction *)zzaArg(zztasp1,0 ).left; /* MR7 */
  2231. altAdd(CurAltStart); /* MR7 */
  2232. };
  2233. _retv = (Node *) ((Junction *)zzaArg(zztasp1,0 ).left)->p1;
  2234. }
  2235. else {
  2236. if ( (LA(1)==Pred) ) {
  2237. if ( old_not ) warn("~ SEMANTIC-PREDICATE is an undefined operation");
  2238. zzmatch(Pred);
  2239. zzaArg(zztasp1,0) = buildAction(LATEXT(1),action_file,action_line, 1);
  2240. zzCONSUME;
  2241. act = (ActionNode *) ((Junction *)zzaArg(zztasp1,0 ).left)->p1;
  2242. if (numericActionLabel) { /* MR10 */
  2243. list_add(&NumericPredLabels,act); /* MR10 */
  2244. numericActionLabel=0; /* MR10 */
  2245. }; /* MR10 */
  2246. {
  2247. zzBLOCK(zztasp2);
  2248. zzMake0;
  2249. {
  2250. char *a;
  2251. if ( (LA(1)==PassAction) ) {
  2252. zzmatch(PassAction);
  2253. a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  2254. require(a!=NULL, "rule element: cannot allocate predicate fail action");
  2255. strcpy(a, LATEXT(1));
  2256. act->pred_fail = a;
  2257. zzCONSUME;
  2258. }
  2259. else {
  2260. if ( (setwd8[LA(1)]&0x1) ) {
  2261. }
  2262. else {zzFAIL(1,zzerr43,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2263. }
  2264. zzEXIT(zztasp2);
  2265. }
  2266. }
  2267. if ( first_on_line ) { /* MR7 */
  2268. CurAltStart = (Junction *)zzaArg(zztasp1,0 ).left; /* MR7 */
  2269. altAdd(CurAltStart); /* MR7 */
  2270. };
  2271. _retv = (Node *)act;
  2272. }
  2273. else {
  2274. if ( (setwd8[LA(1)]&0x2) ) {
  2275. if ( old_not ) warn("~ BLOCK is an undefined operation");
  2276. BlkLevel++;
  2277. if (BlkLevel >= MAX_BLK_LEVEL) fatal("Blocks nested too deeply");
  2278. /* MR23 */ CurBlockID_array[BlkLevel] = CurBlockID;
  2279. /* MR23 */ CurAltNum_array[BlkLevel] = CurAltNum;
  2280. {
  2281. zzBLOCK(zztasp2);
  2282. zzMake0;
  2283. {
  2284. if ( (LA(1)==Pragma) ) {
  2285. zzmatch(Pragma); zzCONSUME;
  2286. {
  2287. zzBLOCK(zztasp3);
  2288. zzMake0;
  2289. {
  2290. if ( (LA(1)==126) ) {
  2291. zzmatch(126);
  2292. approx=LL_k;
  2293. zzCONSUME;
  2294. }
  2295. else {
  2296. if ( (LA(1)==127) ) {
  2297. zzmatch(127);
  2298. approx = 1;
  2299. zzCONSUME;
  2300. }
  2301. else {
  2302. if ( (LA(1)==128) ) {
  2303. zzmatch(128);
  2304. approx = 2;
  2305. zzCONSUME;
  2306. }
  2307. else {zzFAIL(1,zzerr44,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2308. }
  2309. }
  2310. zzEXIT(zztasp3);
  2311. }
  2312. }
  2313. }
  2314. else {
  2315. if ( (setwd8[LA(1)]&0x4) ) {
  2316. }
  2317. else {zzFAIL(1,zzerr45,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2318. }
  2319. zzEXIT(zztasp2);
  2320. }
  2321. }
  2322. {
  2323. zzBLOCK(zztasp2);
  2324. zzMake0;
  2325. {
  2326. if ( (LA(1)==FirstSetSymbol) ) {
  2327. zzmatch(FirstSetSymbol); zzCONSUME;
  2328. zzmatch(114); zzCONSUME;
  2329. {
  2330. zzBLOCK(zztasp3);
  2331. zzMake0;
  2332. {
  2333. if ( (LA(1)==NonTerminal) ) {
  2334. zzmatch(NonTerminal);
  2335. /* MR21 */ pFirstSetSymbol = (char *) calloc(strlen(LATEXT(1))+1,
  2336. /* MR21 */ sizeof(char));
  2337. /* MR21 */ require(pFirstSetSymbol!=NULL,
  2338. /* MR21 */ "cannot allocate first set name");
  2339. /* MR21 */ strcpy(pFirstSetSymbol, LATEXT(1));
  2340. /* MR21 */
  2341. zzCONSUME;
  2342. }
  2343. else {
  2344. if ( (LA(1)==TokenTerm) ) {
  2345. zzmatch(TokenTerm);
  2346. /* MR21 */ pFirstSetSymbol = (char *) calloc(strlen(LATEXT(1))+1,
  2347. /* MR21 */ sizeof(char));
  2348. /* MR21 */ require(pFirstSetSymbol!=NULL,
  2349. /* MR21 */ "cannot allocate first set name");
  2350. /* MR21 */ strcpy(pFirstSetSymbol, LATEXT(1));
  2351. /* MR21 */
  2352. zzCONSUME;
  2353. }
  2354. else {zzFAIL(1,zzerr46,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2355. }
  2356. zzEXIT(zztasp3);
  2357. }
  2358. }
  2359. zzmatch(115); zzCONSUME;
  2360. }
  2361. else {
  2362. if ( (setwd8[LA(1)]&0x8) ) {
  2363. }
  2364. else {zzFAIL(1,zzerr47,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2365. }
  2366. zzEXIT(zztasp2);
  2367. }
  2368. }
  2369. {
  2370. zzBLOCK(zztasp2);
  2371. zzMake0;
  2372. {
  2373. if ( (LA(1)==114) ) {
  2374. zzmatch(114); zzCONSUME;
  2375. block( &toksrefd,&rulesrefd );
  2376. zzmatch(115);
  2377. blk = zzaRet = zzaArg(zztasp2,2);
  2378. /* MR23 */ CurBlockID_array[BlkLevel] = (-1);
  2379. /* MR23 */ CurAltNum_array[BlkLevel] = (-1);
  2380. --BlkLevel;
  2381. zzCONSUME;
  2382. {
  2383. zzBLOCK(zztasp3);
  2384. zzMake0;
  2385. {
  2386. if ( (LA(1)==129) ) {
  2387. zzmatch(129);
  2388. zzaRet = makeLoop(zzaRet,approx,pFirstSetSymbol);
  2389. zzCONSUME;
  2390. }
  2391. else {
  2392. if ( (LA(1)==130) ) {
  2393. zzmatch(130);
  2394. zzaRet = makePlus(zzaRet,approx,pFirstSetSymbol);
  2395. zzCONSUME;
  2396. }
  2397. else {
  2398. if ( (LA(1)==131) ) {
  2399. zzmatch(131); zzCONSUME;
  2400. {
  2401. zzBLOCK(zztasp4);
  2402. zzMake0;
  2403. {
  2404. if ( (setwd8[LA(1)]&0x10) ) {
  2405. {
  2406. zzBLOCK(zztasp5);
  2407. zzMake0;
  2408. {
  2409. if ( (LA(1)==132) ) {
  2410. zzmatch(132);
  2411. ampersandStyle=0;
  2412. zzCONSUME;
  2413. }
  2414. else {
  2415. if ( (LA(1)==113) ) {
  2416. zzmatch(113);
  2417. ampersandStyle=1;
  2418. zzCONSUME;
  2419. }
  2420. else {zzFAIL(1,zzerr48,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2421. }
  2422. zzEXIT(zztasp5);
  2423. }
  2424. }
  2425. zzmatch(Pred);
  2426. zzaRet = buildAction(LATEXT(1),action_file,action_line,1);
  2427. zzCONSUME;
  2428. act = (ActionNode *) ((Junction *)zzaRet.left)->p1;
  2429. semDepth=predicateLookaheadDepth(act);
  2430. if (numericActionLabel) { /* MR10 */
  2431. list_add(&NumericPredLabels,act); /* MR10 */
  2432. numericActionLabel=0; /* MR10 */
  2433. }; /* MR10 */
  2434. {
  2435. zzBLOCK(zztasp5);
  2436. zzMake0;
  2437. {
  2438. char *a;
  2439. if ( (LA(1)==PassAction) ) {
  2440. zzmatch(PassAction);
  2441. a = (char *)calloc(strlen(LATEXT(1))+1, sizeof(char));
  2442. require(a!=NULL, "rule element: cannot allocate predicate fail action");
  2443. strcpy(a, LATEXT(1));
  2444. act->pred_fail = a;
  2445. zzCONSUME;
  2446. }
  2447. else {
  2448. if ( (setwd8[LA(1)]&0x20) ) {
  2449. }
  2450. else {zzFAIL(1,zzerr49,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2451. }
  2452. zzEXIT(zztasp5);
  2453. }
  2454. }
  2455. if ( first_on_line) { /* MR7 */
  2456. CurAltStart=(Junction *)zzaRet.left; /* MR7 */
  2457. altAdd(CurAltStart); /* MR7 */
  2458. };
  2459. _retv = (Node *)act;
  2460. pred = computePredFromContextGuard(blk,&predMsgDone); /* MR10 */
  2461. if ( pred==NULL) { /* MR10 */
  2462. if ( !predMsgDone) err("invalid or missing context guard"); /* MR10 */
  2463. predMsgDone=1; /* MR10 */
  2464. } else { /* MR10 */
  2465. act->guardNodes=(Junction *)blk.left; /* MR11 */
  2466. pred->expr = act->action;
  2467. pred->source = act;
  2468. /* MR10 */ pred->ampersandStyle = ampersandStyle; /* 0 means (g)? => ... 1 means (g)? && ... */
  2469. /* MR13 */ if (pred->tcontext != NULL) {
  2470. /* MR13 */ height=MR_max_height_of_tree(pred->tcontext);
  2471. /* MR13 */ equal_height=MR_all_leaves_same_height(pred->tcontext,height);
  2472. /* MR13 */ if (! equal_height) {
  2473. /* MR13 */ errFL("in guarded predicates all tokens in the guard must be at the same height",
  2474. /* MR13 */ FileStr[act->file],act->line);
  2475. /* MR13 */ };
  2476. /* MR13 */ }
  2477. /* MR10 */ if (ampersandStyle) {
  2478. /* MR10 */ act->ampersandPred = pred;
  2479. /* MR11 */ if (! HoistPredicateContext) {
  2480. /* MR11 */ errFL("without \"-prc on\" (guard)? && <<pred>>? ... doesn't make sense",
  2481. /* MR11 */ FileStr[act->file],act->line);
  2482. /* MR11 */ };
  2483. /* MR10 */ } else {
  2484. /* MR10 */ act->guardpred = pred;
  2485. /* MR10 */ };
  2486. /* MR10 */ if (pred->k != semDepth) {
  2487. /* MR10 */ warn(eMsgd2("length of guard (%d) does not match the length of semantic predicate (%d)",
  2488. /* MR10 */ pred->k,semDepth));
  2489. /* MR10 */ };
  2490. }
  2491. }
  2492. else {
  2493. if ( (setwd8[LA(1)]&0x40) ) {
  2494. zzaRet = makeBlk(zzaRet,approx,pFirstSetSymbol);
  2495. FoundGuessBlk = 1;
  2496. ((Junction *) ((Junction *)zzaRet.left)->p1)->guess=1;
  2497. if ( ! first_on_line ) {
  2498. err("(...)? predicate must be first element of production");
  2499. }
  2500. }
  2501. else {zzFAIL(1,zzerr50,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2502. }
  2503. zzEXIT(zztasp4);
  2504. }
  2505. }
  2506. }
  2507. else {
  2508. if ( (setwd8[LA(1)]&0x80) ) {
  2509. zzaRet = makeBlk(zzaRet,approx,pFirstSetSymbol);
  2510. }
  2511. else {zzFAIL(1,zzerr51,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2512. }
  2513. }
  2514. }
  2515. zzEXIT(zztasp3);
  2516. }
  2517. }
  2518. if ( pred==NULL && !predMsgDone) { /* MR10 */
  2519. ((Junction *)((Junction *)zzaRet.left)->p1)->blockid = CurBlockID;
  2520. ((Junction *)((Junction *)zzaRet.left)->p1)->tokrefs = toksrefd;
  2521. ((Junction *)((Junction *)zzaRet.left)->p1)->rulerefs = rulesrefd;
  2522. if ( first_on_line ) { /* MR7 */
  2523. CurAltStart = (Junction *)((Junction *)((Junction *)zzaRet.left)->p1); /* MR7 */
  2524. altAdd(CurAltStart); /* MR7 */
  2525. }; /* MR7 */
  2526. _retv = (Node *) ((Junction *)zzaRet.left)->p1;
  2527. }
  2528. }
  2529. else {
  2530. if ( (LA(1)==102) ) {
  2531. zzmatch(102); zzCONSUME;
  2532. block( &toksrefd,&rulesrefd );
  2533. zzaRet = makeOpt(zzaArg(zztasp2,2),approx,pFirstSetSymbol);
  2534. /* MR23 */ CurBlockID_array[BlkLevel] = (-1);
  2535. /* MR23 */ CurAltNum_array[BlkLevel] = (-1);
  2536. --BlkLevel;
  2537. zzmatch(98);
  2538. ((Junction *)((Junction *)zzaRet.left)->p1)->blockid = CurBlockID;
  2539. ((Junction *)((Junction *)zzaRet.left)->p1)->tokrefs = toksrefd;
  2540. ((Junction *)((Junction *)zzaRet.left)->p1)->rulerefs = rulesrefd;
  2541. zzCONSUME;
  2542. if ( first_on_line ) { /* MR7 */
  2543. CurAltStart = (Junction *) ((Junction *)((Junction *)zzaRet.left)->p1); /* MR7 */
  2544. altAdd(CurAltStart); /* MR7 */
  2545. };
  2546. _retv = (Node *) ((Junction *)zzaRet.left)->p1;
  2547. }
  2548. else {zzFAIL(1,zzerr52,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2549. }
  2550. zzEXIT(zztasp2);
  2551. }
  2552. }
  2553. }
  2554. else {
  2555. if ( (LA(1)==129) ) {
  2556. zzmatch(129);
  2557. warn("don't you want a ')' with that '*'?"); CannotContinue=TRUE;
  2558. zzCONSUME;
  2559. }
  2560. else {
  2561. if ( (LA(1)==130) ) {
  2562. zzmatch(130);
  2563. warn("don't you want a ')' with that '+'?"); CannotContinue=TRUE;
  2564. zzCONSUME;
  2565. }
  2566. else {
  2567. if ( (LA(1)==105) ) {
  2568. zzmatch(105);
  2569. warn("'>' can only appear after a nonterminal"); CannotContinue=TRUE;
  2570. zzCONSUME;
  2571. }
  2572. else {
  2573. if ( (LA(1)==PassAction) ) {
  2574. zzmatch(PassAction);
  2575. warn("[...] out of context 'rule > [...]'");
  2576. CannotContinue=TRUE;
  2577. zzCONSUME;
  2578. }
  2579. else {zzFAIL(1,zzerr53,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2580. }
  2581. }
  2582. }
  2583. }
  2584. }
  2585. }
  2586. }
  2587. zzEXIT(zztasp1);
  2588. return _retv;
  2589. fail:
  2590. zzEXIT(zztasp1);
  2591. CannotContinue=TRUE;
  2592. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  2593. zzresynch(setwd9, 0x1);
  2594. return _retv;
  2595. }
  2596. }
  2597. void
  2598. #ifdef __USE_PROTOS
  2599. default_exception_handler(void)
  2600. #else
  2601. default_exception_handler()
  2602. #endif
  2603. {
  2604. zzRULE;
  2605. zzBLOCK(zztasp1);
  2606. zzMake0;
  2607. {
  2608. DefaultExGroup = exception_group();
  2609. zzEXIT(zztasp1);
  2610. return;
  2611. fail:
  2612. zzEXIT(zztasp1);
  2613. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  2614. zzresynch(setwd9, 0x2);
  2615. }
  2616. }
  2617. ExceptionGroup *
  2618. #ifdef __USE_PROTOS
  2619. exception_group(void)
  2620. #else
  2621. exception_group()
  2622. #endif
  2623. {
  2624. ExceptionGroup * _retv;
  2625. zzRULE;
  2626. zzBLOCK(zztasp1);
  2627. PCCTS_PURIFY(_retv,sizeof(ExceptionGroup * ))
  2628. zzMake0;
  2629. {
  2630. ExceptionHandler *h; LabelEntry *label=NULL; /* MR6 */
  2631. FoundException = 1; FoundExceptionGroup = 1;
  2632. zzmatch(133);
  2633. _retv = (ExceptionGroup *)calloc(1, sizeof(ExceptionGroup));
  2634. zzCONSUME;
  2635. {
  2636. zzBLOCK(zztasp2);
  2637. zzMake0;
  2638. {
  2639. char *p;
  2640. if ( (LA(1)==PassAction) ) {
  2641. zzmatch(PassAction);
  2642. p = LATEXT(1)+1;
  2643. p[strlen(p)-1] = '\0'; /* kill trailing space */
  2644. label = (LabelEntry *) hash_get(Elabel, LATEXT(1)+1);
  2645. if ( label==NULL )
  2646. {
  2647. err(eMsg1("unknown label in exception handler: '%s'", LATEXT(1)+1));
  2648. }
  2649. zzCONSUME;
  2650. }
  2651. else {
  2652. if ( (setwd9[LA(1)]&0x4) ) {
  2653. }
  2654. else {zzFAIL(1,zzerr54,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2655. }
  2656. zzEXIT(zztasp2);
  2657. }
  2658. }
  2659. {
  2660. zzBLOCK(zztasp2);
  2661. zzMake0;
  2662. {
  2663. while ( (LA(1)==135) ) {
  2664. h = exception_handler();
  2665. list_add(&(_retv->handlers), (void *)h);
  2666. zzLOOP(zztasp2);
  2667. }
  2668. zzEXIT(zztasp2);
  2669. }
  2670. }
  2671. {
  2672. zzBLOCK(zztasp2);
  2673. zzMake0;
  2674. {
  2675. if ( (LA(1)==134) ) {
  2676. zzmatch(134); zzCONSUME;
  2677. zzmatch(106); zzCONSUME;
  2678. zzmatch(Action);
  2679. {
  2680. ExceptionHandler *eh = (ExceptionHandler *)
  2681. calloc(1, sizeof(ExceptionHandler));
  2682. char *a = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  2683. require(eh!=NULL, "exception: cannot allocate handler");
  2684. require(a!=NULL, "exception: cannot allocate action");
  2685. strcpy(a, LATEXT(1));
  2686. eh->action = a;
  2687. eh->signalname = (char *) calloc(strlen("default")+1, sizeof(char));
  2688. require(eh->signalname!=NULL, "exception: cannot allocate sig name");
  2689. strcpy(eh->signalname, "default");
  2690. list_add(&(_retv->handlers), (void *)eh);
  2691. }
  2692. zzCONSUME;
  2693. }
  2694. else {
  2695. if ( (setwd9[LA(1)]&0x8) ) {
  2696. }
  2697. else {zzFAIL(1,zzerr55,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2698. }
  2699. zzEXIT(zztasp2);
  2700. }
  2701. }
  2702. if ( label!=NULL ) {
  2703. /* Record ex group in sym tab for this label */
  2704. if ( label->ex_group!=NULL ) {
  2705. err(eMsg1("duplicate exception handler for label '%s'",label->str));
  2706. } else {
  2707. label->ex_group = _retv;
  2708. /* Label the exception group itself */
  2709. _retv->label = label->str;
  2710. /* Make the labelled element pt to the exception also */
  2711. /* MR6 */ if (label->elem == NULL) {
  2712. /* MR6 */ err(eMsg1("reference in exception handler to undefined label '%s'",label->str));
  2713. /* MR6 */ } else {
  2714. switch ( label->elem->ntype ) {
  2715. case nRuleRef :
  2716. {
  2717. RuleRefNode *r = (RuleRefNode *)label->elem;
  2718. r->ex_group = _retv;
  2719. break;
  2720. }
  2721. case nToken :
  2722. {
  2723. TokNode *t = (TokNode *)label->elem;
  2724. t->ex_group = _retv;
  2725. break;
  2726. }
  2727. } /* end switch */
  2728. /* MR6 */ }; /* end test on label->elem */
  2729. } /* end test on label->ex_group */
  2730. } /* end test on exception label */
  2731. /* MR7 */
  2732. /* MR7 */ if (BlkLevel == 1 && label == NULL) {
  2733. /* MR7 */ _retv->forRule=1;
  2734. /* MR7 */ } else if (label == NULL) {
  2735. /* MR7 */ _retv->altID = makeAltID(CurBlockID_array[BlkLevel], CurAltNum_array[BlkLevel]);
  2736. /* MR7 */ egAdd(_retv);
  2737. /* MR7 */ } else {
  2738. /* MR7 */ _retv->labelEntry=label;
  2739. /* MR7 */ };
  2740. /* MR7 */
  2741. /* MR7 */ /* You may want to remove this exc from the rule list */
  2742. /* MR7 */ /* and handle at the labeled element site. */
  2743. /* MR7 */
  2744. /* MR7 */ if (label != NULL) {
  2745. /* MR7 */ _retv = NULL;
  2746. /* MR7 */ };
  2747. zzEXIT(zztasp1);
  2748. return _retv;
  2749. fail:
  2750. zzEXIT(zztasp1);
  2751. CannotContinue=TRUE;
  2752. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  2753. zzresynch(setwd9, 0x10);
  2754. return _retv;
  2755. }
  2756. }
  2757. ExceptionHandler *
  2758. #ifdef __USE_PROTOS
  2759. exception_handler(void)
  2760. #else
  2761. exception_handler()
  2762. #endif
  2763. {
  2764. ExceptionHandler * _retv;
  2765. zzRULE;
  2766. zzBLOCK(zztasp1);
  2767. PCCTS_PURIFY(_retv,sizeof(ExceptionHandler * ))
  2768. zzMake0;
  2769. {
  2770. ;
  2771. zzmatch(135);
  2772. _retv = (ExceptionHandler *)calloc(1, sizeof(ExceptionHandler));
  2773. require(_retv!=NULL, "exception: cannot allocate handler");
  2774. zzCONSUME;
  2775. {
  2776. zzBLOCK(zztasp2);
  2777. zzMake0;
  2778. {
  2779. if ( (LA(1)==NonTerminal) ) {
  2780. zzmatch(NonTerminal);
  2781. _retv->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  2782. require(_retv->signalname!=NULL, "exception: cannot allocate sig name");
  2783. strcpy(_retv->signalname, LATEXT(1));
  2784. zzCONSUME;
  2785. }
  2786. else {
  2787. if ( (LA(1)==TokenTerm) ) {
  2788. zzmatch(TokenTerm);
  2789. _retv->signalname = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  2790. require(_retv->signalname!=NULL, "exception: cannot allocate sig name");
  2791. strcpy(_retv->signalname, LATEXT(1));
  2792. zzCONSUME;
  2793. }
  2794. else {zzFAIL(1,zzerr56,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2795. }
  2796. zzEXIT(zztasp2);
  2797. }
  2798. }
  2799. zzmatch(106); zzCONSUME;
  2800. {
  2801. zzBLOCK(zztasp2);
  2802. zzMake0;
  2803. {
  2804. _retv->action = NULL;
  2805. if ( (LA(1)==Action) ) {
  2806. zzmatch(Action);
  2807. _retv->action = (char *) calloc(strlen(LATEXT(1))+1, sizeof(char));
  2808. require(_retv->action!=NULL, "exception: cannot allocate action");
  2809. strcpy(_retv->action, LATEXT(1));
  2810. zzCONSUME;
  2811. }
  2812. else {
  2813. if ( (setwd9[LA(1)]&0x20) ) {
  2814. }
  2815. else {zzFAIL(1,zzerr57,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2816. }
  2817. zzEXIT(zztasp2);
  2818. }
  2819. }
  2820. zzEXIT(zztasp1);
  2821. return _retv;
  2822. fail:
  2823. zzEXIT(zztasp1);
  2824. CannotContinue=TRUE;
  2825. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  2826. zzresynch(setwd9, 0x40);
  2827. return _retv;
  2828. }
  2829. }
  2830. void
  2831. #ifdef __USE_PROTOS
  2832. enum_file(char * fname)
  2833. #else
  2834. enum_file(fname)
  2835. char *fname ;
  2836. #endif
  2837. {
  2838. zzRULE;
  2839. zzBLOCK(zztasp1);
  2840. zzMake0;
  2841. {
  2842. if ( (setwd9[LA(1)]&0x80) ) {
  2843. {
  2844. zzBLOCK(zztasp2);
  2845. zzMake0;
  2846. {
  2847. if ( (LA(1)==143) ) {
  2848. zzmatch(143); zzCONSUME;
  2849. zzmatch(ID); zzCONSUME;
  2850. {
  2851. zzBLOCK(zztasp3);
  2852. zzMake0;
  2853. {
  2854. if ( (LA(1)==149) ) {
  2855. zzmatch(149); zzCONSUME;
  2856. zzmatch(ID); zzCONSUME;
  2857. }
  2858. else {
  2859. if ( (setwd10[LA(1)]&0x1) ) {
  2860. }
  2861. else {zzFAIL(1,zzerr58,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2862. }
  2863. zzEXIT(zztasp3);
  2864. }
  2865. }
  2866. }
  2867. else {
  2868. if ( (setwd10[LA(1)]&0x2) ) {
  2869. }
  2870. else {zzFAIL(1,zzerr59,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2871. }
  2872. zzEXIT(zztasp2);
  2873. }
  2874. }
  2875. {
  2876. zzBLOCK(zztasp2);
  2877. zzMake0;
  2878. {
  2879. if ( (LA(1)==151) ) {
  2880. {
  2881. zzBLOCK(zztasp3);
  2882. int zzcnt=1;
  2883. zzMake0;
  2884. {
  2885. do {
  2886. enum_def( fname );
  2887. zzLOOP(zztasp3);
  2888. } while ( (LA(1)==151) );
  2889. zzEXIT(zztasp3);
  2890. }
  2891. }
  2892. }
  2893. else {
  2894. if ( (LA(1)==149) ) {
  2895. defines( fname );
  2896. }
  2897. else {zzFAIL(1,zzerr60,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2898. }
  2899. zzEXIT(zztasp2);
  2900. }
  2901. }
  2902. }
  2903. else {
  2904. if ( (LA(1)==Eof) ) {
  2905. }
  2906. else {zzFAIL(1,zzerr61,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  2907. }
  2908. zzEXIT(zztasp1);
  2909. return;
  2910. fail:
  2911. zzEXIT(zztasp1);
  2912. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  2913. zzresynch(setwd10, 0x4);
  2914. }
  2915. }
  2916. void
  2917. #ifdef __USE_PROTOS
  2918. defines(char * fname)
  2919. #else
  2920. defines(fname)
  2921. char *fname ;
  2922. #endif
  2923. {
  2924. zzRULE;
  2925. zzBLOCK(zztasp1);
  2926. zzMake0;
  2927. {
  2928. int v; int maxt=(-1); char *t;
  2929. {
  2930. zzBLOCK(zztasp2);
  2931. int zzcnt=1;
  2932. zzMake0;
  2933. {
  2934. do {
  2935. zzmatch(149); zzCONSUME;
  2936. zzmatch(ID);
  2937. t = mystrdup(LATEXT(1));
  2938. zzCONSUME;
  2939. zzmatch(INT);
  2940. v = atoi(LATEXT(1));
  2941. /* fprintf(stderr, "#token %s=%d\n", t, v);*/
  2942. /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
  2943. /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
  2944. /* MR2 Don't let #tokdefs be confused by */
  2945. /* MR2 DLGminToken and DLGmaxToken */
  2946. if ( ! isDLGmaxToken(t)) { /* MR2 */
  2947. TokenNum = v;
  2948. if ( v>maxt ) maxt=v;
  2949. if ( Tnum( t ) == 0 ) {
  2950. addForcedTname( t, v );
  2951. } else {
  2952. warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline);
  2953. };
  2954. };
  2955. zzCONSUME;
  2956. zzLOOP(zztasp2);
  2957. } while ( (LA(1)==149) );
  2958. zzEXIT(zztasp2);
  2959. }
  2960. }
  2961. TokenNum = maxt + 1;
  2962. zzEXIT(zztasp1);
  2963. return;
  2964. fail:
  2965. zzEXIT(zztasp1);
  2966. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  2967. zzresynch(setwd10, 0x8);
  2968. }
  2969. }
  2970. void
  2971. #ifdef __USE_PROTOS
  2972. enum_def(char * fname)
  2973. #else
  2974. enum_def(fname)
  2975. char *fname ;
  2976. #endif
  2977. {
  2978. zzRULE;
  2979. zzBLOCK(zztasp1);
  2980. zzMake0;
  2981. {
  2982. int v= 0; int maxt=(-1); char *t;
  2983. zzmatch(151); zzCONSUME;
  2984. zzmatch(ID); zzCONSUME;
  2985. zzmatch(152); zzCONSUME;
  2986. zzmatch(ID);
  2987. t = mystrdup(LATEXT(1));
  2988. zzCONSUME;
  2989. {
  2990. zzBLOCK(zztasp2);
  2991. zzMake0;
  2992. {
  2993. if ( (LA(1)==153) ) {
  2994. zzmatch(153); zzCONSUME;
  2995. zzmatch(INT);
  2996. v=atoi(LATEXT(1));
  2997. zzCONSUME;
  2998. }
  2999. else {
  3000. if ( (setwd10[LA(1)]&0x10) ) {
  3001. v++;
  3002. }
  3003. else {zzFAIL(1,zzerr62,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  3004. }
  3005. zzEXIT(zztasp2);
  3006. }
  3007. }
  3008. /* fprintf(stderr, "#token %s=%d\n", t, v);*/
  3009. TokenNum = v;
  3010. if ( v>maxt ) maxt=v; /* MR3 */
  3011. if ( Tnum( t ) == 0 ) addForcedTname( t, v );
  3012. else {
  3013. warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline);
  3014. }
  3015. {
  3016. zzBLOCK(zztasp2);
  3017. zzMake0;
  3018. {
  3019. while ( (LA(1)==154) ) {
  3020. zzmatch(154); zzCONSUME;
  3021. {
  3022. zzBLOCK(zztasp3);
  3023. zzMake0;
  3024. {
  3025. if ( (LA(1)==ID)&&(isDLGmaxToken(LATEXT(1))) ) {
  3026. if (!(isDLGmaxToken(LATEXT(1))) ) {zzfailed_pred(" isDLGmaxToken(LATEXT(1))",0 /* report */, { ; /* no user action */ } );}
  3027. zzmatch(ID); zzCONSUME;
  3028. {
  3029. zzBLOCK(zztasp4);
  3030. zzMake0;
  3031. {
  3032. if ( (LA(1)==153) ) {
  3033. zzmatch(153); zzCONSUME;
  3034. zzmatch(INT); zzCONSUME;
  3035. }
  3036. else {
  3037. if ( (setwd10[LA(1)]&0x20) ) {
  3038. }
  3039. else {zzFAIL(1,zzerr63,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  3040. }
  3041. zzEXIT(zztasp4);
  3042. }
  3043. }
  3044. }
  3045. else {
  3046. if ( (LA(1)==ID) ) {
  3047. zzmatch(ID);
  3048. t = mystrdup(LATEXT(1));
  3049. zzCONSUME;
  3050. {
  3051. zzBLOCK(zztasp4);
  3052. zzMake0;
  3053. {
  3054. if ( (LA(1)==153) ) {
  3055. zzmatch(153); zzCONSUME;
  3056. zzmatch(INT);
  3057. v=atoi(LATEXT(1));
  3058. zzCONSUME;
  3059. }
  3060. else {
  3061. if ( (setwd10[LA(1)]&0x40) ) {
  3062. v++;
  3063. }
  3064. else {zzFAIL(1,zzerr64,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  3065. }
  3066. zzEXIT(zztasp4);
  3067. }
  3068. }
  3069. /* fprintf(stderr, "#token %s=%d\n", t, v);*/
  3070. TokenNum = v;
  3071. if ( v>maxt ) maxt=v; /* MR3 */
  3072. if ( Tnum( t ) == 0 ) addForcedTname( t, v );
  3073. else {
  3074. warnFL(eMsg1("redefinition of token %s; ignored",t), fname,zzline);
  3075. }
  3076. }
  3077. else {
  3078. if ( (setwd10[LA(1)]&0x80) ) {
  3079. }
  3080. else {zzFAIL(1,zzerr65,&zzMissSet,&zzMissText,&zzBadTok,&zzBadText,&zzErrk); goto fail;}
  3081. }
  3082. }
  3083. zzEXIT(zztasp3);
  3084. }
  3085. }
  3086. zzLOOP(zztasp2);
  3087. }
  3088. zzEXIT(zztasp2);
  3089. }
  3090. }
  3091. zzmatch(155); zzCONSUME;
  3092. zzmatch(156);
  3093. TokenNum = maxt + 1;
  3094. zzCONSUME;
  3095. zzEXIT(zztasp1);
  3096. return;
  3097. fail:
  3098. zzEXIT(zztasp1);
  3099. zzsyn(zzMissText, zzBadTok, (ANTLRChar *)"", zzMissSet, zzMissTok, zzErrk, zzBadText);
  3100. zzresynch(setwd11, 0x1);
  3101. }
  3102. }
  3103. /* MR2 Andreas Magnusson (Andreas.Magnusson@mailbox.swipnet.se) */
  3104. /* MR2 Fix to bug introduced by 1.33MR1 for #tokdefs */
  3105. /* MR2 Don't let #tokdefs be confused by */
  3106. /* MR2 DLGminToken and DLGmaxToken */
  3107. /* semantic check on DLGminToken and DLGmaxmaxToken in #tokdefs */
  3108. #ifdef __USE_PROTOS
  3109. static int isDLGmaxToken(char *Token)
  3110. #else
  3111. static int isDLGmaxToken(Token)
  3112. char * Token;
  3113. #endif
  3114. {
  3115. static char checkStr1[] = "DLGmaxToken";
  3116. static char checkStr2[] = "DLGminToken";
  3117. if (strcmp(Token, checkStr1) == 0)
  3118. return 1;
  3119. else if (strcmp(Token, checkStr2) == 0)
  3120. return 1;
  3121. else
  3122. return 0;
  3123. }
  3124. /* semantics of #token */
  3125. static void
  3126. #ifdef __USE_PROTOS
  3127. chkToken(char *t, char *e, char *a, int tnum)
  3128. #else
  3129. chkToken(t,e,a,tnum)
  3130. char *t, *e, *a;
  3131. int tnum;
  3132. #endif
  3133. {
  3134. TermEntry *p;
  3135. /* check to see that they don't try to redefine a token as a token class */
  3136. if ( t!=NULL ) {
  3137. p = (TermEntry *) hash_get(Tname, t);
  3138. if ( p!=NULL && p->classname ) {
  3139. err(eMsg1("redefinition of #tokclass '%s' to #token not allowed; ignored",t));
  3140. if ( a!=NULL ) free((char *)a);
  3141. return;
  3142. }
  3143. }
  3144. if ( t==NULL && e==NULL ) { /* none found */
  3145. err("#token requires at least token name or rexpr");
  3146. }
  3147. else if ( t!=NULL && e!=NULL ) { /* both found */
  3148. if ( UserDefdTokens ) { /* if #tokdefs, must not define new */
  3149. p = (TermEntry *) hash_get(Tname, t);
  3150. if ( p == NULL) {
  3151. err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t));
  3152. return;
  3153. };
  3154. }
  3155. Tklink(t, e);
  3156. if ( a!=NULL ) {
  3157. if ( hasAction(e) ) {
  3158. err(eMsg1("redefinition of action for %s; ignored",e));
  3159. }
  3160. else setHasAction(e, a);
  3161. }
  3162. }
  3163. else if ( t!=NULL ) { /* only one found */
  3164. if ( UserDefdTokens ) {
  3165. p = (TermEntry *) hash_get(Tname, t);
  3166. if (p == NULL) {
  3167. err(eMsg1("new token definition '%s' not allowed - only #token with name already defined by #tokdefs file allowed",t));
  3168. };
  3169. return;
  3170. }
  3171. if ( Tnum( t ) == 0 ) addTname( t );
  3172. else {
  3173. err(eMsg1("redefinition of token %s; ignored",t));
  3174. }
  3175. if ( a!=NULL ) {
  3176. err(eMsg1("action cannot be attached to a token name (%s); ignored",t));
  3177. free((char *)a);
  3178. }
  3179. }
  3180. else if ( e!=NULL ) {
  3181. if ( Tnum( e ) == 0 ) addTexpr( e );
  3182. else {
  3183. if ( hasAction(e) ) {
  3184. err(eMsg1("redefinition of action for expr %s; ignored",e));
  3185. }
  3186. else if ( a==NULL ) {
  3187. err(eMsg1("redefinition of expr %s; ignored",e));
  3188. }
  3189. }
  3190. if ( a!=NULL ) setHasAction(e, a);
  3191. }
  3192. /* if a token type number was specified, then add the token ID and 'tnum'
  3193. * pair to the ForcedTokens list. (only applies if an id was given)
  3194. */
  3195. if ( t!=NULL && tnum>0 )
  3196. {
  3197. if ( set_el(tnum, reserved_positions) )
  3198. {
  3199. err(eMsgd("a token has already been forced to token number %d; ignored", tnum));
  3200. }
  3201. else
  3202. {
  3203. list_add(&ForcedTokens, newForcedToken(t,tnum));
  3204. set_orel(tnum, &reserved_positions);
  3205. }
  3206. }
  3207. }
  3208. static int
  3209. #ifdef __USE_PROTOS
  3210. match_token(char *s, char **nxt)
  3211. #else
  3212. match_token(s,nxt)
  3213. char *s;
  3214. char **nxt;
  3215. #endif
  3216. {
  3217. if ( !(*s>='A' && *s<='Z') ) return 0;
  3218. s++;
  3219. while ( (*s>='a' && *s<='z') ||
  3220. (*s>='A' && *s<='Z') ||
  3221. (*s>='0' && *s<='9') ||
  3222. *s=='_' )
  3223. {
  3224. s++;
  3225. }
  3226. if ( *s!=' ' && *s!='}' ) return 0;
  3227. *nxt = s;
  3228. return 1;
  3229. }
  3230. static int
  3231. #ifdef __USE_PROTOS
  3232. match_rexpr(char *s, char **nxt)
  3233. #else
  3234. match_rexpr(s,nxt)
  3235. char *s;
  3236. char **nxt;
  3237. #endif
  3238. {
  3239. if ( *s!='"' ) return 0;
  3240. s++;
  3241. while ( *s!='"' )
  3242. {
  3243. if ( *s=='\n' || *s=='\r' ) /* MR13 */
  3244. warn("eoln found in regular expression");
  3245. if ( *s=='\\' ) s++;
  3246. s++;
  3247. }
  3248. *nxt = s+1;
  3249. return 1;
  3250. }
  3251. /*
  3252. * Walk a string "{ A .. Z }" where A..Z is a space separated list
  3253. * of token references (either labels or reg exprs). Return a
  3254. * string "inlineX_set" for some unique integer X. Basically,
  3255. * we pretend as if we had seen "#tokclass inlineX { A .. Z }"
  3256. * on the input stream outside of an action.
  3257. */
  3258. char *
  3259. #ifdef __USE_PROTOS
  3260. inline_set(char *s)
  3261. #else
  3262. inline_set(s)
  3263. char *s;
  3264. #endif
  3265. {
  3266. char *nxt;
  3267. fprintf(stderr, "found consumeUntil( {...} )\n");
  3268. while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
  3269. if ( *s!='{' )
  3270. {
  3271. err("malformed consumeUntil( {...} ); missing '{'");
  3272. return "bad_set";
  3273. }
  3274. s++;
  3275. while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
  3276. while ( *s!='}' )
  3277. {
  3278. if ( match_token(s,&nxt) ) fprintf(stderr, "found token %s\n", s);
  3279. else if ( match_rexpr(s,&nxt) ) fprintf(stderr, "found rexpr %s\n", s);
  3280. else {
  3281. err("invalid element in consumeUntil( {...} )");
  3282. return "bad_set";
  3283. }
  3284. s = nxt;
  3285. while ( *s==' ' || *s=='\t' || *s=='\n' || *s=='\r' ) {s++;}
  3286. }
  3287. return "inlineX_set";
  3288. }
  3289. /* ANTLR-specific syntax error message generator
  3290. * (define USER_ZZSYN when compiling so don't get 2 definitions)
  3291. */
  3292. void
  3293. #ifdef __USE_PROTOS
  3294. zzsyn(char *text, int tok, char *egroup, SetWordType *eset, int etok,
  3295. int k, char *bad_text)
  3296. #else
  3297. zzsyn(text, tok, egroup, eset, etok, k, bad_text)
  3298. char *text, *egroup, *bad_text;
  3299. int tok;
  3300. int etok;
  3301. int k;
  3302. SetWordType *eset;
  3303. #endif
  3304. {
  3305. fprintf(stderr, ErrHdr, FileStr[CurFile]!=NULL?FileStr[CurFile]:"stdin", zzline);
  3306. fprintf(stderr, " syntax error at \"%s\"", (tok==zzEOF_TOKEN)?"EOF":text);
  3307. if ( !etok && !eset ) {fprintf(stderr, "\n"); return;}
  3308. if ( k==1 ) fprintf(stderr, " missing");
  3309. else
  3310. {
  3311. fprintf(stderr, "; \"%s\" not", bad_text);
  3312. if ( zzset_deg(eset)>1 ) fprintf(stderr, " in");
  3313. }
  3314. if ( zzset_deg(eset)>0 ) zzedecode(eset);
  3315. else fprintf(stderr, " %s", zztokens[etok]);
  3316. if ( strlen(egroup) > (size_t)0 ) fprintf(stderr, " in %s", egroup);
  3317. fprintf(stderr, "\n");
  3318. }