NCDConfigParser_parse.c 54 KB

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