NCDConfigParser_parse.c 58 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  1. /* Driver template for the LEMON parser generator.
  2. ** The author disclaims copyright to this source code.
  3. */
  4. /* First off, code is included that follows the "include" declaration
  5. ** in the input grammar file. */
  6. #include <stdio.h>
  7. #line 30 "NCDConfigParser_parse.y"
  8. #include <string.h>
  9. #include <stddef.h>
  10. #include <misc/debug.h>
  11. #include <misc/concat_strings.h>
  12. #include <ncd/NCDAst.h>
  13. struct parser_out {
  14. int out_of_memory;
  15. int syntax_error;
  16. int have_ast;
  17. NCDProgram ast;
  18. };
  19. struct token {
  20. char *str;
  21. size_t len;
  22. };
  23. struct program {
  24. int have;
  25. NCDProgram v;
  26. };
  27. struct block {
  28. int have;
  29. NCDBlock v;
  30. };
  31. struct statement {
  32. int have;
  33. NCDStatement v;
  34. };
  35. struct ifblock {
  36. int have;
  37. NCDIfBlock v;
  38. };
  39. struct value {
  40. int have;
  41. NCDValue v;
  42. };
  43. static void free_token (struct token o) { free(o.str); }
  44. static void free_program (struct program o) { if (o.have) NCDProgram_Free(&o.v); }
  45. static void free_block (struct block o) { if (o.have) NCDBlock_Free(&o.v); }
  46. static void free_statement (struct statement o) { if (o.have) NCDStatement_Free(&o.v); }
  47. static void free_ifblock (struct ifblock o) { if (o.have) NCDIfBlock_Free(&o.v); }
  48. static void free_value (struct value o) { if (o.have) NCDValue_Free(&o.v); }
  49. #line 62 "NCDConfigParser_parse.c"
  50. /* Next is all token values, in a form suitable for use by makeheaders.
  51. ** This section will be null unless lemon is run with the -m switch.
  52. */
  53. /*
  54. ** These constants (all generated automatically by the parser generator)
  55. ** specify the various kinds of tokens (terminals) that the parser
  56. ** understands.
  57. **
  58. ** Each symbol here is a terminal symbol in the grammar.
  59. */
  60. /* Make sure the INTERFACE macro is defined.
  61. */
  62. #ifndef INTERFACE
  63. # define INTERFACE 1
  64. #endif
  65. /* The next thing included is series of defines which control
  66. ** various aspects of the generated parser.
  67. ** YYCODETYPE is the data type used for storing terminal
  68. ** and nonterminal numbers. "unsigned char" is
  69. ** used if there are fewer than 250 terminals
  70. ** and nonterminals. "int" is used otherwise.
  71. ** YYNOCODE is a number of type YYCODETYPE which corresponds
  72. ** to no legal terminal or nonterminal number. This
  73. ** number is used to fill in empty slots of the hash
  74. ** table.
  75. ** YYFALLBACK If defined, this indicates that one or more tokens
  76. ** have fall-back values which should be used if the
  77. ** original value of the token will not parse.
  78. ** YYACTIONTYPE is the data type used for storing terminal
  79. ** and nonterminal numbers. "unsigned char" is
  80. ** used if there are fewer than 250 rules and
  81. ** states combined. "int" is used otherwise.
  82. ** ParseTOKENTYPE is the data type used for minor tokens given
  83. ** directly to the parser from the tokenizer.
  84. ** YYMINORTYPE is the data type used for all minor tokens.
  85. ** This is typically a union of many types, one of
  86. ** which is ParseTOKENTYPE. The entry in the union
  87. ** for base tokens is called "yy0".
  88. ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
  89. ** zero the stack is dynamically sized using realloc()
  90. ** ParseARG_SDECL A static variable declaration for the %extra_argument
  91. ** ParseARG_PDECL A parameter declaration for the %extra_argument
  92. ** ParseARG_STORE Code to store %extra_argument into yypParser
  93. ** ParseARG_FETCH Code to extract %extra_argument from yypParser
  94. ** YYNSTATE the combined number of states.
  95. ** YYNRULE the number of rules in the grammar
  96. ** YYERRORSYMBOL is the code number of the error symbol. If not
  97. ** defined, then do no error processing.
  98. */
  99. #define YYCODETYPE unsigned char
  100. #define YYNOCODE 39
  101. #define YYACTIONTYPE unsigned char
  102. #define ParseTOKENTYPE struct token
  103. typedef union {
  104. int yyinit;
  105. ParseTOKENTYPE yy0;
  106. struct ifblock yy4;
  107. int yy8;
  108. char * yy9;
  109. struct statement yy23;
  110. struct value yy27;
  111. struct block yy29;
  112. struct program yy74;
  113. } YYMINORTYPE;
  114. #ifndef YYSTACKDEPTH
  115. #define YYSTACKDEPTH 0
  116. #endif
  117. #define ParseARG_SDECL struct parser_out *parser_out ;
  118. #define ParseARG_PDECL , struct parser_out *parser_out
  119. #define ParseARG_FETCH struct parser_out *parser_out = yypParser->parser_out
  120. #define ParseARG_STORE yypParser->parser_out = parser_out
  121. #define YYNSTATE 93
  122. #define YYNRULE 36
  123. #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
  124. #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
  125. #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
  126. /* The yyzerominor constant is used to initialize instances of
  127. ** YYMINORTYPE objects to zero. */
  128. static const YYMINORTYPE yyzerominor = { 0 };
  129. /* Define the yytestcase() macro to be a no-op if is not already defined
  130. ** otherwise.
  131. **
  132. ** Applications can choose to define yytestcase() in the %include section
  133. ** to a macro that can assist in verifying code coverage. For production
  134. ** code the yytestcase() macro should be turned off. But it is useful
  135. ** for testing.
  136. */
  137. #ifndef yytestcase
  138. # define yytestcase(X)
  139. #endif
  140. /* Next are the tables used to determine what action to take based on the
  141. ** current state and lookahead token. These tables are used to implement
  142. ** functions that take a state number and lookahead value and return an
  143. ** action integer.
  144. **
  145. ** Suppose the action integer is N. Then the action is determined as
  146. ** follows
  147. **
  148. ** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
  149. ** token onto the stack and goto state N.
  150. **
  151. ** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
  152. **
  153. ** N == YYNSTATE+YYNRULE A syntax error has occurred.
  154. **
  155. ** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
  156. **
  157. ** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
  158. ** slots in the yy_action[] table.
  159. **
  160. ** The action table is constructed as a single large table named yy_action[].
  161. ** Given state S and lookahead X, the action is computed as
  162. **
  163. ** yy_action[ yy_shift_ofst[S] + X ]
  164. **
  165. ** If the index value yy_shift_ofst[S]+X is out of range or if the value
  166. ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
  167. ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
  168. ** and that yy_default[S] should be used instead.
  169. **
  170. ** The formula above is for computing the action when the lookahead is
  171. ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
  172. ** a reduce action) then the yy_reduce_ofst[] array is used in place of
  173. ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
  174. ** YY_SHIFT_USE_DFLT.
  175. **
  176. ** The following are the tables generated in this section:
  177. **
  178. ** yy_action[] A single table containing all actions.
  179. ** yy_lookahead[] A table containing the lookahead for each entry in
  180. ** yy_action. Used to detect hash collisions.
  181. ** yy_shift_ofst[] For each state, the offset into yy_action for
  182. ** shifting terminals.
  183. ** yy_reduce_ofst[] For each state, the offset into yy_action for
  184. ** shifting non-terminals after a reduce.
  185. ** yy_default[] Default action for each state.
  186. */
  187. static const YYACTIONTYPE yy_action[] = {
  188. /* 0 */ 80, 35, 74, 81, 68, 82, 38, 80, 44, 74,
  189. /* 10 */ 81, 64, 82, 38, 37, 3, 76, 80, 32, 39,
  190. /* 20 */ 81, 72, 82, 38, 37, 3, 69, 70, 36, 4,
  191. /* 30 */ 80, 79, 55, 81, 42, 82, 40, 37, 58, 4,
  192. /* 40 */ 83, 79, 80, 73, 75, 81, 80, 82, 38, 81,
  193. /* 50 */ 78, 82, 40, 37, 3, 15, 43, 45, 80, 34,
  194. /* 60 */ 29, 81, 92, 82, 41, 25, 24, 91, 4, 80,
  195. /* 70 */ 79, 51, 81, 80, 82, 47, 81, 80, 82, 53,
  196. /* 80 */ 81, 31, 82, 65, 37, 15, 50, 93, 57, 49,
  197. /* 90 */ 29, 46, 52, 15, 33, 32, 130, 63, 29, 15,
  198. /* 100 */ 62, 15, 11, 56, 29, 88, 29, 15, 18, 15,
  199. /* 110 */ 71, 61, 29, 67, 29, 20, 1, 21, 77, 22,
  200. /* 120 */ 7, 5, 6, 2, 85, 84, 23, 8, 12, 48,
  201. /* 130 */ 19, 86, 13, 9, 30, 26, 14, 87, 54, 59,
  202. /* 140 */ 60, 16, 89, 27, 90, 131, 10, 17, 66, 131,
  203. /* 150 */ 28,
  204. };
  205. static const YYCODETYPE yy_lookahead[] = {
  206. /* 0 */ 28, 29, 30, 31, 22, 33, 34, 28, 29, 30,
  207. /* 10 */ 31, 12, 33, 34, 1, 2, 3, 28, 36, 30,
  208. /* 20 */ 31, 1, 33, 34, 1, 2, 19, 20, 35, 16,
  209. /* 30 */ 28, 18, 5, 31, 32, 33, 34, 1, 11, 16,
  210. /* 40 */ 17, 18, 28, 28, 30, 31, 28, 33, 34, 31,
  211. /* 50 */ 32, 33, 34, 1, 2, 23, 28, 35, 28, 27,
  212. /* 60 */ 28, 31, 25, 33, 34, 26, 24, 25, 16, 28,
  213. /* 70 */ 18, 13, 31, 28, 33, 34, 31, 28, 33, 34,
  214. /* 80 */ 31, 22, 33, 34, 1, 23, 35, 0, 35, 27,
  215. /* 90 */ 28, 8, 9, 23, 1, 36, 37, 27, 28, 23,
  216. /* 100 */ 35, 23, 2, 27, 28, 27, 28, 23, 3, 23,
  217. /* 110 */ 6, 27, 28, 27, 28, 5, 4, 14, 3, 7,
  218. /* 120 */ 11, 15, 15, 4, 6, 17, 5, 4, 2, 5,
  219. /* 130 */ 3, 6, 2, 4, 1, 3, 2, 6, 10, 1,
  220. /* 140 */ 5, 2, 6, 3, 3, 38, 4, 2, 5, 38,
  221. /* 150 */ 3,
  222. };
  223. #define YY_SHIFT_USE_DFLT (-2)
  224. #define YY_SHIFT_MAX 67
  225. static const short yy_shift_ofst[] = {
  226. /* 0 */ 7, 52, 52, 13, 23, 52, 52, 52, 52, 52,
  227. /* 10 */ 52, 83, 83, 83, 83, 83, 83, 83, 7, -1,
  228. /* 20 */ 20, 36, 36, 20, 58, 20, 20, 20, -1, 112,
  229. /* 30 */ 27, 87, 93, 100, 105, 110, 104, 103, 106, 115,
  230. /* 40 */ 109, 107, 108, 119, 121, 118, 123, 124, 126, 127,
  231. /* 50 */ 125, 130, 129, 128, 133, 134, 132, 131, 138, 135,
  232. /* 60 */ 139, 140, 136, 141, 142, 143, 145, 147,
  233. };
  234. #define YY_REDUCE_USE_DFLT (-29)
  235. #define YY_REDUCE_MAX 28
  236. static const signed char yy_reduce_ofst[] = {
  237. /* 0 */ 59, -28, -21, -11, 2, 14, 18, 30, 41, 45,
  238. /* 10 */ 49, 32, 62, 70, 76, 78, 84, 86, -18, 42,
  239. /* 20 */ -7, 15, 28, 22, 39, 51, 53, 65, 37,
  240. };
  241. static const YYACTIONTYPE yy_default[] = {
  242. /* 0 */ 129, 111, 111, 129, 129, 129, 129, 129, 129, 129,
  243. /* 10 */ 129, 129, 129, 129, 129, 107, 129, 129, 94, 101,
  244. /* 20 */ 125, 129, 129, 125, 105, 125, 125, 125, 103, 129,
  245. /* 30 */ 129, 129, 129, 129, 129, 129, 129, 109, 113, 129,
  246. /* 40 */ 129, 117, 129, 129, 129, 129, 129, 129, 129, 129,
  247. /* 50 */ 129, 129, 129, 129, 129, 129, 129, 129, 129, 129,
  248. /* 60 */ 129, 129, 129, 129, 129, 129, 129, 129, 95, 127,
  249. /* 70 */ 128, 96, 126, 110, 112, 114, 115, 116, 118, 121,
  250. /* 80 */ 122, 123, 124, 119, 120, 97, 98, 99, 108, 100,
  251. /* 90 */ 106, 102, 104,
  252. };
  253. #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
  254. /* The next table maps tokens into fallback tokens. If a construct
  255. ** like the following:
  256. **
  257. ** %fallback ID X Y Z.
  258. **
  259. ** appears in the grammar, then ID becomes a fallback token for X, Y,
  260. ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
  261. ** but it does not parse, the type of the token is changed to ID and
  262. ** the parse is retried before an error is thrown.
  263. */
  264. #ifdef YYFALLBACK
  265. static const YYCODETYPE yyFallback[] = {
  266. };
  267. #endif /* YYFALLBACK */
  268. /* The following structure represents a single element of the
  269. ** parser's stack. Information stored includes:
  270. **
  271. ** + The state number for the parser at this level of the stack.
  272. **
  273. ** + The value of the token stored at this level of the stack.
  274. ** (In other words, the "major" token.)
  275. **
  276. ** + The semantic value stored at this level of the stack. This is
  277. ** the information used by the action routines in the grammar.
  278. ** It is sometimes called the "minor" token.
  279. */
  280. struct yyStackEntry {
  281. YYACTIONTYPE stateno; /* The state-number */
  282. YYCODETYPE major; /* The major token value. This is the code
  283. ** number for the token at this stack level */
  284. YYMINORTYPE minor; /* The user-supplied minor token value. This
  285. ** is the value of the token */
  286. };
  287. typedef struct yyStackEntry yyStackEntry;
  288. /* The state of the parser is completely contained in an instance of
  289. ** the following structure */
  290. struct yyParser {
  291. int yyidx; /* Index of top element in stack */
  292. #ifdef YYTRACKMAXSTACKDEPTH
  293. int yyidxMax; /* Maximum value of yyidx */
  294. #endif
  295. int yyerrcnt; /* Shifts left before out of the error */
  296. ParseARG_SDECL /* A place to hold %extra_argument */
  297. #if YYSTACKDEPTH<=0
  298. int yystksz; /* Current side of the stack */
  299. yyStackEntry *yystack; /* The parser's stack */
  300. #else
  301. yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
  302. #endif
  303. };
  304. typedef struct yyParser yyParser;
  305. #ifndef NDEBUG
  306. #include <stdio.h>
  307. static FILE *yyTraceFILE = 0;
  308. static char *yyTracePrompt = 0;
  309. #endif /* NDEBUG */
  310. #ifndef NDEBUG
  311. /*
  312. ** Turn parser tracing on by giving a stream to which to write the trace
  313. ** and a prompt to preface each trace message. Tracing is turned off
  314. ** by making either argument NULL
  315. **
  316. ** Inputs:
  317. ** <ul>
  318. ** <li> A FILE* to which trace output should be written.
  319. ** If NULL, then tracing is turned off.
  320. ** <li> A prefix string written at the beginning of every
  321. ** line of trace output. If NULL, then tracing is
  322. ** turned off.
  323. ** </ul>
  324. **
  325. ** Outputs:
  326. ** None.
  327. */
  328. void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
  329. yyTraceFILE = TraceFILE;
  330. yyTracePrompt = zTracePrompt;
  331. if( yyTraceFILE==0 ) yyTracePrompt = 0;
  332. else if( yyTracePrompt==0 ) yyTraceFILE = 0;
  333. }
  334. #endif /* NDEBUG */
  335. #ifndef NDEBUG
  336. /* For tracing shifts, the names of all terminals and nonterminals
  337. ** are required. The following table supplies these names */
  338. static const char *const yyTokenName[] = {
  339. "$", "NAME", "CURLY_OPEN", "CURLY_CLOSE",
  340. "ROUND_OPEN", "ROUND_CLOSE", "SEMICOLON", "ARROW",
  341. "IF", "FOREACH", "AS", "COLON",
  342. "ELIF", "ELSE", "DOT", "COMMA",
  343. "BRACKET_OPEN", "BRACKET_CLOSE", "STRING", "PROCESS",
  344. "TEMPLATE", "error", "processes", "statement",
  345. "elif_maybe", "elif", "else_maybe", "statements",
  346. "dotted_name", "statement_args_maybe", "list_contents", "list",
  347. "map_contents", "map", "value", "name_maybe",
  348. "process_or_template", "input",
  349. };
  350. #endif /* NDEBUG */
  351. #ifndef NDEBUG
  352. /* For tracing reduce actions, the names of all rules are required.
  353. */
  354. static const char *const yyRuleName[] = {
  355. /* 0 */ "input ::= processes",
  356. /* 1 */ "processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE",
  357. /* 2 */ "processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE processes",
  358. /* 3 */ "statement ::= dotted_name ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON",
  359. /* 4 */ "statement ::= dotted_name ARROW dotted_name ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON",
  360. /* 5 */ "statement ::= IF ROUND_OPEN value ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE elif_maybe else_maybe name_maybe SEMICOLON",
  361. /* 6 */ "statement ::= FOREACH ROUND_OPEN value AS NAME ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE name_maybe SEMICOLON",
  362. /* 7 */ "statement ::= FOREACH ROUND_OPEN value AS NAME COLON NAME ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE name_maybe SEMICOLON",
  363. /* 8 */ "elif_maybe ::=",
  364. /* 9 */ "elif_maybe ::= elif",
  365. /* 10 */ "elif ::= ELIF ROUND_OPEN value ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE",
  366. /* 11 */ "elif ::= ELIF ROUND_OPEN value ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE elif",
  367. /* 12 */ "else_maybe ::=",
  368. /* 13 */ "else_maybe ::= ELSE CURLY_OPEN statements CURLY_CLOSE",
  369. /* 14 */ "statements ::= statement",
  370. /* 15 */ "statements ::= statement statements",
  371. /* 16 */ "dotted_name ::= NAME",
  372. /* 17 */ "dotted_name ::= NAME DOT dotted_name",
  373. /* 18 */ "statement_args_maybe ::=",
  374. /* 19 */ "statement_args_maybe ::= list_contents",
  375. /* 20 */ "list_contents ::= value",
  376. /* 21 */ "list_contents ::= value COMMA list_contents",
  377. /* 22 */ "list ::= CURLY_OPEN CURLY_CLOSE",
  378. /* 23 */ "list ::= CURLY_OPEN list_contents CURLY_CLOSE",
  379. /* 24 */ "map_contents ::= value COLON value",
  380. /* 25 */ "map_contents ::= value COLON value COMMA map_contents",
  381. /* 26 */ "map ::= BRACKET_OPEN BRACKET_CLOSE",
  382. /* 27 */ "map ::= BRACKET_OPEN map_contents BRACKET_CLOSE",
  383. /* 28 */ "value ::= STRING",
  384. /* 29 */ "value ::= dotted_name",
  385. /* 30 */ "value ::= list",
  386. /* 31 */ "value ::= map",
  387. /* 32 */ "name_maybe ::=",
  388. /* 33 */ "name_maybe ::= NAME",
  389. /* 34 */ "process_or_template ::= PROCESS",
  390. /* 35 */ "process_or_template ::= TEMPLATE",
  391. };
  392. #endif /* NDEBUG */
  393. #if YYSTACKDEPTH<=0
  394. /*
  395. ** Try to increase the size of the parser stack.
  396. */
  397. static void yyGrowStack(yyParser *p){
  398. int newSize;
  399. yyStackEntry *pNew;
  400. newSize = p->yystksz*2 + 100;
  401. pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
  402. if( pNew ){
  403. p->yystack = pNew;
  404. p->yystksz = newSize;
  405. #ifndef NDEBUG
  406. if( yyTraceFILE ){
  407. fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
  408. yyTracePrompt, p->yystksz);
  409. }
  410. #endif
  411. }
  412. }
  413. #endif
  414. /*
  415. ** This function allocates a new parser.
  416. ** The only argument is a pointer to a function which works like
  417. ** malloc.
  418. **
  419. ** Inputs:
  420. ** A pointer to the function used to allocate memory.
  421. **
  422. ** Outputs:
  423. ** A pointer to a parser. This pointer is used in subsequent calls
  424. ** to Parse and ParseFree.
  425. */
  426. void *ParseAlloc(void *(*mallocProc)(size_t)){
  427. yyParser *pParser;
  428. pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
  429. if( pParser ){
  430. pParser->yyidx = -1;
  431. #ifdef YYTRACKMAXSTACKDEPTH
  432. pParser->yyidxMax = 0;
  433. #endif
  434. #if YYSTACKDEPTH<=0
  435. pParser->yystack = NULL;
  436. pParser->yystksz = 0;
  437. yyGrowStack(pParser);
  438. #endif
  439. }
  440. return pParser;
  441. }
  442. /* The following function deletes the value associated with a
  443. ** symbol. The symbol can be either a terminal or nonterminal.
  444. ** "yymajor" is the symbol code, and "yypminor" is a pointer to
  445. ** the value.
  446. */
  447. static void yy_destructor(
  448. yyParser *yypParser, /* The parser */
  449. YYCODETYPE yymajor, /* Type code for object to destroy */
  450. YYMINORTYPE *yypminor /* The object to be destroyed */
  451. ){
  452. ParseARG_FETCH;
  453. switch( yymajor ){
  454. /* Here is inserted the actions which take place when a
  455. ** terminal or non-terminal is destroyed. This can happen
  456. ** when the symbol is popped from the stack during a
  457. ** reduce or during error processing or when a parser is
  458. ** being destroyed before it is finished parsing.
  459. **
  460. ** Note: during a reduce, the only symbols destroyed are those
  461. ** which appear on the RHS of the rule, but which are not used
  462. ** inside the C code.
  463. */
  464. /* TERMINAL Destructor */
  465. case 1: /* NAME */
  466. case 2: /* CURLY_OPEN */
  467. case 3: /* CURLY_CLOSE */
  468. case 4: /* ROUND_OPEN */
  469. case 5: /* ROUND_CLOSE */
  470. case 6: /* SEMICOLON */
  471. case 7: /* ARROW */
  472. case 8: /* IF */
  473. case 9: /* FOREACH */
  474. case 10: /* AS */
  475. case 11: /* COLON */
  476. case 12: /* ELIF */
  477. case 13: /* ELSE */
  478. case 14: /* DOT */
  479. case 15: /* COMMA */
  480. case 16: /* BRACKET_OPEN */
  481. case 17: /* BRACKET_CLOSE */
  482. case 18: /* STRING */
  483. case 19: /* PROCESS */
  484. case 20: /* TEMPLATE */
  485. {
  486. #line 89 "NCDConfigParser_parse.y"
  487. free_token((yypminor->yy0));
  488. #line 517 "NCDConfigParser_parse.c"
  489. }
  490. break;
  491. case 22: /* processes */
  492. {
  493. #line 108 "NCDConfigParser_parse.y"
  494. (void)parser_out; free_program((yypminor->yy74));
  495. #line 524 "NCDConfigParser_parse.c"
  496. }
  497. break;
  498. case 23: /* statement */
  499. {
  500. #line 109 "NCDConfigParser_parse.y"
  501. free_statement((yypminor->yy23));
  502. #line 531 "NCDConfigParser_parse.c"
  503. }
  504. break;
  505. case 24: /* elif_maybe */
  506. case 25: /* elif */
  507. {
  508. #line 110 "NCDConfigParser_parse.y"
  509. free_ifblock((yypminor->yy4));
  510. #line 539 "NCDConfigParser_parse.c"
  511. }
  512. break;
  513. case 26: /* else_maybe */
  514. case 27: /* statements */
  515. {
  516. #line 112 "NCDConfigParser_parse.y"
  517. free_block((yypminor->yy29));
  518. #line 547 "NCDConfigParser_parse.c"
  519. }
  520. break;
  521. case 28: /* dotted_name */
  522. case 35: /* name_maybe */
  523. {
  524. #line 114 "NCDConfigParser_parse.y"
  525. free((yypminor->yy9));
  526. #line 555 "NCDConfigParser_parse.c"
  527. }
  528. break;
  529. case 29: /* statement_args_maybe */
  530. case 30: /* list_contents */
  531. case 31: /* list */
  532. case 32: /* map_contents */
  533. case 33: /* map */
  534. case 34: /* value */
  535. {
  536. #line 115 "NCDConfigParser_parse.y"
  537. free_value((yypminor->yy27));
  538. #line 567 "NCDConfigParser_parse.c"
  539. }
  540. break;
  541. default: break; /* If no destructor action specified: do nothing */
  542. }
  543. }
  544. /*
  545. ** Pop the parser's stack once.
  546. **
  547. ** If there is a destructor routine associated with the token which
  548. ** is popped from the stack, then call it.
  549. **
  550. ** Return the major token number for the symbol popped.
  551. */
  552. static int yy_pop_parser_stack(yyParser *pParser){
  553. YYCODETYPE yymajor;
  554. yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
  555. if( pParser->yyidx<0 ) return 0;
  556. #ifndef NDEBUG
  557. if( yyTraceFILE && pParser->yyidx>=0 ){
  558. fprintf(yyTraceFILE,"%sPopping %s\n",
  559. yyTracePrompt,
  560. yyTokenName[yytos->major]);
  561. }
  562. #endif
  563. yymajor = yytos->major;
  564. yy_destructor(pParser, yymajor, &yytos->minor);
  565. pParser->yyidx--;
  566. return yymajor;
  567. }
  568. /*
  569. ** Deallocate and destroy a parser. Destructors are all called for
  570. ** all stack elements before shutting the parser down.
  571. **
  572. ** Inputs:
  573. ** <ul>
  574. ** <li> A pointer to the parser. This should be a pointer
  575. ** obtained from ParseAlloc.
  576. ** <li> A pointer to a function used to reclaim memory obtained
  577. ** from malloc.
  578. ** </ul>
  579. */
  580. void ParseFree(
  581. void *p, /* The parser to be deleted */
  582. void (*freeProc)(void*) /* Function used to reclaim memory */
  583. ){
  584. yyParser *pParser = (yyParser*)p;
  585. if( pParser==0 ) return;
  586. while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
  587. #if YYSTACKDEPTH<=0
  588. free(pParser->yystack);
  589. #endif
  590. (*freeProc)((void*)pParser);
  591. }
  592. /*
  593. ** Return the peak depth of the stack for a parser.
  594. */
  595. #ifdef YYTRACKMAXSTACKDEPTH
  596. int ParseStackPeak(void *p){
  597. yyParser *pParser = (yyParser*)p;
  598. return pParser->yyidxMax;
  599. }
  600. #endif
  601. /*
  602. ** Find the appropriate action for a parser given the terminal
  603. ** look-ahead token iLookAhead.
  604. **
  605. ** If the look-ahead token is YYNOCODE, then check to see if the action is
  606. ** independent of the look-ahead. If it is, return the action, otherwise
  607. ** return YY_NO_ACTION.
  608. */
  609. static int yy_find_shift_action(
  610. yyParser *pParser, /* The parser */
  611. YYCODETYPE iLookAhead /* The look-ahead token */
  612. ){
  613. int i;
  614. int stateno = pParser->yystack[pParser->yyidx].stateno;
  615. if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
  616. return yy_default[stateno];
  617. }
  618. assert( iLookAhead!=YYNOCODE );
  619. i += iLookAhead;
  620. if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  621. if( iLookAhead>0 ){
  622. #ifdef YYFALLBACK
  623. YYCODETYPE iFallback; /* Fallback token */
  624. if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
  625. && (iFallback = yyFallback[iLookAhead])!=0 ){
  626. #ifndef NDEBUG
  627. if( yyTraceFILE ){
  628. fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
  629. yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
  630. }
  631. #endif
  632. return yy_find_shift_action(pParser, iFallback);
  633. }
  634. #endif
  635. #ifdef YYWILDCARD
  636. {
  637. int j = i - iLookAhead + YYWILDCARD;
  638. if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
  639. #ifndef NDEBUG
  640. if( yyTraceFILE ){
  641. fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
  642. yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
  643. }
  644. #endif /* NDEBUG */
  645. return yy_action[j];
  646. }
  647. }
  648. #endif /* YYWILDCARD */
  649. }
  650. return yy_default[stateno];
  651. }else{
  652. return yy_action[i];
  653. }
  654. }
  655. /*
  656. ** Find the appropriate action for a parser given the non-terminal
  657. ** look-ahead token iLookAhead.
  658. **
  659. ** If the look-ahead token is YYNOCODE, then check to see if the action is
  660. ** independent of the look-ahead. If it is, return the action, otherwise
  661. ** return YY_NO_ACTION.
  662. */
  663. static int yy_find_reduce_action(
  664. int stateno, /* Current state number */
  665. YYCODETYPE iLookAhead /* The look-ahead token */
  666. ){
  667. int i;
  668. #ifdef YYERRORSYMBOL
  669. if( stateno>YY_REDUCE_MAX ){
  670. return yy_default[stateno];
  671. }
  672. #else
  673. assert( stateno<=YY_REDUCE_MAX );
  674. #endif
  675. i = yy_reduce_ofst[stateno];
  676. assert( i!=YY_REDUCE_USE_DFLT );
  677. assert( iLookAhead!=YYNOCODE );
  678. i += iLookAhead;
  679. #ifdef YYERRORSYMBOL
  680. if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  681. return yy_default[stateno];
  682. }
  683. #else
  684. assert( i>=0 && i<YY_SZ_ACTTAB );
  685. assert( yy_lookahead[i]==iLookAhead );
  686. #endif
  687. return yy_action[i];
  688. }
  689. /*
  690. ** The following routine is called if the stack overflows.
  691. */
  692. static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
  693. ParseARG_FETCH;
  694. yypParser->yyidx--;
  695. #ifndef NDEBUG
  696. if( yyTraceFILE ){
  697. fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
  698. }
  699. #endif
  700. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  701. /* Here code is inserted which will execute if the parser
  702. ** stack every overflows */
  703. #line 130 "NCDConfigParser_parse.y"
  704. if (yypMinor) {
  705. free_token(yypMinor->yy0);
  706. }
  707. #line 745 "NCDConfigParser_parse.c"
  708. ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
  709. }
  710. /*
  711. ** Perform a shift action.
  712. */
  713. static void yy_shift(
  714. yyParser *yypParser, /* The parser to be shifted */
  715. int yyNewState, /* The new state to shift in */
  716. int yyMajor, /* The major token to shift in */
  717. YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
  718. ){
  719. yyStackEntry *yytos;
  720. yypParser->yyidx++;
  721. #ifdef YYTRACKMAXSTACKDEPTH
  722. if( yypParser->yyidx>yypParser->yyidxMax ){
  723. yypParser->yyidxMax = yypParser->yyidx;
  724. }
  725. #endif
  726. #if YYSTACKDEPTH>0
  727. if( yypParser->yyidx>=YYSTACKDEPTH ){
  728. yyStackOverflow(yypParser, yypMinor);
  729. return;
  730. }
  731. #else
  732. if( yypParser->yyidx>=yypParser->yystksz ){
  733. yyGrowStack(yypParser);
  734. if( yypParser->yyidx>=yypParser->yystksz ){
  735. yyStackOverflow(yypParser, yypMinor);
  736. return;
  737. }
  738. }
  739. #endif
  740. yytos = &yypParser->yystack[yypParser->yyidx];
  741. yytos->stateno = (YYACTIONTYPE)yyNewState;
  742. yytos->major = (YYCODETYPE)yyMajor;
  743. yytos->minor = *yypMinor;
  744. #ifndef NDEBUG
  745. if( yyTraceFILE && yypParser->yyidx>0 ){
  746. int i;
  747. fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
  748. fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
  749. for(i=1; i<=yypParser->yyidx; i++)
  750. fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
  751. fprintf(yyTraceFILE,"\n");
  752. }
  753. #endif
  754. }
  755. /* The following table contains information about every rule that
  756. ** is used during the reduce.
  757. */
  758. static const struct {
  759. YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
  760. unsigned char nrhs; /* Number of right-hand side symbols in the rule */
  761. } yyRuleInfo[] = {
  762. { 37, 1 },
  763. { 22, 5 },
  764. { 22, 6 },
  765. { 23, 6 },
  766. { 23, 8 },
  767. { 23, 11 },
  768. { 23, 11 },
  769. { 23, 13 },
  770. { 24, 0 },
  771. { 24, 1 },
  772. { 25, 7 },
  773. { 25, 8 },
  774. { 26, 0 },
  775. { 26, 4 },
  776. { 27, 1 },
  777. { 27, 2 },
  778. { 28, 1 },
  779. { 28, 3 },
  780. { 29, 0 },
  781. { 29, 1 },
  782. { 30, 1 },
  783. { 30, 3 },
  784. { 31, 2 },
  785. { 31, 3 },
  786. { 32, 3 },
  787. { 32, 5 },
  788. { 33, 2 },
  789. { 33, 3 },
  790. { 34, 1 },
  791. { 34, 1 },
  792. { 34, 1 },
  793. { 34, 1 },
  794. { 35, 0 },
  795. { 35, 1 },
  796. { 36, 1 },
  797. { 36, 1 },
  798. };
  799. static void yy_accept(yyParser*); /* Forward Declaration */
  800. /*
  801. ** Perform a reduce action and the shift that must immediately
  802. ** follow the reduce.
  803. */
  804. static void yy_reduce(
  805. yyParser *yypParser, /* The parser */
  806. int yyruleno /* Number of the rule by which to reduce */
  807. ){
  808. int yygoto; /* The next state */
  809. int yyact; /* The next action */
  810. YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
  811. yyStackEntry *yymsp; /* The top of the parser's stack */
  812. int yysize; /* Amount to pop the stack */
  813. ParseARG_FETCH;
  814. yymsp = &yypParser->yystack[yypParser->yyidx];
  815. #ifndef NDEBUG
  816. if( yyTraceFILE && yyruleno>=0
  817. && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
  818. fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
  819. yyRuleName[yyruleno]);
  820. }
  821. #endif /* NDEBUG */
  822. /* Silence complaints from purify about yygotominor being uninitialized
  823. ** in some cases when it is copied into the stack after the following
  824. ** switch. yygotominor is uninitialized when a rule reduces that does
  825. ** not set the value of its left-hand side nonterminal. Leaving the
  826. ** value of the nonterminal uninitialized is utterly harmless as long
  827. ** as the value is never used. So really the only thing this code
  828. ** accomplishes is to quieten purify.
  829. **
  830. ** 2007-01-16: The wireshark project (www.wireshark.org) reports that
  831. ** without this code, their parser segfaults. I'm not sure what there
  832. ** parser is doing to make this happen. This is the second bug report
  833. ** from wireshark this week. Clearly they are stressing Lemon in ways
  834. ** that it has not been previously stressed... (SQLite ticket #2172)
  835. */
  836. /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  837. yygotominor = yyzerominor;
  838. switch( yyruleno ){
  839. /* Beginning here are the reduction cases. A typical example
  840. ** follows:
  841. ** case 0:
  842. ** #line <lineno> <grammarfile>
  843. ** { ... } // User supplied code
  844. ** #line <lineno> <thisfile>
  845. ** break;
  846. */
  847. case 0: /* input ::= processes */
  848. #line 136 "NCDConfigParser_parse.y"
  849. {
  850. ASSERT(!parser_out->have_ast)
  851. if (yymsp[0].minor.yy74.have) {
  852. parser_out->have_ast = 1;
  853. parser_out->ast = yymsp[0].minor.yy74.v;
  854. }
  855. }
  856. #line 902 "NCDConfigParser_parse.c"
  857. break;
  858. case 1: /* processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE */
  859. #line 145 "NCDConfigParser_parse.y"
  860. {
  861. ASSERT(yymsp[-3].minor.yy0.str)
  862. if (!yymsp[-1].minor.yy29.have) {
  863. goto failA0;
  864. }
  865. NCDProcess proc;
  866. if (!NCDProcess_Init(&proc, yymsp[-4].minor.yy8, yymsp[-3].minor.yy0.str, yymsp[-1].minor.yy29.v)) {
  867. goto failA0;
  868. }
  869. yymsp[-1].minor.yy29.have = 0;
  870. NCDProgram prog;
  871. NCDProgram_Init(&prog);
  872. if (!NCDProgram_PrependProcess(&prog, proc)) {
  873. goto failA1;
  874. }
  875. yygotominor.yy74.have = 1;
  876. yygotominor.yy74.v = prog;
  877. goto doneA;
  878. failA1:
  879. NCDProgram_Free(&prog);
  880. NCDProcess_Free(&proc);
  881. failA0:
  882. yygotominor.yy74.have = 0;
  883. parser_out->out_of_memory = 1;
  884. doneA:
  885. free_token(yymsp[-3].minor.yy0);
  886. free_block(yymsp[-1].minor.yy29);
  887. yy_destructor(yypParser,2,&yymsp[-2].minor);
  888. yy_destructor(yypParser,3,&yymsp[0].minor);
  889. }
  890. #line 941 "NCDConfigParser_parse.c"
  891. break;
  892. case 2: /* processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE processes */
  893. #line 179 "NCDConfigParser_parse.y"
  894. {
  895. ASSERT(yymsp[-4].minor.yy0.str)
  896. if (!yymsp[-2].minor.yy29.have || !yymsp[0].minor.yy74.have) {
  897. goto failB0;
  898. }
  899. NCDProcess proc;
  900. if (!NCDProcess_Init(&proc, yymsp[-5].minor.yy8, yymsp[-4].minor.yy0.str, yymsp[-2].minor.yy29.v)) {
  901. goto failB0;
  902. }
  903. yymsp[-2].minor.yy29.have = 0;
  904. if (!NCDProgram_PrependProcess(&yymsp[0].minor.yy74.v, proc)) {
  905. goto failB1;
  906. }
  907. yygotominor.yy74.have = 1;
  908. yygotominor.yy74.v = yymsp[0].minor.yy74.v;
  909. yymsp[0].minor.yy74.have = 0;
  910. goto doneB;
  911. failB1:
  912. NCDProcess_Free(&proc);
  913. failB0:
  914. yygotominor.yy74.have = 0;
  915. parser_out->out_of_memory = 1;
  916. doneB:
  917. free_token(yymsp[-4].minor.yy0);
  918. free_block(yymsp[-2].minor.yy29);
  919. free_program(yymsp[0].minor.yy74);
  920. yy_destructor(yypParser,2,&yymsp[-3].minor);
  921. yy_destructor(yypParser,3,&yymsp[-1].minor);
  922. }
  923. #line 978 "NCDConfigParser_parse.c"
  924. break;
  925. case 3: /* statement ::= dotted_name ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON */
  926. #line 211 "NCDConfigParser_parse.y"
  927. {
  928. if (!yymsp[-5].minor.yy9 || !yymsp[-3].minor.yy27.have) {
  929. goto failC0;
  930. }
  931. if (!NCDStatement_InitReg(&yygotominor.yy23.v, yymsp[-1].minor.yy9, NULL, yymsp[-5].minor.yy9, yymsp[-3].minor.yy27.v)) {
  932. goto failC0;
  933. }
  934. yymsp[-3].minor.yy27.have = 0;
  935. yygotominor.yy23.have = 1;
  936. goto doneC;
  937. failC0:
  938. yygotominor.yy23.have = 0;
  939. parser_out->out_of_memory = 1;
  940. doneC:
  941. free(yymsp[-5].minor.yy9);
  942. free_value(yymsp[-3].minor.yy27);
  943. free(yymsp[-1].minor.yy9);
  944. yy_destructor(yypParser,4,&yymsp[-4].minor);
  945. yy_destructor(yypParser,5,&yymsp[-2].minor);
  946. yy_destructor(yypParser,6,&yymsp[0].minor);
  947. }
  948. #line 1006 "NCDConfigParser_parse.c"
  949. break;
  950. case 4: /* statement ::= dotted_name ARROW dotted_name ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON */
  951. #line 233 "NCDConfigParser_parse.y"
  952. {
  953. if (!yymsp[-7].minor.yy9 || !yymsp[-5].minor.yy9 || !yymsp[-3].minor.yy27.have) {
  954. goto failD0;
  955. }
  956. if (!NCDStatement_InitReg(&yygotominor.yy23.v, yymsp[-1].minor.yy9, yymsp[-7].minor.yy9, yymsp[-5].minor.yy9, yymsp[-3].minor.yy27.v)) {
  957. goto failD0;
  958. }
  959. yymsp[-3].minor.yy27.have = 0;
  960. yygotominor.yy23.have = 1;
  961. goto doneD;
  962. failD0:
  963. yygotominor.yy23.have = 0;
  964. parser_out->out_of_memory = 1;
  965. doneD:
  966. free(yymsp[-7].minor.yy9);
  967. free(yymsp[-5].minor.yy9);
  968. free_value(yymsp[-3].minor.yy27);
  969. free(yymsp[-1].minor.yy9);
  970. yy_destructor(yypParser,7,&yymsp[-6].minor);
  971. yy_destructor(yypParser,4,&yymsp[-4].minor);
  972. yy_destructor(yypParser,5,&yymsp[-2].minor);
  973. yy_destructor(yypParser,6,&yymsp[0].minor);
  974. }
  975. #line 1036 "NCDConfigParser_parse.c"
  976. break;
  977. case 5: /* statement ::= IF ROUND_OPEN value ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE elif_maybe else_maybe name_maybe SEMICOLON */
  978. #line 256 "NCDConfigParser_parse.y"
  979. {
  980. if (!yymsp[-8].minor.yy27.have || !yymsp[-5].minor.yy29.have || !yymsp[-3].minor.yy4.have) {
  981. goto failE0;
  982. }
  983. NCDIf ifc;
  984. NCDIf_Init(&ifc, yymsp[-8].minor.yy27.v, yymsp[-5].minor.yy29.v);
  985. yymsp[-8].minor.yy27.have = 0;
  986. yymsp[-5].minor.yy29.have = 0;
  987. if (!NCDIfBlock_PrependIf(&yymsp[-3].minor.yy4.v, ifc)) {
  988. NCDIf_Free(&ifc);
  989. goto failE0;
  990. }
  991. if (!NCDStatement_InitIf(&yygotominor.yy23.v, yymsp[-1].minor.yy9, yymsp[-3].minor.yy4.v)) {
  992. goto failE0;
  993. }
  994. yymsp[-3].minor.yy4.have = 0;
  995. if (yymsp[-2].minor.yy29.have) {
  996. NCDStatement_IfAddElse(&yygotominor.yy23.v, yymsp[-2].minor.yy29.v);
  997. yymsp[-2].minor.yy29.have = 0;
  998. }
  999. yygotominor.yy23.have = 1;
  1000. goto doneE;
  1001. failE0:
  1002. yygotominor.yy23.have = 0;
  1003. parser_out->out_of_memory = 1;
  1004. doneE:
  1005. free_value(yymsp[-8].minor.yy27);
  1006. free_block(yymsp[-5].minor.yy29);
  1007. free_ifblock(yymsp[-3].minor.yy4);
  1008. free_block(yymsp[-2].minor.yy29);
  1009. free(yymsp[-1].minor.yy9);
  1010. yy_destructor(yypParser,8,&yymsp[-10].minor);
  1011. yy_destructor(yypParser,4,&yymsp[-9].minor);
  1012. yy_destructor(yypParser,5,&yymsp[-7].minor);
  1013. yy_destructor(yypParser,2,&yymsp[-6].minor);
  1014. yy_destructor(yypParser,3,&yymsp[-4].minor);
  1015. yy_destructor(yypParser,6,&yymsp[0].minor);
  1016. }
  1017. #line 1084 "NCDConfigParser_parse.c"
  1018. break;
  1019. case 6: /* statement ::= FOREACH ROUND_OPEN value AS NAME ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE name_maybe SEMICOLON */
  1020. #line 295 "NCDConfigParser_parse.y"
  1021. {
  1022. if (!yymsp[-8].minor.yy27.have || !yymsp[-6].minor.yy0.str || !yymsp[-3].minor.yy29.have) {
  1023. goto failEA0;
  1024. }
  1025. if (!NCDStatement_InitForeach(&yygotominor.yy23.v, yymsp[-1].minor.yy9, yymsp[-8].minor.yy27.v, yymsp[-6].minor.yy0.str, NULL, yymsp[-3].minor.yy29.v)) {
  1026. goto failEA0;
  1027. }
  1028. yymsp[-8].minor.yy27.have = 0;
  1029. yymsp[-3].minor.yy29.have = 0;
  1030. yygotominor.yy23.have = 1;
  1031. goto doneEA0;
  1032. failEA0:
  1033. yygotominor.yy23.have = 0;
  1034. parser_out->out_of_memory = 1;
  1035. doneEA0:
  1036. free_value(yymsp[-8].minor.yy27);
  1037. free_token(yymsp[-6].minor.yy0);
  1038. free_block(yymsp[-3].minor.yy29);
  1039. free(yymsp[-1].minor.yy9);
  1040. yy_destructor(yypParser,9,&yymsp[-10].minor);
  1041. yy_destructor(yypParser,4,&yymsp[-9].minor);
  1042. yy_destructor(yypParser,10,&yymsp[-7].minor);
  1043. yy_destructor(yypParser,5,&yymsp[-5].minor);
  1044. yy_destructor(yypParser,2,&yymsp[-4].minor);
  1045. yy_destructor(yypParser,3,&yymsp[-2].minor);
  1046. yy_destructor(yypParser,6,&yymsp[0].minor);
  1047. }
  1048. #line 1118 "NCDConfigParser_parse.c"
  1049. break;
  1050. case 7: /* statement ::= FOREACH ROUND_OPEN value AS NAME COLON NAME ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE name_maybe SEMICOLON */
  1051. #line 319 "NCDConfigParser_parse.y"
  1052. {
  1053. if (!yymsp[-10].minor.yy27.have || !yymsp[-8].minor.yy0.str || !yymsp[-6].minor.yy0.str || !yymsp[-3].minor.yy29.have) {
  1054. goto failEB0;
  1055. }
  1056. if (!NCDStatement_InitForeach(&yygotominor.yy23.v, yymsp[-1].minor.yy9, yymsp[-10].minor.yy27.v, yymsp[-8].minor.yy0.str, yymsp[-6].minor.yy0.str, yymsp[-3].minor.yy29.v)) {
  1057. goto failEB0;
  1058. }
  1059. yymsp[-10].minor.yy27.have = 0;
  1060. yymsp[-3].minor.yy29.have = 0;
  1061. yygotominor.yy23.have = 1;
  1062. goto doneEB0;
  1063. failEB0:
  1064. yygotominor.yy23.have = 0;
  1065. parser_out->out_of_memory = 1;
  1066. doneEB0:
  1067. free_value(yymsp[-10].minor.yy27);
  1068. free_token(yymsp[-8].minor.yy0);
  1069. free_token(yymsp[-6].minor.yy0);
  1070. free_block(yymsp[-3].minor.yy29);
  1071. free(yymsp[-1].minor.yy9);
  1072. yy_destructor(yypParser,9,&yymsp[-12].minor);
  1073. yy_destructor(yypParser,4,&yymsp[-11].minor);
  1074. yy_destructor(yypParser,10,&yymsp[-9].minor);
  1075. yy_destructor(yypParser,11,&yymsp[-7].minor);
  1076. yy_destructor(yypParser,5,&yymsp[-5].minor);
  1077. yy_destructor(yypParser,2,&yymsp[-4].minor);
  1078. yy_destructor(yypParser,3,&yymsp[-2].minor);
  1079. yy_destructor(yypParser,6,&yymsp[0].minor);
  1080. }
  1081. #line 1154 "NCDConfigParser_parse.c"
  1082. break;
  1083. case 8: /* elif_maybe ::= */
  1084. #line 344 "NCDConfigParser_parse.y"
  1085. {
  1086. NCDIfBlock_Init(&yygotominor.yy4.v);
  1087. yygotominor.yy4.have = 1;
  1088. }
  1089. #line 1162 "NCDConfigParser_parse.c"
  1090. break;
  1091. case 9: /* elif_maybe ::= elif */
  1092. #line 349 "NCDConfigParser_parse.y"
  1093. {
  1094. yygotominor.yy4 = yymsp[0].minor.yy4;
  1095. }
  1096. #line 1169 "NCDConfigParser_parse.c"
  1097. break;
  1098. case 10: /* elif ::= ELIF ROUND_OPEN value ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE */
  1099. #line 353 "NCDConfigParser_parse.y"
  1100. {
  1101. if (!yymsp[-4].minor.yy27.have || !yymsp[-1].minor.yy29.have) {
  1102. goto failF0;
  1103. }
  1104. NCDIfBlock_Init(&yygotominor.yy4.v);
  1105. NCDIf ifc;
  1106. NCDIf_Init(&ifc, yymsp[-4].minor.yy27.v, yymsp[-1].minor.yy29.v);
  1107. yymsp[-4].minor.yy27.have = 0;
  1108. yymsp[-1].minor.yy29.have = 0;
  1109. if (!NCDIfBlock_PrependIf(&yygotominor.yy4.v, ifc)) {
  1110. goto failF1;
  1111. }
  1112. yygotominor.yy4.have = 1;
  1113. goto doneF0;
  1114. failF1:
  1115. NCDIf_Free(&ifc);
  1116. NCDIfBlock_Free(&yygotominor.yy4.v);
  1117. failF0:
  1118. yygotominor.yy4.have = 0;
  1119. parser_out->out_of_memory = 1;
  1120. doneF0:
  1121. free_value(yymsp[-4].minor.yy27);
  1122. free_block(yymsp[-1].minor.yy29);
  1123. yy_destructor(yypParser,12,&yymsp[-6].minor);
  1124. yy_destructor(yypParser,4,&yymsp[-5].minor);
  1125. yy_destructor(yypParser,5,&yymsp[-3].minor);
  1126. yy_destructor(yypParser,2,&yymsp[-2].minor);
  1127. yy_destructor(yypParser,3,&yymsp[0].minor);
  1128. }
  1129. #line 1207 "NCDConfigParser_parse.c"
  1130. break;
  1131. case 11: /* elif ::= ELIF ROUND_OPEN value ROUND_CLOSE CURLY_OPEN statements CURLY_CLOSE elif */
  1132. #line 383 "NCDConfigParser_parse.y"
  1133. {
  1134. if (!yymsp[-5].minor.yy27.have || !yymsp[-2].minor.yy29.have || !yymsp[0].minor.yy4.have) {
  1135. goto failG0;
  1136. }
  1137. NCDIf ifc;
  1138. NCDIf_Init(&ifc, yymsp[-5].minor.yy27.v, yymsp[-2].minor.yy29.v);
  1139. yymsp[-5].minor.yy27.have = 0;
  1140. yymsp[-2].minor.yy29.have = 0;
  1141. if (!NCDIfBlock_PrependIf(&yymsp[0].minor.yy4.v, ifc)) {
  1142. goto failG1;
  1143. }
  1144. yygotominor.yy4.have = 1;
  1145. yygotominor.yy4.v = yymsp[0].minor.yy4.v;
  1146. yymsp[0].minor.yy4.have = 0;
  1147. goto doneG0;
  1148. failG1:
  1149. NCDIf_Free(&ifc);
  1150. failG0:
  1151. yygotominor.yy4.have = 0;
  1152. parser_out->out_of_memory = 1;
  1153. doneG0:
  1154. free_value(yymsp[-5].minor.yy27);
  1155. free_block(yymsp[-2].minor.yy29);
  1156. free_ifblock(yymsp[0].minor.yy4);
  1157. yy_destructor(yypParser,12,&yymsp[-7].minor);
  1158. yy_destructor(yypParser,4,&yymsp[-6].minor);
  1159. yy_destructor(yypParser,5,&yymsp[-4].minor);
  1160. yy_destructor(yypParser,2,&yymsp[-3].minor);
  1161. yy_destructor(yypParser,3,&yymsp[-1].minor);
  1162. }
  1163. #line 1245 "NCDConfigParser_parse.c"
  1164. break;
  1165. case 12: /* else_maybe ::= */
  1166. #line 413 "NCDConfigParser_parse.y"
  1167. {
  1168. yygotominor.yy29.have = 0;
  1169. }
  1170. #line 1252 "NCDConfigParser_parse.c"
  1171. break;
  1172. case 13: /* else_maybe ::= ELSE CURLY_OPEN statements CURLY_CLOSE */
  1173. #line 417 "NCDConfigParser_parse.y"
  1174. {
  1175. yygotominor.yy29 = yymsp[-1].minor.yy29;
  1176. yy_destructor(yypParser,13,&yymsp[-3].minor);
  1177. yy_destructor(yypParser,2,&yymsp[-2].minor);
  1178. yy_destructor(yypParser,3,&yymsp[0].minor);
  1179. }
  1180. #line 1262 "NCDConfigParser_parse.c"
  1181. break;
  1182. case 14: /* statements ::= statement */
  1183. #line 421 "NCDConfigParser_parse.y"
  1184. {
  1185. if (!yymsp[0].minor.yy23.have) {
  1186. goto failH0;
  1187. }
  1188. NCDBlock_Init(&yygotominor.yy29.v);
  1189. if (!NCDBlock_PrependStatement(&yygotominor.yy29.v, yymsp[0].minor.yy23.v)) {
  1190. goto failH1;
  1191. }
  1192. yymsp[0].minor.yy23.have = 0;
  1193. yygotominor.yy29.have = 1;
  1194. goto doneH;
  1195. failH1:
  1196. NCDBlock_Free(&yygotominor.yy29.v);
  1197. failH0:
  1198. yygotominor.yy29.have = 0;
  1199. parser_out->out_of_memory = 1;
  1200. doneH:
  1201. free_statement(yymsp[0].minor.yy23);
  1202. }
  1203. #line 1289 "NCDConfigParser_parse.c"
  1204. break;
  1205. case 15: /* statements ::= statement statements */
  1206. #line 445 "NCDConfigParser_parse.y"
  1207. {
  1208. if (!yymsp[-1].minor.yy23.have || !yymsp[0].minor.yy29.have) {
  1209. goto failI0;
  1210. }
  1211. if (!NCDBlock_PrependStatement(&yymsp[0].minor.yy29.v, yymsp[-1].minor.yy23.v)) {
  1212. goto failI1;
  1213. }
  1214. yymsp[-1].minor.yy23.have = 0;
  1215. yygotominor.yy29.have = 1;
  1216. yygotominor.yy29.v = yymsp[0].minor.yy29.v;
  1217. yymsp[0].minor.yy29.have = 0;
  1218. goto doneI;
  1219. failI1:
  1220. NCDBlock_Free(&yygotominor.yy29.v);
  1221. failI0:
  1222. yygotominor.yy29.have = 0;
  1223. parser_out->out_of_memory = 1;
  1224. doneI:
  1225. free_statement(yymsp[-1].minor.yy23);
  1226. free_block(yymsp[0].minor.yy29);
  1227. }
  1228. #line 1317 "NCDConfigParser_parse.c"
  1229. break;
  1230. case 16: /* dotted_name ::= NAME */
  1231. case 33: /* name_maybe ::= NAME */ yytestcase(yyruleno==33);
  1232. #line 470 "NCDConfigParser_parse.y"
  1233. {
  1234. ASSERT(yymsp[0].minor.yy0.str)
  1235. yygotominor.yy9 = yymsp[0].minor.yy0.str;
  1236. }
  1237. #line 1327 "NCDConfigParser_parse.c"
  1238. break;
  1239. case 17: /* dotted_name ::= NAME DOT dotted_name */
  1240. #line 476 "NCDConfigParser_parse.y"
  1241. {
  1242. ASSERT(yymsp[-2].minor.yy0.str)
  1243. if (!yymsp[0].minor.yy9) {
  1244. goto failJ0;
  1245. }
  1246. if (!(yygotominor.yy9 = concat_strings(3, yymsp[-2].minor.yy0.str, ".", yymsp[0].minor.yy9))) {
  1247. goto failJ0;
  1248. }
  1249. goto doneJ;
  1250. failJ0:
  1251. yygotominor.yy9 = NULL;
  1252. parser_out->out_of_memory = 1;
  1253. doneJ:
  1254. free_token(yymsp[-2].minor.yy0);
  1255. free(yymsp[0].minor.yy9);
  1256. yy_destructor(yypParser,14,&yymsp[-1].minor);
  1257. }
  1258. #line 1351 "NCDConfigParser_parse.c"
  1259. break;
  1260. case 18: /* statement_args_maybe ::= */
  1261. #line 496 "NCDConfigParser_parse.y"
  1262. {
  1263. yygotominor.yy27.have = 1;
  1264. NCDValue_InitList(&yygotominor.yy27.v);
  1265. }
  1266. #line 1359 "NCDConfigParser_parse.c"
  1267. break;
  1268. case 19: /* statement_args_maybe ::= list_contents */
  1269. case 30: /* value ::= list */ yytestcase(yyruleno==30);
  1270. case 31: /* value ::= map */ yytestcase(yyruleno==31);
  1271. #line 501 "NCDConfigParser_parse.y"
  1272. {
  1273. yygotominor.yy27 = yymsp[0].minor.yy27;
  1274. }
  1275. #line 1368 "NCDConfigParser_parse.c"
  1276. break;
  1277. case 20: /* list_contents ::= value */
  1278. #line 505 "NCDConfigParser_parse.y"
  1279. {
  1280. if (!yymsp[0].minor.yy27.have) {
  1281. goto failL0;
  1282. }
  1283. NCDValue_InitList(&yygotominor.yy27.v);
  1284. if (!NCDValue_ListPrepend(&yygotominor.yy27.v, yymsp[0].minor.yy27.v)) {
  1285. goto failL1;
  1286. }
  1287. yymsp[0].minor.yy27.have = 0;
  1288. yygotominor.yy27.have = 1;
  1289. goto doneL;
  1290. failL1:
  1291. NCDValue_Free(&yygotominor.yy27.v);
  1292. failL0:
  1293. yygotominor.yy27.have = 0;
  1294. parser_out->out_of_memory = 1;
  1295. doneL:
  1296. free_value(yymsp[0].minor.yy27);
  1297. }
  1298. #line 1395 "NCDConfigParser_parse.c"
  1299. break;
  1300. case 21: /* list_contents ::= value COMMA list_contents */
  1301. #line 529 "NCDConfigParser_parse.y"
  1302. {
  1303. if (!yymsp[-2].minor.yy27.have || !yymsp[0].minor.yy27.have) {
  1304. goto failM0;
  1305. }
  1306. if (!NCDValue_ListPrepend(&yymsp[0].minor.yy27.v, yymsp[-2].minor.yy27.v)) {
  1307. goto failM0;
  1308. }
  1309. yymsp[-2].minor.yy27.have = 0;
  1310. yygotominor.yy27.have = 1;
  1311. yygotominor.yy27.v = yymsp[0].minor.yy27.v;
  1312. yymsp[0].minor.yy27.have = 0;
  1313. goto doneM;
  1314. failM0:
  1315. yygotominor.yy27.have = 0;
  1316. parser_out->out_of_memory = 1;
  1317. doneM:
  1318. free_value(yymsp[-2].minor.yy27);
  1319. free_value(yymsp[0].minor.yy27);
  1320. yy_destructor(yypParser,15,&yymsp[-1].minor);
  1321. }
  1322. #line 1422 "NCDConfigParser_parse.c"
  1323. break;
  1324. case 22: /* list ::= CURLY_OPEN CURLY_CLOSE */
  1325. #line 552 "NCDConfigParser_parse.y"
  1326. {
  1327. yygotominor.yy27.have = 1;
  1328. NCDValue_InitList(&yygotominor.yy27.v);
  1329. yy_destructor(yypParser,2,&yymsp[-1].minor);
  1330. yy_destructor(yypParser,3,&yymsp[0].minor);
  1331. }
  1332. #line 1432 "NCDConfigParser_parse.c"
  1333. break;
  1334. case 23: /* list ::= CURLY_OPEN list_contents CURLY_CLOSE */
  1335. #line 557 "NCDConfigParser_parse.y"
  1336. {
  1337. yygotominor.yy27 = yymsp[-1].minor.yy27;
  1338. yy_destructor(yypParser,2,&yymsp[-2].minor);
  1339. yy_destructor(yypParser,3,&yymsp[0].minor);
  1340. }
  1341. #line 1441 "NCDConfigParser_parse.c"
  1342. break;
  1343. case 24: /* map_contents ::= value COLON value */
  1344. #line 561 "NCDConfigParser_parse.y"
  1345. {
  1346. if (!yymsp[-2].minor.yy27.have || !yymsp[0].minor.yy27.have) {
  1347. goto failS0;
  1348. }
  1349. NCDValue_InitMap(&yygotominor.yy27.v);
  1350. if (!NCDValue_MapInsert(&yygotominor.yy27.v, yymsp[-2].minor.yy27.v, yymsp[0].minor.yy27.v)) {
  1351. goto failS1;
  1352. }
  1353. yymsp[-2].minor.yy27.have = 0;
  1354. yymsp[0].minor.yy27.have = 0;
  1355. yygotominor.yy27.have = 1;
  1356. goto doneS;
  1357. failS1:
  1358. NCDValue_Free(&yygotominor.yy27.v);
  1359. failS0:
  1360. yygotominor.yy27.have = 0;
  1361. parser_out->out_of_memory = 1;
  1362. doneS:
  1363. free_value(yymsp[-2].minor.yy27);
  1364. free_value(yymsp[0].minor.yy27);
  1365. yy_destructor(yypParser,11,&yymsp[-1].minor);
  1366. }
  1367. #line 1471 "NCDConfigParser_parse.c"
  1368. break;
  1369. case 25: /* map_contents ::= value COLON value COMMA map_contents */
  1370. #line 587 "NCDConfigParser_parse.y"
  1371. {
  1372. if (!yymsp[-4].minor.yy27.have || !yymsp[-2].minor.yy27.have || !yymsp[0].minor.yy27.have) {
  1373. goto failT0;
  1374. }
  1375. if (NCDValue_MapFindKey(&yymsp[0].minor.yy27.v, &yymsp[-4].minor.yy27.v)) {
  1376. BLog(BLOG_ERROR, "duplicate key in map");
  1377. yygotominor.yy27.have = 0;
  1378. parser_out->syntax_error = 1;
  1379. goto doneT;
  1380. }
  1381. if (!NCDValue_MapInsert(&yymsp[0].minor.yy27.v, yymsp[-4].minor.yy27.v, yymsp[-2].minor.yy27.v)) {
  1382. goto failT0;
  1383. }
  1384. yymsp[-4].minor.yy27.have = 0;
  1385. yymsp[-2].minor.yy27.have = 0;
  1386. yygotominor.yy27.have = 1;
  1387. yygotominor.yy27.v = yymsp[0].minor.yy27.v;
  1388. yymsp[0].minor.yy27.have = 0;
  1389. goto doneT;
  1390. failT0:
  1391. yygotominor.yy27.have = 0;
  1392. parser_out->out_of_memory = 1;
  1393. doneT:
  1394. free_value(yymsp[-4].minor.yy27);
  1395. free_value(yymsp[-2].minor.yy27);
  1396. free_value(yymsp[0].minor.yy27);
  1397. yy_destructor(yypParser,11,&yymsp[-3].minor);
  1398. yy_destructor(yypParser,15,&yymsp[-1].minor);
  1399. }
  1400. #line 1508 "NCDConfigParser_parse.c"
  1401. break;
  1402. case 26: /* map ::= BRACKET_OPEN BRACKET_CLOSE */
  1403. #line 619 "NCDConfigParser_parse.y"
  1404. {
  1405. yygotominor.yy27.have = 1;
  1406. NCDValue_InitMap(&yygotominor.yy27.v);
  1407. yy_destructor(yypParser,16,&yymsp[-1].minor);
  1408. yy_destructor(yypParser,17,&yymsp[0].minor);
  1409. }
  1410. #line 1518 "NCDConfigParser_parse.c"
  1411. break;
  1412. case 27: /* map ::= BRACKET_OPEN map_contents BRACKET_CLOSE */
  1413. #line 624 "NCDConfigParser_parse.y"
  1414. {
  1415. yygotominor.yy27 = yymsp[-1].minor.yy27;
  1416. yy_destructor(yypParser,16,&yymsp[-2].minor);
  1417. yy_destructor(yypParser,17,&yymsp[0].minor);
  1418. }
  1419. #line 1527 "NCDConfigParser_parse.c"
  1420. break;
  1421. case 28: /* value ::= STRING */
  1422. #line 628 "NCDConfigParser_parse.y"
  1423. {
  1424. ASSERT(yymsp[0].minor.yy0.str)
  1425. if (!NCDValue_InitStringBin(&yygotominor.yy27.v, (uint8_t *)yymsp[0].minor.yy0.str, yymsp[0].minor.yy0.len)) {
  1426. goto failU0;
  1427. }
  1428. yygotominor.yy27.have = 1;
  1429. goto doneU;
  1430. failU0:
  1431. yygotominor.yy27.have = 0;
  1432. parser_out->out_of_memory = 1;
  1433. doneU:
  1434. free_token(yymsp[0].minor.yy0);
  1435. }
  1436. #line 1547 "NCDConfigParser_parse.c"
  1437. break;
  1438. case 29: /* value ::= dotted_name */
  1439. #line 645 "NCDConfigParser_parse.y"
  1440. {
  1441. if (!yymsp[0].minor.yy9) {
  1442. goto failV0;
  1443. }
  1444. if (!NCDValue_InitVar(&yygotominor.yy27.v, yymsp[0].minor.yy9)) {
  1445. goto failV0;
  1446. }
  1447. yygotominor.yy27.have = 1;
  1448. goto doneV;
  1449. failV0:
  1450. yygotominor.yy27.have = 0;
  1451. parser_out->out_of_memory = 1;
  1452. doneV:
  1453. free(yymsp[0].minor.yy9);
  1454. }
  1455. #line 1569 "NCDConfigParser_parse.c"
  1456. break;
  1457. case 32: /* name_maybe ::= */
  1458. #line 672 "NCDConfigParser_parse.y"
  1459. {
  1460. yygotominor.yy9 = NULL;
  1461. }
  1462. #line 1576 "NCDConfigParser_parse.c"
  1463. break;
  1464. case 34: /* process_or_template ::= PROCESS */
  1465. #line 682 "NCDConfigParser_parse.y"
  1466. {
  1467. yygotominor.yy8 = 0;
  1468. yy_destructor(yypParser,19,&yymsp[0].minor);
  1469. }
  1470. #line 1584 "NCDConfigParser_parse.c"
  1471. break;
  1472. case 35: /* process_or_template ::= TEMPLATE */
  1473. #line 686 "NCDConfigParser_parse.y"
  1474. {
  1475. yygotominor.yy8 = 1;
  1476. yy_destructor(yypParser,20,&yymsp[0].minor);
  1477. }
  1478. #line 1592 "NCDConfigParser_parse.c"
  1479. break;
  1480. default:
  1481. break;
  1482. };
  1483. yygoto = yyRuleInfo[yyruleno].lhs;
  1484. yysize = yyRuleInfo[yyruleno].nrhs;
  1485. yypParser->yyidx -= yysize;
  1486. yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  1487. if( yyact < YYNSTATE ){
  1488. #ifdef NDEBUG
  1489. /* If we are not debugging and the reduce action popped at least
  1490. ** one element off the stack, then we can push the new element back
  1491. ** onto the stack here, and skip the stack overflow test in yy_shift().
  1492. ** That gives a significant speed improvement. */
  1493. if( yysize ){
  1494. yypParser->yyidx++;
  1495. yymsp -= yysize-1;
  1496. yymsp->stateno = (YYACTIONTYPE)yyact;
  1497. yymsp->major = (YYCODETYPE)yygoto;
  1498. yymsp->minor = yygotominor;
  1499. }else
  1500. #endif
  1501. {
  1502. yy_shift(yypParser,yyact,yygoto,&yygotominor);
  1503. }
  1504. }else{
  1505. assert( yyact == YYNSTATE + YYNRULE + 1 );
  1506. yy_accept(yypParser);
  1507. }
  1508. }
  1509. /*
  1510. ** The following code executes when the parse fails
  1511. */
  1512. #ifndef YYNOERRORRECOVERY
  1513. static void yy_parse_failed(
  1514. yyParser *yypParser /* The parser */
  1515. ){
  1516. ParseARG_FETCH;
  1517. #ifndef NDEBUG
  1518. if( yyTraceFILE ){
  1519. fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
  1520. }
  1521. #endif
  1522. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  1523. /* Here code is inserted which will be executed whenever the
  1524. ** parser fails */
  1525. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  1526. }
  1527. #endif /* YYNOERRORRECOVERY */
  1528. /*
  1529. ** The following code executes when a syntax error first occurs.
  1530. */
  1531. static void yy_syntax_error(
  1532. yyParser *yypParser, /* The parser */
  1533. int yymajor, /* The major type of the error token */
  1534. YYMINORTYPE yyminor /* The minor type of the error token */
  1535. ){
  1536. ParseARG_FETCH;
  1537. #define TOKEN (yyminor.yy0)
  1538. #line 125 "NCDConfigParser_parse.y"
  1539. parser_out->syntax_error = 1;
  1540. #line 1657 "NCDConfigParser_parse.c"
  1541. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  1542. }
  1543. /*
  1544. ** The following is executed when the parser accepts
  1545. */
  1546. static void yy_accept(
  1547. yyParser *yypParser /* The parser */
  1548. ){
  1549. ParseARG_FETCH;
  1550. #ifndef NDEBUG
  1551. if( yyTraceFILE ){
  1552. fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
  1553. }
  1554. #endif
  1555. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  1556. /* Here code is inserted which will be executed whenever the
  1557. ** parser accepts */
  1558. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  1559. }
  1560. /* The main parser program.
  1561. ** The first argument is a pointer to a structure obtained from
  1562. ** "ParseAlloc" which describes the current state of the parser.
  1563. ** The second argument is the major token number. The third is
  1564. ** the minor token. The fourth optional argument is whatever the
  1565. ** user wants (and specified in the grammar) and is available for
  1566. ** use by the action routines.
  1567. **
  1568. ** Inputs:
  1569. ** <ul>
  1570. ** <li> A pointer to the parser (an opaque structure.)
  1571. ** <li> The major token number.
  1572. ** <li> The minor token number.
  1573. ** <li> An option argument of a grammar-specified type.
  1574. ** </ul>
  1575. **
  1576. ** Outputs:
  1577. ** None.
  1578. */
  1579. void Parse(
  1580. void *yyp, /* The parser */
  1581. int yymajor, /* The major token code number */
  1582. ParseTOKENTYPE yyminor /* The value for the token */
  1583. ParseARG_PDECL /* Optional %extra_argument parameter */
  1584. ){
  1585. YYMINORTYPE yyminorunion;
  1586. int yyact; /* The parser action. */
  1587. int yyendofinput; /* True if we are at the end of input */
  1588. #ifdef YYERRORSYMBOL
  1589. int yyerrorhit = 0; /* True if yymajor has invoked an error */
  1590. #endif
  1591. yyParser *yypParser; /* The parser */
  1592. /* (re)initialize the parser, if necessary */
  1593. yypParser = (yyParser*)yyp;
  1594. if( yypParser->yyidx<0 ){
  1595. #if YYSTACKDEPTH<=0
  1596. if( yypParser->yystksz <=0 ){
  1597. /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/
  1598. yyminorunion = yyzerominor;
  1599. yyStackOverflow(yypParser, &yyminorunion);
  1600. return;
  1601. }
  1602. #endif
  1603. yypParser->yyidx = 0;
  1604. yypParser->yyerrcnt = -1;
  1605. yypParser->yystack[0].stateno = 0;
  1606. yypParser->yystack[0].major = 0;
  1607. }
  1608. yyminorunion.yy0 = yyminor;
  1609. yyendofinput = (yymajor==0);
  1610. ParseARG_STORE;
  1611. #ifndef NDEBUG
  1612. if( yyTraceFILE ){
  1613. fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  1614. }
  1615. #endif
  1616. do{
  1617. yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
  1618. if( yyact<YYNSTATE ){
  1619. assert( !yyendofinput ); /* Impossible to shift the $ token */
  1620. yy_shift(yypParser,yyact,yymajor,&yyminorunion);
  1621. yypParser->yyerrcnt--;
  1622. yymajor = YYNOCODE;
  1623. }else if( yyact < YYNSTATE + YYNRULE ){
  1624. yy_reduce(yypParser,yyact-YYNSTATE);
  1625. }else{
  1626. assert( yyact == YY_ERROR_ACTION );
  1627. #ifdef YYERRORSYMBOL
  1628. int yymx;
  1629. #endif
  1630. #ifndef NDEBUG
  1631. if( yyTraceFILE ){
  1632. fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
  1633. }
  1634. #endif
  1635. #ifdef YYERRORSYMBOL
  1636. /* A syntax error has occurred.
  1637. ** The response to an error depends upon whether or not the
  1638. ** grammar defines an error token "ERROR".
  1639. **
  1640. ** This is what we do if the grammar does define ERROR:
  1641. **
  1642. ** * Call the %syntax_error function.
  1643. **
  1644. ** * Begin popping the stack until we enter a state where
  1645. ** it is legal to shift the error symbol, then shift
  1646. ** the error symbol.
  1647. **
  1648. ** * Set the error count to three.
  1649. **
  1650. ** * Begin accepting and shifting new tokens. No new error
  1651. ** processing will occur until three tokens have been
  1652. ** shifted successfully.
  1653. **
  1654. */
  1655. if( yypParser->yyerrcnt<0 ){
  1656. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1657. }
  1658. yymx = yypParser->yystack[yypParser->yyidx].major;
  1659. if( yymx==YYERRORSYMBOL || yyerrorhit ){
  1660. #ifndef NDEBUG
  1661. if( yyTraceFILE ){
  1662. fprintf(yyTraceFILE,"%sDiscard input token %s\n",
  1663. yyTracePrompt,yyTokenName[yymajor]);
  1664. }
  1665. #endif
  1666. yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
  1667. yymajor = YYNOCODE;
  1668. }else{
  1669. while(
  1670. yypParser->yyidx >= 0 &&
  1671. yymx != YYERRORSYMBOL &&
  1672. (yyact = yy_find_reduce_action(
  1673. yypParser->yystack[yypParser->yyidx].stateno,
  1674. YYERRORSYMBOL)) >= YYNSTATE
  1675. ){
  1676. yy_pop_parser_stack(yypParser);
  1677. }
  1678. if( yypParser->yyidx < 0 || yymajor==0 ){
  1679. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1680. yy_parse_failed(yypParser);
  1681. yymajor = YYNOCODE;
  1682. }else if( yymx!=YYERRORSYMBOL ){
  1683. YYMINORTYPE u2;
  1684. u2.YYERRSYMDT = 0;
  1685. yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
  1686. }
  1687. }
  1688. yypParser->yyerrcnt = 3;
  1689. yyerrorhit = 1;
  1690. #elif defined(YYNOERRORRECOVERY)
  1691. /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
  1692. ** do any kind of error recovery. Instead, simply invoke the syntax
  1693. ** error routine and continue going as if nothing had happened.
  1694. **
  1695. ** Applications can set this macro (for example inside %include) if
  1696. ** they intend to abandon the parse upon the first syntax error seen.
  1697. */
  1698. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1699. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1700. yymajor = YYNOCODE;
  1701. #else /* YYERRORSYMBOL is not defined */
  1702. /* This is what we do if the grammar does not define ERROR:
  1703. **
  1704. ** * Report an error message, and throw away the input token.
  1705. **
  1706. ** * If the input token is $, then fail the parse.
  1707. **
  1708. ** As before, subsequent error messages are suppressed until
  1709. ** three input tokens have been successfully shifted.
  1710. */
  1711. if( yypParser->yyerrcnt<=0 ){
  1712. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1713. }
  1714. yypParser->yyerrcnt = 3;
  1715. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1716. if( yyendofinput ){
  1717. yy_parse_failed(yypParser);
  1718. }
  1719. yymajor = YYNOCODE;
  1720. #endif
  1721. }
  1722. }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
  1723. return;
  1724. }