NCDConfigParser_parse.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260
  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 <ncd/NCDConfig.h>
  12. struct parser_out {
  13. int out_of_memory;
  14. int syntax_error;
  15. struct NCDConfig_processes *ast;
  16. };
  17. #line 23 "NCDConfigParser_parse.c"
  18. /* Next is all token values, in a form suitable for use by makeheaders.
  19. ** This section will be null unless lemon is run with the -m switch.
  20. */
  21. /*
  22. ** These constants (all generated automatically by the parser generator)
  23. ** specify the various kinds of tokens (terminals) that the parser
  24. ** understands.
  25. **
  26. ** Each symbol here is a terminal symbol in the grammar.
  27. */
  28. /* Make sure the INTERFACE macro is defined.
  29. */
  30. #ifndef INTERFACE
  31. # define INTERFACE 1
  32. #endif
  33. /* The next thing included is series of defines which control
  34. ** various aspects of the generated parser.
  35. ** YYCODETYPE is the data type used for storing terminal
  36. ** and nonterminal numbers. "unsigned char" is
  37. ** used if there are fewer than 250 terminals
  38. ** and nonterminals. "int" is used otherwise.
  39. ** YYNOCODE is a number of type YYCODETYPE which corresponds
  40. ** to no legal terminal or nonterminal number. This
  41. ** number is used to fill in empty slots of the hash
  42. ** table.
  43. ** YYFALLBACK If defined, this indicates that one or more tokens
  44. ** have fall-back values which should be used if the
  45. ** original value of the token will not parse.
  46. ** YYACTIONTYPE is the data type used for storing terminal
  47. ** and nonterminal numbers. "unsigned char" is
  48. ** used if there are fewer than 250 rules and
  49. ** states combined. "int" is used otherwise.
  50. ** ParseTOKENTYPE is the data type used for minor tokens given
  51. ** directly to the parser from the tokenizer.
  52. ** YYMINORTYPE is the data type used for all minor tokens.
  53. ** This is typically a union of many types, one of
  54. ** which is ParseTOKENTYPE. The entry in the union
  55. ** for base tokens is called "yy0".
  56. ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
  57. ** zero the stack is dynamically sized using realloc()
  58. ** ParseARG_SDECL A static variable declaration for the %extra_argument
  59. ** ParseARG_PDECL A parameter declaration for the %extra_argument
  60. ** ParseARG_STORE Code to store %extra_argument into yypParser
  61. ** ParseARG_FETCH Code to extract %extra_argument from yypParser
  62. ** YYNSTATE the combined number of states.
  63. ** YYNRULE the number of rules in the grammar
  64. ** YYERRORSYMBOL is the code number of the error symbol. If not
  65. ** defined, then do no error processing.
  66. */
  67. #define YYCODETYPE unsigned char
  68. #define YYNOCODE 24
  69. #define YYACTIONTYPE unsigned char
  70. #define ParseTOKENTYPE void *
  71. typedef union {
  72. int yyinit;
  73. ParseTOKENTYPE yy0;
  74. int yy6;
  75. struct NCDConfig_strings * yy10;
  76. struct NCDConfig_list * yy24;
  77. struct NCDConfig_statements * yy34;
  78. struct NCDConfig_processes * yy41;
  79. char * yy45;
  80. } YYMINORTYPE;
  81. #ifndef YYSTACKDEPTH
  82. #define YYSTACKDEPTH 0
  83. #endif
  84. #define ParseARG_SDECL struct parser_out *parser_out;
  85. #define ParseARG_PDECL ,struct parser_out *parser_out
  86. #define ParseARG_FETCH struct parser_out *parser_out = yypParser->parser_out
  87. #define ParseARG_STORE yypParser->parser_out = parser_out
  88. #define YYNSTATE 43
  89. #define YYNRULE 23
  90. #define YY_NO_ACTION (YYNSTATE+YYNRULE+2)
  91. #define YY_ACCEPT_ACTION (YYNSTATE+YYNRULE+1)
  92. #define YY_ERROR_ACTION (YYNSTATE+YYNRULE)
  93. /* The yyzerominor constant is used to initialize instances of
  94. ** YYMINORTYPE objects to zero. */
  95. static const YYMINORTYPE yyzerominor = { 0 };
  96. /* Define the yytestcase() macro to be a no-op if is not already defined
  97. ** otherwise.
  98. **
  99. ** Applications can choose to define yytestcase() in the %include section
  100. ** to a macro that can assist in verifying code coverage. For production
  101. ** code the yytestcase() macro should be turned off. But it is useful
  102. ** for testing.
  103. */
  104. #ifndef yytestcase
  105. # define yytestcase(X)
  106. #endif
  107. /* Next are the tables used to determine what action to take based on the
  108. ** current state and lookahead token. These tables are used to implement
  109. ** functions that take a state number and lookahead value and return an
  110. ** action integer.
  111. **
  112. ** Suppose the action integer is N. Then the action is determined as
  113. ** follows
  114. **
  115. ** 0 <= N < YYNSTATE Shift N. That is, push the lookahead
  116. ** token onto the stack and goto state N.
  117. **
  118. ** YYNSTATE <= N < YYNSTATE+YYNRULE Reduce by rule N-YYNSTATE.
  119. **
  120. ** N == YYNSTATE+YYNRULE A syntax error has occurred.
  121. **
  122. ** N == YYNSTATE+YYNRULE+1 The parser accepts its input.
  123. **
  124. ** N == YYNSTATE+YYNRULE+2 No such action. Denotes unused
  125. ** slots in the yy_action[] table.
  126. **
  127. ** The action table is constructed as a single large table named yy_action[].
  128. ** Given state S and lookahead X, the action is computed as
  129. **
  130. ** yy_action[ yy_shift_ofst[S] + X ]
  131. **
  132. ** If the index value yy_shift_ofst[S]+X is out of range or if the value
  133. ** yy_lookahead[yy_shift_ofst[S]+X] is not equal to X or if yy_shift_ofst[S]
  134. ** is equal to YY_SHIFT_USE_DFLT, it means that the action is not in the table
  135. ** and that yy_default[S] should be used instead.
  136. **
  137. ** The formula above is for computing the action when the lookahead is
  138. ** a terminal symbol. If the lookahead is a non-terminal (as occurs after
  139. ** a reduce action) then the yy_reduce_ofst[] array is used in place of
  140. ** the yy_shift_ofst[] array and YY_REDUCE_USE_DFLT is used in place of
  141. ** YY_SHIFT_USE_DFLT.
  142. **
  143. ** The following are the tables generated in this section:
  144. **
  145. ** yy_action[] A single table containing all actions.
  146. ** yy_lookahead[] A table containing the lookahead for each entry in
  147. ** yy_action. Used to detect hash collisions.
  148. ** yy_shift_ofst[] For each state, the offset into yy_action for
  149. ** shifting terminals.
  150. ** yy_reduce_ofst[] For each state, the offset into yy_action for
  151. ** shifting non-terminals after a reduce.
  152. ** yy_default[] Default action for each state.
  153. */
  154. static const YYACTIONTYPE yy_action[] = {
  155. /* 0 */ 24, 20, 36, 25, 24, 28, 36, 25, 22, 3,
  156. /* 10 */ 38, 16, 22, 3, 31, 32, 23, 34, 17, 67,
  157. /* 20 */ 23, 24, 22, 26, 25, 24, 35, 41, 25, 24,
  158. /* 30 */ 30, 40, 25, 24, 21, 37, 25, 17, 27, 19,
  159. /* 40 */ 15, 33, 15, 42, 15, 1, 43, 29, 13, 18,
  160. /* 50 */ 7, 8, 12, 4, 68, 11, 68, 9, 2, 39,
  161. /* 60 */ 68, 68, 5, 6, 14, 68, 10,
  162. };
  163. static const YYCODETYPE yy_lookahead[] = {
  164. /* 0 */ 16, 17, 18, 19, 16, 17, 18, 19, 1, 2,
  165. /* 10 */ 3, 14, 1, 2, 11, 12, 9, 16, 21, 22,
  166. /* 20 */ 9, 16, 1, 18, 19, 16, 1, 18, 19, 16,
  167. /* 30 */ 14, 18, 19, 16, 20, 18, 19, 21, 16, 15,
  168. /* 40 */ 16, 15, 16, 15, 16, 4, 0, 20, 7, 1,
  169. /* 50 */ 3, 2, 8, 10, 23, 5, 23, 6, 4, 3,
  170. /* 60 */ 23, 23, 10, 10, 5, 23, 6,
  171. };
  172. #define YY_SHIFT_USE_DFLT (-1)
  173. #define YY_SHIFT_MAX 29
  174. static const signed char yy_shift_ofst[] = {
  175. /* 0 */ 3, 11, 11, 7, 11, 11, 11, 3, 21, 21,
  176. /* 10 */ 21, 25, 21, 21, 25, 41, 46, 48, 49, 47,
  177. /* 20 */ 50, 51, 44, 43, 52, 53, 56, 54, 59, 60,
  178. };
  179. #define YY_REDUCE_USE_DFLT (-17)
  180. #define YY_REDUCE_MAX 14
  181. static const signed char yy_reduce_ofst[] = {
  182. /* 0 */ -3, -16, -12, 5, 9, 13, 17, 16, 24, 26,
  183. /* 10 */ 28, 14, 1, 22, 27,
  184. };
  185. static const YYACTIONTYPE yy_default[] = {
  186. /* 0 */ 66, 52, 52, 66, 66, 66, 66, 44, 66, 46,
  187. /* 10 */ 48, 62, 66, 66, 62, 66, 66, 66, 66, 66,
  188. /* 20 */ 66, 66, 50, 54, 55, 56, 66, 66, 66, 66,
  189. /* 30 */ 45, 64, 65, 47, 51, 63, 53, 59, 60, 61,
  190. /* 40 */ 58, 57, 49,
  191. };
  192. #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
  193. /* The next table maps tokens into fallback tokens. If a construct
  194. ** like the following:
  195. **
  196. ** %fallback ID X Y Z.
  197. **
  198. ** appears in the grammar, then ID becomes a fallback token for X, Y,
  199. ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
  200. ** but it does not parse, the type of the token is changed to ID and
  201. ** the parse is retried before an error is thrown.
  202. */
  203. #ifdef YYFALLBACK
  204. static const YYCODETYPE yyFallback[] = {
  205. };
  206. #endif /* YYFALLBACK */
  207. /* The following structure represents a single element of the
  208. ** parser's stack. Information stored includes:
  209. **
  210. ** + The state number for the parser at this level of the stack.
  211. **
  212. ** + The value of the token stored at this level of the stack.
  213. ** (In other words, the "major" token.)
  214. **
  215. ** + The semantic value stored at this level of the stack. This is
  216. ** the information used by the action routines in the grammar.
  217. ** It is sometimes called the "minor" token.
  218. */
  219. struct yyStackEntry {
  220. YYACTIONTYPE stateno; /* The state-number */
  221. YYCODETYPE major; /* The major token value. This is the code
  222. ** number for the token at this stack level */
  223. YYMINORTYPE minor; /* The user-supplied minor token value. This
  224. ** is the value of the token */
  225. };
  226. typedef struct yyStackEntry yyStackEntry;
  227. /* The state of the parser is completely contained in an instance of
  228. ** the following structure */
  229. struct yyParser {
  230. int yyidx; /* Index of top element in stack */
  231. #ifdef YYTRACKMAXSTACKDEPTH
  232. int yyidxMax; /* Maximum value of yyidx */
  233. #endif
  234. int yyerrcnt; /* Shifts left before out of the error */
  235. ParseARG_SDECL /* A place to hold %extra_argument */
  236. #if YYSTACKDEPTH<=0
  237. int yystksz; /* Current side of the stack */
  238. yyStackEntry *yystack; /* The parser's stack */
  239. #else
  240. yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
  241. #endif
  242. };
  243. typedef struct yyParser yyParser;
  244. #ifndef NDEBUG
  245. #include <stdio.h>
  246. static FILE *yyTraceFILE = 0;
  247. static char *yyTracePrompt = 0;
  248. #endif /* NDEBUG */
  249. #ifndef NDEBUG
  250. /*
  251. ** Turn parser tracing on by giving a stream to which to write the trace
  252. ** and a prompt to preface each trace message. Tracing is turned off
  253. ** by making either argument NULL
  254. **
  255. ** Inputs:
  256. ** <ul>
  257. ** <li> A FILE* to which trace output should be written.
  258. ** If NULL, then tracing is turned off.
  259. ** <li> A prefix string written at the beginning of every
  260. ** line of trace output. If NULL, then tracing is
  261. ** turned off.
  262. ** </ul>
  263. **
  264. ** Outputs:
  265. ** None.
  266. */
  267. void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
  268. yyTraceFILE = TraceFILE;
  269. yyTracePrompt = zTracePrompt;
  270. if( yyTraceFILE==0 ) yyTracePrompt = 0;
  271. else if( yyTracePrompt==0 ) yyTraceFILE = 0;
  272. }
  273. #endif /* NDEBUG */
  274. #ifndef NDEBUG
  275. /* For tracing shifts, the names of all terminals and nonterminals
  276. ** are required. The following table supplies these names */
  277. static const char *const yyTokenName[] = {
  278. "$", "NAME", "CURLY_OPEN", "CURLY_CLOSE",
  279. "ROUND_OPEN", "ROUND_CLOSE", "SEMICOLON", "ARROW",
  280. "DOT", "STRING", "COMMA", "PROCESS",
  281. "TEMPLATE", "error", "processes", "statements",
  282. "statement_names", "statement_args_maybe", "list_contents", "list",
  283. "name_maybe", "process_or_template", "input",
  284. };
  285. #endif /* NDEBUG */
  286. #ifndef NDEBUG
  287. /* For tracing reduce actions, the names of all rules are required.
  288. */
  289. static const char *const yyRuleName[] = {
  290. /* 0 */ "input ::= processes",
  291. /* 1 */ "processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE",
  292. /* 2 */ "processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE processes",
  293. /* 3 */ "statements ::= statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON",
  294. /* 4 */ "statements ::= statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON statements",
  295. /* 5 */ "statements ::= statement_names ARROW statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON",
  296. /* 6 */ "statements ::= statement_names ARROW statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON statements",
  297. /* 7 */ "statement_names ::= NAME",
  298. /* 8 */ "statement_names ::= NAME DOT statement_names",
  299. /* 9 */ "statement_args_maybe ::=",
  300. /* 10 */ "statement_args_maybe ::= list_contents",
  301. /* 11 */ "list_contents ::= STRING",
  302. /* 12 */ "list_contents ::= statement_names",
  303. /* 13 */ "list_contents ::= list",
  304. /* 14 */ "list_contents ::= STRING COMMA list_contents",
  305. /* 15 */ "list_contents ::= statement_names COMMA list_contents",
  306. /* 16 */ "list_contents ::= list COMMA list_contents",
  307. /* 17 */ "list ::= CURLY_OPEN CURLY_CLOSE",
  308. /* 18 */ "list ::= CURLY_OPEN list_contents CURLY_CLOSE",
  309. /* 19 */ "name_maybe ::=",
  310. /* 20 */ "name_maybe ::= NAME",
  311. /* 21 */ "process_or_template ::= PROCESS",
  312. /* 22 */ "process_or_template ::= TEMPLATE",
  313. };
  314. #endif /* NDEBUG */
  315. #if YYSTACKDEPTH<=0
  316. /*
  317. ** Try to increase the size of the parser stack.
  318. */
  319. static void yyGrowStack(yyParser *p){
  320. int newSize;
  321. yyStackEntry *pNew;
  322. newSize = p->yystksz*2 + 100;
  323. pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
  324. if( pNew ){
  325. p->yystack = pNew;
  326. p->yystksz = newSize;
  327. #ifndef NDEBUG
  328. if( yyTraceFILE ){
  329. fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
  330. yyTracePrompt, p->yystksz);
  331. }
  332. #endif
  333. }
  334. }
  335. #endif
  336. /*
  337. ** This function allocates a new parser.
  338. ** The only argument is a pointer to a function which works like
  339. ** malloc.
  340. **
  341. ** Inputs:
  342. ** A pointer to the function used to allocate memory.
  343. **
  344. ** Outputs:
  345. ** A pointer to a parser. This pointer is used in subsequent calls
  346. ** to Parse and ParseFree.
  347. */
  348. void *ParseAlloc(void *(*mallocProc)(size_t)){
  349. yyParser *pParser;
  350. pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
  351. if( pParser ){
  352. pParser->yyidx = -1;
  353. #ifdef YYTRACKMAXSTACKDEPTH
  354. pParser->yyidxMax = 0;
  355. #endif
  356. #if YYSTACKDEPTH<=0
  357. pParser->yystack = NULL;
  358. pParser->yystksz = 0;
  359. yyGrowStack(pParser);
  360. #endif
  361. }
  362. return pParser;
  363. }
  364. /* The following function deletes the value associated with a
  365. ** symbol. The symbol can be either a terminal or nonterminal.
  366. ** "yymajor" is the symbol code, and "yypminor" is a pointer to
  367. ** the value.
  368. */
  369. static void yy_destructor(
  370. yyParser *yypParser, /* The parser */
  371. YYCODETYPE yymajor, /* Type code for object to destroy */
  372. YYMINORTYPE *yypminor /* The object to be destroyed */
  373. ){
  374. ParseARG_FETCH;
  375. switch( yymajor ){
  376. /* Here is inserted the actions which take place when a
  377. ** terminal or non-terminal is destroyed. This can happen
  378. ** when the symbol is popped from the stack during a
  379. ** reduce or during error processing or when a parser is
  380. ** being destroyed before it is finished parsing.
  381. **
  382. ** Note: during a reduce, the only symbols destroyed are those
  383. ** which appear on the RHS of the rule, but which are not used
  384. ** inside the C code.
  385. */
  386. /* TERMINAL Destructor */
  387. case 1: /* NAME */
  388. case 2: /* CURLY_OPEN */
  389. case 3: /* CURLY_CLOSE */
  390. case 4: /* ROUND_OPEN */
  391. case 5: /* ROUND_CLOSE */
  392. case 6: /* SEMICOLON */
  393. case 7: /* ARROW */
  394. case 8: /* DOT */
  395. case 9: /* STRING */
  396. case 10: /* COMMA */
  397. case 11: /* PROCESS */
  398. case 12: /* TEMPLATE */
  399. {
  400. #line 50 "NCDConfigParser_parse.y"
  401. free((yypminor->yy0));
  402. #line 424 "NCDConfigParser_parse.c"
  403. }
  404. break;
  405. case 14: /* processes */
  406. {
  407. #line 61 "NCDConfigParser_parse.y"
  408. NCDConfig_free_processes((yypminor->yy41));
  409. #line 431 "NCDConfigParser_parse.c"
  410. }
  411. break;
  412. case 15: /* statements */
  413. {
  414. #line 62 "NCDConfigParser_parse.y"
  415. NCDConfig_free_statements((yypminor->yy34));
  416. #line 438 "NCDConfigParser_parse.c"
  417. }
  418. break;
  419. case 16: /* statement_names */
  420. {
  421. #line 63 "NCDConfigParser_parse.y"
  422. NCDConfig_free_strings((yypminor->yy10));
  423. #line 445 "NCDConfigParser_parse.c"
  424. }
  425. break;
  426. case 17: /* statement_args_maybe */
  427. case 18: /* list_contents */
  428. case 19: /* list */
  429. {
  430. #line 64 "NCDConfigParser_parse.y"
  431. NCDConfig_free_list((yypminor->yy24));
  432. #line 454 "NCDConfigParser_parse.c"
  433. }
  434. break;
  435. case 20: /* name_maybe */
  436. {
  437. #line 67 "NCDConfigParser_parse.y"
  438. free((yypminor->yy45));
  439. #line 461 "NCDConfigParser_parse.c"
  440. }
  441. break;
  442. default: break; /* If no destructor action specified: do nothing */
  443. }
  444. }
  445. /*
  446. ** Pop the parser's stack once.
  447. **
  448. ** If there is a destructor routine associated with the token which
  449. ** is popped from the stack, then call it.
  450. **
  451. ** Return the major token number for the symbol popped.
  452. */
  453. static int yy_pop_parser_stack(yyParser *pParser){
  454. YYCODETYPE yymajor;
  455. yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
  456. if( pParser->yyidx<0 ) return 0;
  457. #ifndef NDEBUG
  458. if( yyTraceFILE && pParser->yyidx>=0 ){
  459. fprintf(yyTraceFILE,"%sPopping %s\n",
  460. yyTracePrompt,
  461. yyTokenName[yytos->major]);
  462. }
  463. #endif
  464. yymajor = yytos->major;
  465. yy_destructor(pParser, yymajor, &yytos->minor);
  466. pParser->yyidx--;
  467. return yymajor;
  468. }
  469. /*
  470. ** Deallocate and destroy a parser. Destructors are all called for
  471. ** all stack elements before shutting the parser down.
  472. **
  473. ** Inputs:
  474. ** <ul>
  475. ** <li> A pointer to the parser. This should be a pointer
  476. ** obtained from ParseAlloc.
  477. ** <li> A pointer to a function used to reclaim memory obtained
  478. ** from malloc.
  479. ** </ul>
  480. */
  481. void ParseFree(
  482. void *p, /* The parser to be deleted */
  483. void (*freeProc)(void*) /* Function used to reclaim memory */
  484. ){
  485. yyParser *pParser = (yyParser*)p;
  486. if( pParser==0 ) return;
  487. while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
  488. #if YYSTACKDEPTH<=0
  489. free(pParser->yystack);
  490. #endif
  491. (*freeProc)((void*)pParser);
  492. }
  493. /*
  494. ** Return the peak depth of the stack for a parser.
  495. */
  496. #ifdef YYTRACKMAXSTACKDEPTH
  497. int ParseStackPeak(void *p){
  498. yyParser *pParser = (yyParser*)p;
  499. return pParser->yyidxMax;
  500. }
  501. #endif
  502. /*
  503. ** Find the appropriate action for a parser given the terminal
  504. ** look-ahead token iLookAhead.
  505. **
  506. ** If the look-ahead token is YYNOCODE, then check to see if the action is
  507. ** independent of the look-ahead. If it is, return the action, otherwise
  508. ** return YY_NO_ACTION.
  509. */
  510. static int yy_find_shift_action(
  511. yyParser *pParser, /* The parser */
  512. YYCODETYPE iLookAhead /* The look-ahead token */
  513. ){
  514. int i;
  515. int stateno = pParser->yystack[pParser->yyidx].stateno;
  516. if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
  517. return yy_default[stateno];
  518. }
  519. assert( iLookAhead!=YYNOCODE );
  520. i += iLookAhead;
  521. if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  522. if( iLookAhead>0 ){
  523. #ifdef YYFALLBACK
  524. YYCODETYPE iFallback; /* Fallback token */
  525. if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
  526. && (iFallback = yyFallback[iLookAhead])!=0 ){
  527. #ifndef NDEBUG
  528. if( yyTraceFILE ){
  529. fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
  530. yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
  531. }
  532. #endif
  533. return yy_find_shift_action(pParser, iFallback);
  534. }
  535. #endif
  536. #ifdef YYWILDCARD
  537. {
  538. int j = i - iLookAhead + YYWILDCARD;
  539. if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
  540. #ifndef NDEBUG
  541. if( yyTraceFILE ){
  542. fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
  543. yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
  544. }
  545. #endif /* NDEBUG */
  546. return yy_action[j];
  547. }
  548. }
  549. #endif /* YYWILDCARD */
  550. }
  551. return yy_default[stateno];
  552. }else{
  553. return yy_action[i];
  554. }
  555. }
  556. /*
  557. ** Find the appropriate action for a parser given the non-terminal
  558. ** look-ahead token iLookAhead.
  559. **
  560. ** If the look-ahead token is YYNOCODE, then check to see if the action is
  561. ** independent of the look-ahead. If it is, return the action, otherwise
  562. ** return YY_NO_ACTION.
  563. */
  564. static int yy_find_reduce_action(
  565. int stateno, /* Current state number */
  566. YYCODETYPE iLookAhead /* The look-ahead token */
  567. ){
  568. int i;
  569. #ifdef YYERRORSYMBOL
  570. if( stateno>YY_REDUCE_MAX ){
  571. return yy_default[stateno];
  572. }
  573. #else
  574. assert( stateno<=YY_REDUCE_MAX );
  575. #endif
  576. i = yy_reduce_ofst[stateno];
  577. assert( i!=YY_REDUCE_USE_DFLT );
  578. assert( iLookAhead!=YYNOCODE );
  579. i += iLookAhead;
  580. #ifdef YYERRORSYMBOL
  581. if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  582. return yy_default[stateno];
  583. }
  584. #else
  585. assert( i>=0 && i<YY_SZ_ACTTAB );
  586. assert( yy_lookahead[i]==iLookAhead );
  587. #endif
  588. return yy_action[i];
  589. }
  590. /*
  591. ** The following routine is called if the stack overflows.
  592. */
  593. static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
  594. ParseARG_FETCH;
  595. yypParser->yyidx--;
  596. #ifndef NDEBUG
  597. if( yyTraceFILE ){
  598. fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
  599. }
  600. #endif
  601. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  602. /* Here code is inserted which will execute if the parser
  603. ** stack every overflows */
  604. #line 76 "NCDConfigParser_parse.y"
  605. if (yypMinor) {
  606. free(yypMinor->yy0);
  607. }
  608. #line 639 "NCDConfigParser_parse.c"
  609. ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
  610. }
  611. /*
  612. ** Perform a shift action.
  613. */
  614. static void yy_shift(
  615. yyParser *yypParser, /* The parser to be shifted */
  616. int yyNewState, /* The new state to shift in */
  617. int yyMajor, /* The major token to shift in */
  618. YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
  619. ){
  620. yyStackEntry *yytos;
  621. yypParser->yyidx++;
  622. #ifdef YYTRACKMAXSTACKDEPTH
  623. if( yypParser->yyidx>yypParser->yyidxMax ){
  624. yypParser->yyidxMax = yypParser->yyidx;
  625. }
  626. #endif
  627. #if YYSTACKDEPTH>0
  628. if( yypParser->yyidx>=YYSTACKDEPTH ){
  629. yyStackOverflow(yypParser, yypMinor);
  630. return;
  631. }
  632. #else
  633. if( yypParser->yyidx>=yypParser->yystksz ){
  634. yyGrowStack(yypParser);
  635. if( yypParser->yyidx>=yypParser->yystksz ){
  636. yyStackOverflow(yypParser, yypMinor);
  637. return;
  638. }
  639. }
  640. #endif
  641. yytos = &yypParser->yystack[yypParser->yyidx];
  642. yytos->stateno = (YYACTIONTYPE)yyNewState;
  643. yytos->major = (YYCODETYPE)yyMajor;
  644. yytos->minor = *yypMinor;
  645. #ifndef NDEBUG
  646. if( yyTraceFILE && yypParser->yyidx>0 ){
  647. int i;
  648. fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
  649. fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
  650. for(i=1; i<=yypParser->yyidx; i++)
  651. fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
  652. fprintf(yyTraceFILE,"\n");
  653. }
  654. #endif
  655. }
  656. /* The following table contains information about every rule that
  657. ** is used during the reduce.
  658. */
  659. static const struct {
  660. YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
  661. unsigned char nrhs; /* Number of right-hand side symbols in the rule */
  662. } yyRuleInfo[] = {
  663. { 22, 1 },
  664. { 14, 5 },
  665. { 14, 6 },
  666. { 15, 6 },
  667. { 15, 7 },
  668. { 15, 8 },
  669. { 15, 9 },
  670. { 16, 1 },
  671. { 16, 3 },
  672. { 17, 0 },
  673. { 17, 1 },
  674. { 18, 1 },
  675. { 18, 1 },
  676. { 18, 1 },
  677. { 18, 3 },
  678. { 18, 3 },
  679. { 18, 3 },
  680. { 19, 2 },
  681. { 19, 3 },
  682. { 20, 0 },
  683. { 20, 1 },
  684. { 21, 1 },
  685. { 21, 1 },
  686. };
  687. static void yy_accept(yyParser*); /* Forward Declaration */
  688. /*
  689. ** Perform a reduce action and the shift that must immediately
  690. ** follow the reduce.
  691. */
  692. static void yy_reduce(
  693. yyParser *yypParser, /* The parser */
  694. int yyruleno /* Number of the rule by which to reduce */
  695. ){
  696. int yygoto; /* The next state */
  697. int yyact; /* The next action */
  698. YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
  699. yyStackEntry *yymsp; /* The top of the parser's stack */
  700. int yysize; /* Amount to pop the stack */
  701. ParseARG_FETCH;
  702. yymsp = &yypParser->yystack[yypParser->yyidx];
  703. #ifndef NDEBUG
  704. if( yyTraceFILE && yyruleno>=0
  705. && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
  706. fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
  707. yyRuleName[yyruleno]);
  708. }
  709. #endif /* NDEBUG */
  710. /* Silence complaints from purify about yygotominor being uninitialized
  711. ** in some cases when it is copied into the stack after the following
  712. ** switch. yygotominor is uninitialized when a rule reduces that does
  713. ** not set the value of its left-hand side nonterminal. Leaving the
  714. ** value of the nonterminal uninitialized is utterly harmless as long
  715. ** as the value is never used. So really the only thing this code
  716. ** accomplishes is to quieten purify.
  717. **
  718. ** 2007-01-16: The wireshark project (www.wireshark.org) reports that
  719. ** without this code, their parser segfaults. I'm not sure what there
  720. ** parser is doing to make this happen. This is the second bug report
  721. ** from wireshark this week. Clearly they are stressing Lemon in ways
  722. ** that it has not been previously stressed... (SQLite ticket #2172)
  723. */
  724. /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  725. yygotominor = yyzerominor;
  726. switch( yyruleno ){
  727. /* Beginning here are the reduction cases. A typical example
  728. ** follows:
  729. ** case 0:
  730. ** #line <lineno> <grammarfile>
  731. ** { ... } // User supplied code
  732. ** #line <lineno> <thisfile>
  733. ** break;
  734. */
  735. case 0: /* input ::= processes */
  736. #line 82 "NCDConfigParser_parse.y"
  737. {
  738. parser_out->ast = yymsp[0].minor.yy41;
  739. if (!yymsp[0].minor.yy41) {
  740. parser_out->out_of_memory = 1;
  741. }
  742. }
  743. #line 782 "NCDConfigParser_parse.c"
  744. break;
  745. case 1: /* processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE */
  746. #line 90 "NCDConfigParser_parse.y"
  747. {
  748. yygotominor.yy41 = NCDConfig_make_processes(yymsp[-4].minor.yy6, yymsp[-3].minor.yy0, yymsp[-1].minor.yy34, 0, NULL);
  749. if (!yygotominor.yy41) {
  750. parser_out->out_of_memory = 1;
  751. }
  752. yy_destructor(yypParser,2,&yymsp[-2].minor);
  753. yy_destructor(yypParser,3,&yymsp[0].minor);
  754. }
  755. #line 794 "NCDConfigParser_parse.c"
  756. break;
  757. case 2: /* processes ::= process_or_template NAME CURLY_OPEN statements CURLY_CLOSE processes */
  758. #line 97 "NCDConfigParser_parse.y"
  759. {
  760. yygotominor.yy41 = NCDConfig_make_processes(yymsp[-5].minor.yy6, yymsp[-4].minor.yy0, yymsp[-2].minor.yy34, 1, yymsp[0].minor.yy41);
  761. if (!yygotominor.yy41) {
  762. parser_out->out_of_memory = 1;
  763. }
  764. yy_destructor(yypParser,2,&yymsp[-3].minor);
  765. yy_destructor(yypParser,3,&yymsp[-1].minor);
  766. }
  767. #line 806 "NCDConfigParser_parse.c"
  768. break;
  769. case 3: /* statements ::= statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON */
  770. #line 104 "NCDConfigParser_parse.y"
  771. {
  772. yygotominor.yy34 = NCDConfig_make_statements(NULL, yymsp[-5].minor.yy10, yymsp[-3].minor.yy24, yymsp[-1].minor.yy45, NULL);
  773. if (!yygotominor.yy34) {
  774. parser_out->out_of_memory = 1;
  775. }
  776. yy_destructor(yypParser,4,&yymsp[-4].minor);
  777. yy_destructor(yypParser,5,&yymsp[-2].minor);
  778. yy_destructor(yypParser,6,&yymsp[0].minor);
  779. }
  780. #line 819 "NCDConfigParser_parse.c"
  781. break;
  782. case 4: /* statements ::= statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON statements */
  783. #line 111 "NCDConfigParser_parse.y"
  784. {
  785. yygotominor.yy34 = NCDConfig_make_statements(NULL, yymsp[-6].minor.yy10, yymsp[-4].minor.yy24, yymsp[-2].minor.yy45, yymsp[0].minor.yy34);
  786. if (!yygotominor.yy34) {
  787. parser_out->out_of_memory = 1;
  788. }
  789. yy_destructor(yypParser,4,&yymsp[-5].minor);
  790. yy_destructor(yypParser,5,&yymsp[-3].minor);
  791. yy_destructor(yypParser,6,&yymsp[-1].minor);
  792. }
  793. #line 832 "NCDConfigParser_parse.c"
  794. break;
  795. case 5: /* statements ::= statement_names ARROW statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON */
  796. #line 118 "NCDConfigParser_parse.y"
  797. {
  798. yygotominor.yy34 = NCDConfig_make_statements(yymsp[-7].minor.yy10, yymsp[-5].minor.yy10, yymsp[-3].minor.yy24, yymsp[-1].minor.yy45, NULL);
  799. if (!yygotominor.yy34) {
  800. parser_out->out_of_memory = 1;
  801. }
  802. yy_destructor(yypParser,7,&yymsp[-6].minor);
  803. yy_destructor(yypParser,4,&yymsp[-4].minor);
  804. yy_destructor(yypParser,5,&yymsp[-2].minor);
  805. yy_destructor(yypParser,6,&yymsp[0].minor);
  806. }
  807. #line 846 "NCDConfigParser_parse.c"
  808. break;
  809. case 6: /* statements ::= statement_names ARROW statement_names ROUND_OPEN statement_args_maybe ROUND_CLOSE name_maybe SEMICOLON statements */
  810. #line 125 "NCDConfigParser_parse.y"
  811. {
  812. yygotominor.yy34 = NCDConfig_make_statements(yymsp[-8].minor.yy10, yymsp[-6].minor.yy10, yymsp[-4].minor.yy24, yymsp[-2].minor.yy45, yymsp[0].minor.yy34);
  813. if (!yygotominor.yy34) {
  814. parser_out->out_of_memory = 1;
  815. }
  816. yy_destructor(yypParser,7,&yymsp[-7].minor);
  817. yy_destructor(yypParser,4,&yymsp[-5].minor);
  818. yy_destructor(yypParser,5,&yymsp[-3].minor);
  819. yy_destructor(yypParser,6,&yymsp[-1].minor);
  820. }
  821. #line 860 "NCDConfigParser_parse.c"
  822. break;
  823. case 7: /* statement_names ::= NAME */
  824. #line 132 "NCDConfigParser_parse.y"
  825. {
  826. yygotominor.yy10 = NCDConfig_make_strings(yymsp[0].minor.yy0, 0, NULL);
  827. if (!yygotominor.yy10) {
  828. parser_out->out_of_memory = 1;
  829. }
  830. }
  831. #line 870 "NCDConfigParser_parse.c"
  832. break;
  833. case 8: /* statement_names ::= NAME DOT statement_names */
  834. #line 139 "NCDConfigParser_parse.y"
  835. {
  836. yygotominor.yy10 = NCDConfig_make_strings(yymsp[-2].minor.yy0, 1, yymsp[0].minor.yy10);
  837. if (!yygotominor.yy10) {
  838. parser_out->out_of_memory = 1;
  839. }
  840. yy_destructor(yypParser,8,&yymsp[-1].minor);
  841. }
  842. #line 881 "NCDConfigParser_parse.c"
  843. break;
  844. case 9: /* statement_args_maybe ::= */
  845. #line 146 "NCDConfigParser_parse.y"
  846. {
  847. yygotominor.yy24 = NULL;
  848. }
  849. #line 888 "NCDConfigParser_parse.c"
  850. break;
  851. case 10: /* statement_args_maybe ::= list_contents */
  852. #line 150 "NCDConfigParser_parse.y"
  853. {
  854. yygotominor.yy24 = yymsp[0].minor.yy24;
  855. }
  856. #line 895 "NCDConfigParser_parse.c"
  857. break;
  858. case 11: /* list_contents ::= STRING */
  859. #line 154 "NCDConfigParser_parse.y"
  860. {
  861. yygotominor.yy24 = NCDConfig_make_list_string(yymsp[0].minor.yy0, NULL);
  862. if (!yygotominor.yy24) {
  863. parser_out->out_of_memory = 1;
  864. }
  865. }
  866. #line 905 "NCDConfigParser_parse.c"
  867. break;
  868. case 12: /* list_contents ::= statement_names */
  869. #line 161 "NCDConfigParser_parse.y"
  870. {
  871. yygotominor.yy24 = NCDConfig_make_list_var(yymsp[0].minor.yy10, NULL);
  872. if (!yygotominor.yy24) {
  873. parser_out->out_of_memory = 1;
  874. }
  875. }
  876. #line 915 "NCDConfigParser_parse.c"
  877. break;
  878. case 13: /* list_contents ::= list */
  879. #line 168 "NCDConfigParser_parse.y"
  880. {
  881. yygotominor.yy24 = NCDConfig_make_list_list(yymsp[0].minor.yy24, NULL);
  882. if (!yygotominor.yy24) {
  883. parser_out->out_of_memory = 1;
  884. }
  885. }
  886. #line 925 "NCDConfigParser_parse.c"
  887. break;
  888. case 14: /* list_contents ::= STRING COMMA list_contents */
  889. #line 175 "NCDConfigParser_parse.y"
  890. {
  891. yygotominor.yy24 = NCDConfig_make_list_string(yymsp[-2].minor.yy0, yymsp[0].minor.yy24);
  892. if (!yygotominor.yy24) {
  893. parser_out->out_of_memory = 1;
  894. }
  895. yy_destructor(yypParser,10,&yymsp[-1].minor);
  896. }
  897. #line 936 "NCDConfigParser_parse.c"
  898. break;
  899. case 15: /* list_contents ::= statement_names COMMA list_contents */
  900. #line 182 "NCDConfigParser_parse.y"
  901. {
  902. yygotominor.yy24 = NCDConfig_make_list_var(yymsp[-2].minor.yy10, yymsp[0].minor.yy24);
  903. if (!yygotominor.yy24) {
  904. parser_out->out_of_memory = 1;
  905. }
  906. yy_destructor(yypParser,10,&yymsp[-1].minor);
  907. }
  908. #line 947 "NCDConfigParser_parse.c"
  909. break;
  910. case 16: /* list_contents ::= list COMMA list_contents */
  911. #line 189 "NCDConfigParser_parse.y"
  912. {
  913. yygotominor.yy24 = NCDConfig_make_list_list(yymsp[-2].minor.yy24, yymsp[0].minor.yy24);
  914. if (!yygotominor.yy24) {
  915. parser_out->out_of_memory = 1;
  916. }
  917. yy_destructor(yypParser,10,&yymsp[-1].minor);
  918. }
  919. #line 958 "NCDConfigParser_parse.c"
  920. break;
  921. case 17: /* list ::= CURLY_OPEN CURLY_CLOSE */
  922. #line 196 "NCDConfigParser_parse.y"
  923. {
  924. yygotominor.yy24 = NULL;
  925. yy_destructor(yypParser,2,&yymsp[-1].minor);
  926. yy_destructor(yypParser,3,&yymsp[0].minor);
  927. }
  928. #line 967 "NCDConfigParser_parse.c"
  929. break;
  930. case 18: /* list ::= CURLY_OPEN list_contents CURLY_CLOSE */
  931. #line 200 "NCDConfigParser_parse.y"
  932. {
  933. yygotominor.yy24 = yymsp[-1].minor.yy24;
  934. yy_destructor(yypParser,2,&yymsp[-2].minor);
  935. yy_destructor(yypParser,3,&yymsp[0].minor);
  936. }
  937. #line 976 "NCDConfigParser_parse.c"
  938. break;
  939. case 19: /* name_maybe ::= */
  940. #line 204 "NCDConfigParser_parse.y"
  941. {
  942. yygotominor.yy45 = NULL;
  943. }
  944. #line 983 "NCDConfigParser_parse.c"
  945. break;
  946. case 20: /* name_maybe ::= NAME */
  947. #line 208 "NCDConfigParser_parse.y"
  948. {
  949. yygotominor.yy45 = yymsp[0].minor.yy0;
  950. }
  951. #line 990 "NCDConfigParser_parse.c"
  952. break;
  953. case 21: /* process_or_template ::= PROCESS */
  954. #line 212 "NCDConfigParser_parse.y"
  955. {
  956. yygotominor.yy6 = 0;
  957. yy_destructor(yypParser,11,&yymsp[0].minor);
  958. }
  959. #line 998 "NCDConfigParser_parse.c"
  960. break;
  961. case 22: /* process_or_template ::= TEMPLATE */
  962. #line 216 "NCDConfigParser_parse.y"
  963. {
  964. yygotominor.yy6 = 1;
  965. yy_destructor(yypParser,12,&yymsp[0].minor);
  966. }
  967. #line 1006 "NCDConfigParser_parse.c"
  968. break;
  969. default:
  970. break;
  971. };
  972. yygoto = yyRuleInfo[yyruleno].lhs;
  973. yysize = yyRuleInfo[yyruleno].nrhs;
  974. yypParser->yyidx -= yysize;
  975. yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  976. if( yyact < YYNSTATE ){
  977. #ifdef NDEBUG
  978. /* If we are not debugging and the reduce action popped at least
  979. ** one element off the stack, then we can push the new element back
  980. ** onto the stack here, and skip the stack overflow test in yy_shift().
  981. ** That gives a significant speed improvement. */
  982. if( yysize ){
  983. yypParser->yyidx++;
  984. yymsp -= yysize-1;
  985. yymsp->stateno = (YYACTIONTYPE)yyact;
  986. yymsp->major = (YYCODETYPE)yygoto;
  987. yymsp->minor = yygotominor;
  988. }else
  989. #endif
  990. {
  991. yy_shift(yypParser,yyact,yygoto,&yygotominor);
  992. }
  993. }else{
  994. assert( yyact == YYNSTATE + YYNRULE + 1 );
  995. yy_accept(yypParser);
  996. }
  997. }
  998. /*
  999. ** The following code executes when the parse fails
  1000. */
  1001. #ifndef YYNOERRORRECOVERY
  1002. static void yy_parse_failed(
  1003. yyParser *yypParser /* The parser */
  1004. ){
  1005. ParseARG_FETCH;
  1006. #ifndef NDEBUG
  1007. if( yyTraceFILE ){
  1008. fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
  1009. }
  1010. #endif
  1011. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  1012. /* Here code is inserted which will be executed whenever the
  1013. ** parser fails */
  1014. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  1015. }
  1016. #endif /* YYNOERRORRECOVERY */
  1017. /*
  1018. ** The following code executes when a syntax error first occurs.
  1019. */
  1020. static void yy_syntax_error(
  1021. yyParser *yypParser, /* The parser */
  1022. int yymajor, /* The major type of the error token */
  1023. YYMINORTYPE yyminor /* The minor type of the error token */
  1024. ){
  1025. ParseARG_FETCH;
  1026. #define TOKEN (yyminor.yy0)
  1027. #line 71 "NCDConfigParser_parse.y"
  1028. parser_out->syntax_error = 1;
  1029. #line 1071 "NCDConfigParser_parse.c"
  1030. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  1031. }
  1032. /*
  1033. ** The following is executed when the parser accepts
  1034. */
  1035. static void yy_accept(
  1036. yyParser *yypParser /* The parser */
  1037. ){
  1038. ParseARG_FETCH;
  1039. #ifndef NDEBUG
  1040. if( yyTraceFILE ){
  1041. fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
  1042. }
  1043. #endif
  1044. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  1045. /* Here code is inserted which will be executed whenever the
  1046. ** parser accepts */
  1047. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  1048. }
  1049. /* The main parser program.
  1050. ** The first argument is a pointer to a structure obtained from
  1051. ** "ParseAlloc" which describes the current state of the parser.
  1052. ** The second argument is the major token number. The third is
  1053. ** the minor token. The fourth optional argument is whatever the
  1054. ** user wants (and specified in the grammar) and is available for
  1055. ** use by the action routines.
  1056. **
  1057. ** Inputs:
  1058. ** <ul>
  1059. ** <li> A pointer to the parser (an opaque structure.)
  1060. ** <li> The major token number.
  1061. ** <li> The minor token number.
  1062. ** <li> An option argument of a grammar-specified type.
  1063. ** </ul>
  1064. **
  1065. ** Outputs:
  1066. ** None.
  1067. */
  1068. void Parse(
  1069. void *yyp, /* The parser */
  1070. int yymajor, /* The major token code number */
  1071. ParseTOKENTYPE yyminor /* The value for the token */
  1072. ParseARG_PDECL /* Optional %extra_argument parameter */
  1073. ){
  1074. YYMINORTYPE yyminorunion;
  1075. int yyact; /* The parser action. */
  1076. int yyendofinput; /* True if we are at the end of input */
  1077. #ifdef YYERRORSYMBOL
  1078. int yyerrorhit = 0; /* True if yymajor has invoked an error */
  1079. #endif
  1080. yyParser *yypParser; /* The parser */
  1081. /* (re)initialize the parser, if necessary */
  1082. yypParser = (yyParser*)yyp;
  1083. if( yypParser->yyidx<0 ){
  1084. #if YYSTACKDEPTH<=0
  1085. if( yypParser->yystksz <=0 ){
  1086. /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/
  1087. yyminorunion = yyzerominor;
  1088. yyStackOverflow(yypParser, &yyminorunion);
  1089. return;
  1090. }
  1091. #endif
  1092. yypParser->yyidx = 0;
  1093. yypParser->yyerrcnt = -1;
  1094. yypParser->yystack[0].stateno = 0;
  1095. yypParser->yystack[0].major = 0;
  1096. }
  1097. yyminorunion.yy0 = yyminor;
  1098. yyendofinput = (yymajor==0);
  1099. ParseARG_STORE;
  1100. #ifndef NDEBUG
  1101. if( yyTraceFILE ){
  1102. fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  1103. }
  1104. #endif
  1105. do{
  1106. yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
  1107. if( yyact<YYNSTATE ){
  1108. assert( !yyendofinput ); /* Impossible to shift the $ token */
  1109. yy_shift(yypParser,yyact,yymajor,&yyminorunion);
  1110. yypParser->yyerrcnt--;
  1111. yymajor = YYNOCODE;
  1112. }else if( yyact < YYNSTATE + YYNRULE ){
  1113. yy_reduce(yypParser,yyact-YYNSTATE);
  1114. }else{
  1115. assert( yyact == YY_ERROR_ACTION );
  1116. #ifdef YYERRORSYMBOL
  1117. int yymx;
  1118. #endif
  1119. #ifndef NDEBUG
  1120. if( yyTraceFILE ){
  1121. fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
  1122. }
  1123. #endif
  1124. #ifdef YYERRORSYMBOL
  1125. /* A syntax error has occurred.
  1126. ** The response to an error depends upon whether or not the
  1127. ** grammar defines an error token "ERROR".
  1128. **
  1129. ** This is what we do if the grammar does define ERROR:
  1130. **
  1131. ** * Call the %syntax_error function.
  1132. **
  1133. ** * Begin popping the stack until we enter a state where
  1134. ** it is legal to shift the error symbol, then shift
  1135. ** the error symbol.
  1136. **
  1137. ** * Set the error count to three.
  1138. **
  1139. ** * Begin accepting and shifting new tokens. No new error
  1140. ** processing will occur until three tokens have been
  1141. ** shifted successfully.
  1142. **
  1143. */
  1144. if( yypParser->yyerrcnt<0 ){
  1145. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1146. }
  1147. yymx = yypParser->yystack[yypParser->yyidx].major;
  1148. if( yymx==YYERRORSYMBOL || yyerrorhit ){
  1149. #ifndef NDEBUG
  1150. if( yyTraceFILE ){
  1151. fprintf(yyTraceFILE,"%sDiscard input token %s\n",
  1152. yyTracePrompt,yyTokenName[yymajor]);
  1153. }
  1154. #endif
  1155. yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
  1156. yymajor = YYNOCODE;
  1157. }else{
  1158. while(
  1159. yypParser->yyidx >= 0 &&
  1160. yymx != YYERRORSYMBOL &&
  1161. (yyact = yy_find_reduce_action(
  1162. yypParser->yystack[yypParser->yyidx].stateno,
  1163. YYERRORSYMBOL)) >= YYNSTATE
  1164. ){
  1165. yy_pop_parser_stack(yypParser);
  1166. }
  1167. if( yypParser->yyidx < 0 || yymajor==0 ){
  1168. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1169. yy_parse_failed(yypParser);
  1170. yymajor = YYNOCODE;
  1171. }else if( yymx!=YYERRORSYMBOL ){
  1172. YYMINORTYPE u2;
  1173. u2.YYERRSYMDT = 0;
  1174. yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
  1175. }
  1176. }
  1177. yypParser->yyerrcnt = 3;
  1178. yyerrorhit = 1;
  1179. #elif defined(YYNOERRORRECOVERY)
  1180. /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
  1181. ** do any kind of error recovery. Instead, simply invoke the syntax
  1182. ** error routine and continue going as if nothing had happened.
  1183. **
  1184. ** Applications can set this macro (for example inside %include) if
  1185. ** they intend to abandon the parse upon the first syntax error seen.
  1186. */
  1187. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1188. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1189. yymajor = YYNOCODE;
  1190. #else /* YYERRORSYMBOL is not defined */
  1191. /* This is what we do if the grammar does not define ERROR:
  1192. **
  1193. ** * Report an error message, and throw away the input token.
  1194. **
  1195. ** * If the input token is $, then fail the parse.
  1196. **
  1197. ** As before, subsequent error messages are suppressed until
  1198. ** three input tokens have been successfully shifted.
  1199. */
  1200. if( yypParser->yyerrcnt<=0 ){
  1201. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1202. }
  1203. yypParser->yyerrcnt = 3;
  1204. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1205. if( yyendofinput ){
  1206. yy_parse_failed(yypParser);
  1207. }
  1208. yymajor = YYNOCODE;
  1209. #endif
  1210. }
  1211. }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
  1212. return;
  1213. }