NCDValueParser_parse.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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 "NCDValueParser_parse.y"
  8. #include <string.h>
  9. #include <stddef.h>
  10. #include <misc/debug.h>
  11. #include <ncd/NCDConfig.h>
  12. #define AST_TYPE_NONE 0
  13. #define AST_TYPE_STRING 1
  14. #define AST_TYPE_LIST 2
  15. struct parser_out {
  16. int out_of_memory;
  17. int syntax_error;
  18. int ast_type;
  19. char *ast_string;
  20. struct NCDConfig_list *ast_list;
  21. };
  22. #line 29 "NCDValueParser_parse.c"
  23. /* Next is all token values, in a form suitable for use by makeheaders.
  24. ** This section will be null unless lemon is run with the -m switch.
  25. */
  26. /*
  27. ** These constants (all generated automatically by the parser generator)
  28. ** specify the various kinds of tokens (terminals) that the parser
  29. ** understands.
  30. **
  31. ** Each symbol here is a terminal symbol in the grammar.
  32. */
  33. /* Make sure the INTERFACE macro is defined.
  34. */
  35. #ifndef INTERFACE
  36. # define INTERFACE 1
  37. #endif
  38. /* The next thing included is series of defines which control
  39. ** various aspects of the generated parser.
  40. ** YYCODETYPE is the data type used for storing terminal
  41. ** and nonterminal numbers. "unsigned char" is
  42. ** used if there are fewer than 250 terminals
  43. ** and nonterminals. "int" is used otherwise.
  44. ** YYNOCODE is a number of type YYCODETYPE which corresponds
  45. ** to no legal terminal or nonterminal number. This
  46. ** number is used to fill in empty slots of the hash
  47. ** table.
  48. ** YYFALLBACK If defined, this indicates that one or more tokens
  49. ** have fall-back values which should be used if the
  50. ** original value of the token will not parse.
  51. ** YYACTIONTYPE is the data type used for storing terminal
  52. ** and nonterminal numbers. "unsigned char" is
  53. ** used if there are fewer than 250 rules and
  54. ** states combined. "int" is used otherwise.
  55. ** ParseTOKENTYPE is the data type used for minor tokens given
  56. ** directly to the parser from the tokenizer.
  57. ** YYMINORTYPE is the data type used for all minor tokens.
  58. ** This is typically a union of many types, one of
  59. ** which is ParseTOKENTYPE. The entry in the union
  60. ** for base tokens is called "yy0".
  61. ** YYSTACKDEPTH is the maximum depth of the parser's stack. If
  62. ** zero the stack is dynamically sized using realloc()
  63. ** ParseARG_SDECL A static variable declaration for the %extra_argument
  64. ** ParseARG_PDECL A parameter declaration for the %extra_argument
  65. ** ParseARG_STORE Code to store %extra_argument into yypParser
  66. ** ParseARG_FETCH Code to extract %extra_argument from yypParser
  67. ** YYNSTATE the combined number of states.
  68. ** YYNRULE the number of rules in the grammar
  69. ** YYERRORSYMBOL is the code number of the error symbol. If not
  70. ** defined, then do no error processing.
  71. */
  72. #define YYCODETYPE unsigned char
  73. #define YYNOCODE 11
  74. #define YYACTIONTYPE unsigned char
  75. #define ParseTOKENTYPE void *
  76. typedef union {
  77. int yyinit;
  78. ParseTOKENTYPE yy0;
  79. struct NCDConfig_list * yy14;
  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 12
  89. #define YYNRULE 8
  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 */ 8, 11, 1, 10, 6, 9, 5, 7, 9, 5,
  156. /* 10 */ 3, 4, 1, 21, 8, 12, 1, 13, 2,
  157. };
  158. static const YYCODETYPE yy_lookahead[] = {
  159. /* 0 */ 1, 4, 3, 4, 6, 7, 8, 6, 7, 8,
  160. /* 10 */ 1, 7, 3, 9, 1, 0, 3, 0, 2,
  161. };
  162. #define YY_SHIFT_USE_DFLT (-4)
  163. #define YY_SHIFT_MAX 6
  164. static const signed char yy_shift_ofst[] = {
  165. /* 0 */ 9, -1, 13, 15, 17, 16, -3,
  166. };
  167. #define YY_REDUCE_USE_DFLT (-3)
  168. #define YY_REDUCE_MAX 2
  169. static const signed char yy_reduce_ofst[] = {
  170. /* 0 */ 4, -2, 1,
  171. };
  172. static const YYACTIONTYPE yy_default[] = {
  173. /* 0 */ 20, 20, 20, 20, 20, 14, 20, 15, 18, 19,
  174. /* 10 */ 16, 17,
  175. };
  176. #define YY_SZ_ACTTAB (int)(sizeof(yy_action)/sizeof(yy_action[0]))
  177. /* The next table maps tokens into fallback tokens. If a construct
  178. ** like the following:
  179. **
  180. ** %fallback ID X Y Z.
  181. **
  182. ** appears in the grammar, then ID becomes a fallback token for X, Y,
  183. ** and Z. Whenever one of the tokens X, Y, or Z is input to the parser
  184. ** but it does not parse, the type of the token is changed to ID and
  185. ** the parse is retried before an error is thrown.
  186. */
  187. #ifdef YYFALLBACK
  188. static const YYCODETYPE yyFallback[] = {
  189. };
  190. #endif /* YYFALLBACK */
  191. /* The following structure represents a single element of the
  192. ** parser's stack. Information stored includes:
  193. **
  194. ** + The state number for the parser at this level of the stack.
  195. **
  196. ** + The value of the token stored at this level of the stack.
  197. ** (In other words, the "major" token.)
  198. **
  199. ** + The semantic value stored at this level of the stack. This is
  200. ** the information used by the action routines in the grammar.
  201. ** It is sometimes called the "minor" token.
  202. */
  203. struct yyStackEntry {
  204. YYACTIONTYPE stateno; /* The state-number */
  205. YYCODETYPE major; /* The major token value. This is the code
  206. ** number for the token at this stack level */
  207. YYMINORTYPE minor; /* The user-supplied minor token value. This
  208. ** is the value of the token */
  209. };
  210. typedef struct yyStackEntry yyStackEntry;
  211. /* The state of the parser is completely contained in an instance of
  212. ** the following structure */
  213. struct yyParser {
  214. int yyidx; /* Index of top element in stack */
  215. #ifdef YYTRACKMAXSTACKDEPTH
  216. int yyidxMax; /* Maximum value of yyidx */
  217. #endif
  218. int yyerrcnt; /* Shifts left before out of the error */
  219. ParseARG_SDECL /* A place to hold %extra_argument */
  220. #if YYSTACKDEPTH<=0
  221. int yystksz; /* Current side of the stack */
  222. yyStackEntry *yystack; /* The parser's stack */
  223. #else
  224. yyStackEntry yystack[YYSTACKDEPTH]; /* The parser's stack */
  225. #endif
  226. };
  227. typedef struct yyParser yyParser;
  228. #ifndef NDEBUG
  229. #include <stdio.h>
  230. static FILE *yyTraceFILE = 0;
  231. static char *yyTracePrompt = 0;
  232. #endif /* NDEBUG */
  233. #ifndef NDEBUG
  234. /*
  235. ** Turn parser tracing on by giving a stream to which to write the trace
  236. ** and a prompt to preface each trace message. Tracing is turned off
  237. ** by making either argument NULL
  238. **
  239. ** Inputs:
  240. ** <ul>
  241. ** <li> A FILE* to which trace output should be written.
  242. ** If NULL, then tracing is turned off.
  243. ** <li> A prefix string written at the beginning of every
  244. ** line of trace output. If NULL, then tracing is
  245. ** turned off.
  246. ** </ul>
  247. **
  248. ** Outputs:
  249. ** None.
  250. */
  251. void ParseTrace(FILE *TraceFILE, char *zTracePrompt){
  252. yyTraceFILE = TraceFILE;
  253. yyTracePrompt = zTracePrompt;
  254. if( yyTraceFILE==0 ) yyTracePrompt = 0;
  255. else if( yyTracePrompt==0 ) yyTraceFILE = 0;
  256. }
  257. #endif /* NDEBUG */
  258. #ifndef NDEBUG
  259. /* For tracing shifts, the names of all terminals and nonterminals
  260. ** are required. The following table supplies these names */
  261. static const char *const yyTokenName[] = {
  262. "$", "STRING", "COMMA", "CURLY_OPEN",
  263. "CURLY_CLOSE", "error", "list_contents", "list",
  264. "value", "input",
  265. };
  266. #endif /* NDEBUG */
  267. #ifndef NDEBUG
  268. /* For tracing reduce actions, the names of all rules are required.
  269. */
  270. static const char *const yyRuleName[] = {
  271. /* 0 */ "input ::= STRING",
  272. /* 1 */ "input ::= list",
  273. /* 2 */ "list_contents ::= value",
  274. /* 3 */ "list_contents ::= value COMMA list_contents",
  275. /* 4 */ "list ::= CURLY_OPEN CURLY_CLOSE",
  276. /* 5 */ "list ::= CURLY_OPEN list_contents CURLY_CLOSE",
  277. /* 6 */ "value ::= STRING",
  278. /* 7 */ "value ::= list",
  279. };
  280. #endif /* NDEBUG */
  281. #if YYSTACKDEPTH<=0
  282. /*
  283. ** Try to increase the size of the parser stack.
  284. */
  285. static void yyGrowStack(yyParser *p){
  286. int newSize;
  287. yyStackEntry *pNew;
  288. newSize = p->yystksz*2 + 100;
  289. pNew = realloc(p->yystack, newSize*sizeof(pNew[0]));
  290. if( pNew ){
  291. p->yystack = pNew;
  292. p->yystksz = newSize;
  293. #ifndef NDEBUG
  294. if( yyTraceFILE ){
  295. fprintf(yyTraceFILE,"%sStack grows to %d entries!\n",
  296. yyTracePrompt, p->yystksz);
  297. }
  298. #endif
  299. }
  300. }
  301. #endif
  302. /*
  303. ** This function allocates a new parser.
  304. ** The only argument is a pointer to a function which works like
  305. ** malloc.
  306. **
  307. ** Inputs:
  308. ** A pointer to the function used to allocate memory.
  309. **
  310. ** Outputs:
  311. ** A pointer to a parser. This pointer is used in subsequent calls
  312. ** to Parse and ParseFree.
  313. */
  314. void *ParseAlloc(void *(*mallocProc)(size_t)){
  315. yyParser *pParser;
  316. pParser = (yyParser*)(*mallocProc)( (size_t)sizeof(yyParser) );
  317. if( pParser ){
  318. pParser->yyidx = -1;
  319. #ifdef YYTRACKMAXSTACKDEPTH
  320. pParser->yyidxMax = 0;
  321. #endif
  322. #if YYSTACKDEPTH<=0
  323. pParser->yystack = NULL;
  324. pParser->yystksz = 0;
  325. yyGrowStack(pParser);
  326. #endif
  327. }
  328. return pParser;
  329. }
  330. /* The following function deletes the value associated with a
  331. ** symbol. The symbol can be either a terminal or nonterminal.
  332. ** "yymajor" is the symbol code, and "yypminor" is a pointer to
  333. ** the value.
  334. */
  335. static void yy_destructor(
  336. yyParser *yypParser, /* The parser */
  337. YYCODETYPE yymajor, /* Type code for object to destroy */
  338. YYMINORTYPE *yypminor /* The object to be destroyed */
  339. ){
  340. ParseARG_FETCH;
  341. switch( yymajor ){
  342. /* Here is inserted the actions which take place when a
  343. ** terminal or non-terminal is destroyed. This can happen
  344. ** when the symbol is popped from the stack during a
  345. ** reduce or during error processing or when a parser is
  346. ** being destroyed before it is finished parsing.
  347. **
  348. ** Note: during a reduce, the only symbols destroyed are those
  349. ** which appear on the RHS of the rule, but which are not used
  350. ** inside the C code.
  351. */
  352. /* TERMINAL Destructor */
  353. case 1: /* STRING */
  354. case 2: /* COMMA */
  355. case 3: /* CURLY_OPEN */
  356. case 4: /* CURLY_CLOSE */
  357. {
  358. #line 56 "NCDValueParser_parse.y"
  359. free((yypminor->yy0));
  360. #line 383 "NCDValueParser_parse.c"
  361. }
  362. break;
  363. case 6: /* list_contents */
  364. case 7: /* list */
  365. case 8: /* value */
  366. {
  367. #line 62 "NCDValueParser_parse.y"
  368. NCDConfig_free_list((yypminor->yy14));
  369. #line 392 "NCDValueParser_parse.c"
  370. }
  371. break;
  372. default: break; /* If no destructor action specified: do nothing */
  373. }
  374. }
  375. /*
  376. ** Pop the parser's stack once.
  377. **
  378. ** If there is a destructor routine associated with the token which
  379. ** is popped from the stack, then call it.
  380. **
  381. ** Return the major token number for the symbol popped.
  382. */
  383. static int yy_pop_parser_stack(yyParser *pParser){
  384. YYCODETYPE yymajor;
  385. yyStackEntry *yytos = &pParser->yystack[pParser->yyidx];
  386. if( pParser->yyidx<0 ) return 0;
  387. #ifndef NDEBUG
  388. if( yyTraceFILE && pParser->yyidx>=0 ){
  389. fprintf(yyTraceFILE,"%sPopping %s\n",
  390. yyTracePrompt,
  391. yyTokenName[yytos->major]);
  392. }
  393. #endif
  394. yymajor = yytos->major;
  395. yy_destructor(pParser, yymajor, &yytos->minor);
  396. pParser->yyidx--;
  397. return yymajor;
  398. }
  399. /*
  400. ** Deallocate and destroy a parser. Destructors are all called for
  401. ** all stack elements before shutting the parser down.
  402. **
  403. ** Inputs:
  404. ** <ul>
  405. ** <li> A pointer to the parser. This should be a pointer
  406. ** obtained from ParseAlloc.
  407. ** <li> A pointer to a function used to reclaim memory obtained
  408. ** from malloc.
  409. ** </ul>
  410. */
  411. void ParseFree(
  412. void *p, /* The parser to be deleted */
  413. void (*freeProc)(void*) /* Function used to reclaim memory */
  414. ){
  415. yyParser *pParser = (yyParser*)p;
  416. if( pParser==0 ) return;
  417. while( pParser->yyidx>=0 ) yy_pop_parser_stack(pParser);
  418. #if YYSTACKDEPTH<=0
  419. free(pParser->yystack);
  420. #endif
  421. (*freeProc)((void*)pParser);
  422. }
  423. /*
  424. ** Return the peak depth of the stack for a parser.
  425. */
  426. #ifdef YYTRACKMAXSTACKDEPTH
  427. int ParseStackPeak(void *p){
  428. yyParser *pParser = (yyParser*)p;
  429. return pParser->yyidxMax;
  430. }
  431. #endif
  432. /*
  433. ** Find the appropriate action for a parser given the terminal
  434. ** look-ahead token iLookAhead.
  435. **
  436. ** If the look-ahead token is YYNOCODE, then check to see if the action is
  437. ** independent of the look-ahead. If it is, return the action, otherwise
  438. ** return YY_NO_ACTION.
  439. */
  440. static int yy_find_shift_action(
  441. yyParser *pParser, /* The parser */
  442. YYCODETYPE iLookAhead /* The look-ahead token */
  443. ){
  444. int i;
  445. int stateno = pParser->yystack[pParser->yyidx].stateno;
  446. if( stateno>YY_SHIFT_MAX || (i = yy_shift_ofst[stateno])==YY_SHIFT_USE_DFLT ){
  447. return yy_default[stateno];
  448. }
  449. assert( iLookAhead!=YYNOCODE );
  450. i += iLookAhead;
  451. if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  452. if( iLookAhead>0 ){
  453. #ifdef YYFALLBACK
  454. YYCODETYPE iFallback; /* Fallback token */
  455. if( iLookAhead<sizeof(yyFallback)/sizeof(yyFallback[0])
  456. && (iFallback = yyFallback[iLookAhead])!=0 ){
  457. #ifndef NDEBUG
  458. if( yyTraceFILE ){
  459. fprintf(yyTraceFILE, "%sFALLBACK %s => %s\n",
  460. yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[iFallback]);
  461. }
  462. #endif
  463. return yy_find_shift_action(pParser, iFallback);
  464. }
  465. #endif
  466. #ifdef YYWILDCARD
  467. {
  468. int j = i - iLookAhead + YYWILDCARD;
  469. if( j>=0 && j<YY_SZ_ACTTAB && yy_lookahead[j]==YYWILDCARD ){
  470. #ifndef NDEBUG
  471. if( yyTraceFILE ){
  472. fprintf(yyTraceFILE, "%sWILDCARD %s => %s\n",
  473. yyTracePrompt, yyTokenName[iLookAhead], yyTokenName[YYWILDCARD]);
  474. }
  475. #endif /* NDEBUG */
  476. return yy_action[j];
  477. }
  478. }
  479. #endif /* YYWILDCARD */
  480. }
  481. return yy_default[stateno];
  482. }else{
  483. return yy_action[i];
  484. }
  485. }
  486. /*
  487. ** Find the appropriate action for a parser given the non-terminal
  488. ** look-ahead token iLookAhead.
  489. **
  490. ** If the look-ahead token is YYNOCODE, then check to see if the action is
  491. ** independent of the look-ahead. If it is, return the action, otherwise
  492. ** return YY_NO_ACTION.
  493. */
  494. static int yy_find_reduce_action(
  495. int stateno, /* Current state number */
  496. YYCODETYPE iLookAhead /* The look-ahead token */
  497. ){
  498. int i;
  499. #ifdef YYERRORSYMBOL
  500. if( stateno>YY_REDUCE_MAX ){
  501. return yy_default[stateno];
  502. }
  503. #else
  504. assert( stateno<=YY_REDUCE_MAX );
  505. #endif
  506. i = yy_reduce_ofst[stateno];
  507. assert( i!=YY_REDUCE_USE_DFLT );
  508. assert( iLookAhead!=YYNOCODE );
  509. i += iLookAhead;
  510. #ifdef YYERRORSYMBOL
  511. if( i<0 || i>=YY_SZ_ACTTAB || yy_lookahead[i]!=iLookAhead ){
  512. return yy_default[stateno];
  513. }
  514. #else
  515. assert( i>=0 && i<YY_SZ_ACTTAB );
  516. assert( yy_lookahead[i]==iLookAhead );
  517. #endif
  518. return yy_action[i];
  519. }
  520. /*
  521. ** The following routine is called if the stack overflows.
  522. */
  523. static void yyStackOverflow(yyParser *yypParser, YYMINORTYPE *yypMinor){
  524. ParseARG_FETCH;
  525. yypParser->yyidx--;
  526. #ifndef NDEBUG
  527. if( yyTraceFILE ){
  528. fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
  529. }
  530. #endif
  531. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  532. /* Here code is inserted which will execute if the parser
  533. ** stack every overflows */
  534. #line 73 "NCDValueParser_parse.y"
  535. if (yypMinor) {
  536. free(yypMinor->yy0);
  537. }
  538. #line 570 "NCDValueParser_parse.c"
  539. ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
  540. }
  541. /*
  542. ** Perform a shift action.
  543. */
  544. static void yy_shift(
  545. yyParser *yypParser, /* The parser to be shifted */
  546. int yyNewState, /* The new state to shift in */
  547. int yyMajor, /* The major token to shift in */
  548. YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
  549. ){
  550. yyStackEntry *yytos;
  551. yypParser->yyidx++;
  552. #ifdef YYTRACKMAXSTACKDEPTH
  553. if( yypParser->yyidx>yypParser->yyidxMax ){
  554. yypParser->yyidxMax = yypParser->yyidx;
  555. }
  556. #endif
  557. #if YYSTACKDEPTH>0
  558. if( yypParser->yyidx>=YYSTACKDEPTH ){
  559. yyStackOverflow(yypParser, yypMinor);
  560. return;
  561. }
  562. #else
  563. if( yypParser->yyidx>=yypParser->yystksz ){
  564. yyGrowStack(yypParser);
  565. if( yypParser->yyidx>=yypParser->yystksz ){
  566. yyStackOverflow(yypParser, yypMinor);
  567. return;
  568. }
  569. }
  570. #endif
  571. yytos = &yypParser->yystack[yypParser->yyidx];
  572. yytos->stateno = (YYACTIONTYPE)yyNewState;
  573. yytos->major = (YYCODETYPE)yyMajor;
  574. yytos->minor = *yypMinor;
  575. #ifndef NDEBUG
  576. if( yyTraceFILE && yypParser->yyidx>0 ){
  577. int i;
  578. fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
  579. fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
  580. for(i=1; i<=yypParser->yyidx; i++)
  581. fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
  582. fprintf(yyTraceFILE,"\n");
  583. }
  584. #endif
  585. }
  586. /* The following table contains information about every rule that
  587. ** is used during the reduce.
  588. */
  589. static const struct {
  590. YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
  591. unsigned char nrhs; /* Number of right-hand side symbols in the rule */
  592. } yyRuleInfo[] = {
  593. { 9, 1 },
  594. { 9, 1 },
  595. { 6, 1 },
  596. { 6, 3 },
  597. { 7, 2 },
  598. { 7, 3 },
  599. { 8, 1 },
  600. { 8, 1 },
  601. };
  602. static void yy_accept(yyParser*); /* Forward Declaration */
  603. /*
  604. ** Perform a reduce action and the shift that must immediately
  605. ** follow the reduce.
  606. */
  607. static void yy_reduce(
  608. yyParser *yypParser, /* The parser */
  609. int yyruleno /* Number of the rule by which to reduce */
  610. ){
  611. int yygoto; /* The next state */
  612. int yyact; /* The next action */
  613. YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
  614. yyStackEntry *yymsp; /* The top of the parser's stack */
  615. int yysize; /* Amount to pop the stack */
  616. ParseARG_FETCH;
  617. yymsp = &yypParser->yystack[yypParser->yyidx];
  618. #ifndef NDEBUG
  619. if( yyTraceFILE && yyruleno>=0
  620. && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
  621. fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
  622. yyRuleName[yyruleno]);
  623. }
  624. #endif /* NDEBUG */
  625. /* Silence complaints from purify about yygotominor being uninitialized
  626. ** in some cases when it is copied into the stack after the following
  627. ** switch. yygotominor is uninitialized when a rule reduces that does
  628. ** not set the value of its left-hand side nonterminal. Leaving the
  629. ** value of the nonterminal uninitialized is utterly harmless as long
  630. ** as the value is never used. So really the only thing this code
  631. ** accomplishes is to quieten purify.
  632. **
  633. ** 2007-01-16: The wireshark project (www.wireshark.org) reports that
  634. ** without this code, their parser segfaults. I'm not sure what there
  635. ** parser is doing to make this happen. This is the second bug report
  636. ** from wireshark this week. Clearly they are stressing Lemon in ways
  637. ** that it has not been previously stressed... (SQLite ticket #2172)
  638. */
  639. /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  640. yygotominor = yyzerominor;
  641. switch( yyruleno ){
  642. /* Beginning here are the reduction cases. A typical example
  643. ** follows:
  644. ** case 0:
  645. ** #line <lineno> <grammarfile>
  646. ** { ... } // User supplied code
  647. ** #line <lineno> <thisfile>
  648. ** break;
  649. */
  650. case 0: /* input ::= STRING */
  651. #line 79 "NCDValueParser_parse.y"
  652. {
  653. ASSERT(parser_out->ast_type == AST_TYPE_NONE)
  654. parser_out->ast_string = yymsp[0].minor.yy0;
  655. parser_out->ast_type = AST_TYPE_STRING;
  656. }
  657. #line 697 "NCDValueParser_parse.c"
  658. break;
  659. case 1: /* input ::= list */
  660. #line 86 "NCDValueParser_parse.y"
  661. {
  662. ASSERT(parser_out->ast_type == AST_TYPE_NONE)
  663. parser_out->ast_list = yymsp[0].minor.yy14;
  664. parser_out->ast_type = AST_TYPE_LIST;
  665. }
  666. #line 707 "NCDValueParser_parse.c"
  667. break;
  668. case 2: /* list_contents ::= value */
  669. #line 93 "NCDValueParser_parse.y"
  670. {
  671. yygotominor.yy14 = yymsp[0].minor.yy14;
  672. }
  673. #line 714 "NCDValueParser_parse.c"
  674. break;
  675. case 3: /* list_contents ::= value COMMA list_contents */
  676. #line 97 "NCDValueParser_parse.y"
  677. {
  678. if (!yymsp[-2].minor.yy14) {
  679. NCDConfig_free_list(yymsp[0].minor.yy14);
  680. } else {
  681. ASSERT(!yymsp[-2].minor.yy14->next)
  682. yymsp[-2].minor.yy14->next = yymsp[0].minor.yy14;
  683. }
  684. yygotominor.yy14 = yymsp[-2].minor.yy14;
  685. yy_destructor(yypParser,2,&yymsp[-1].minor);
  686. }
  687. #line 728 "NCDValueParser_parse.c"
  688. break;
  689. case 4: /* list ::= CURLY_OPEN CURLY_CLOSE */
  690. #line 107 "NCDValueParser_parse.y"
  691. {
  692. yygotominor.yy14 = NULL;
  693. yy_destructor(yypParser,3,&yymsp[-1].minor);
  694. yy_destructor(yypParser,4,&yymsp[0].minor);
  695. }
  696. #line 737 "NCDValueParser_parse.c"
  697. break;
  698. case 5: /* list ::= CURLY_OPEN list_contents CURLY_CLOSE */
  699. #line 111 "NCDValueParser_parse.y"
  700. {
  701. yygotominor.yy14 = yymsp[-1].minor.yy14;
  702. yy_destructor(yypParser,3,&yymsp[-2].minor);
  703. yy_destructor(yypParser,4,&yymsp[0].minor);
  704. }
  705. #line 746 "NCDValueParser_parse.c"
  706. break;
  707. case 6: /* value ::= STRING */
  708. #line 115 "NCDValueParser_parse.y"
  709. {
  710. yygotominor.yy14 = NCDConfig_make_list_string(yymsp[0].minor.yy0, NULL);
  711. if (!yygotominor.yy14) {
  712. parser_out->out_of_memory = 1;
  713. }
  714. }
  715. #line 756 "NCDValueParser_parse.c"
  716. break;
  717. case 7: /* value ::= list */
  718. #line 122 "NCDValueParser_parse.y"
  719. {
  720. yygotominor.yy14 = NCDConfig_make_list_list(yymsp[0].minor.yy14, NULL);
  721. if (!yygotominor.yy14) {
  722. parser_out->out_of_memory = 1;
  723. }
  724. }
  725. #line 766 "NCDValueParser_parse.c"
  726. break;
  727. default:
  728. break;
  729. };
  730. yygoto = yyRuleInfo[yyruleno].lhs;
  731. yysize = yyRuleInfo[yyruleno].nrhs;
  732. yypParser->yyidx -= yysize;
  733. yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  734. if( yyact < YYNSTATE ){
  735. #ifdef NDEBUG
  736. /* If we are not debugging and the reduce action popped at least
  737. ** one element off the stack, then we can push the new element back
  738. ** onto the stack here, and skip the stack overflow test in yy_shift().
  739. ** That gives a significant speed improvement. */
  740. if( yysize ){
  741. yypParser->yyidx++;
  742. yymsp -= yysize-1;
  743. yymsp->stateno = (YYACTIONTYPE)yyact;
  744. yymsp->major = (YYCODETYPE)yygoto;
  745. yymsp->minor = yygotominor;
  746. }else
  747. #endif
  748. {
  749. yy_shift(yypParser,yyact,yygoto,&yygotominor);
  750. }
  751. }else{
  752. assert( yyact == YYNSTATE + YYNRULE + 1 );
  753. yy_accept(yypParser);
  754. }
  755. }
  756. /*
  757. ** The following code executes when the parse fails
  758. */
  759. #ifndef YYNOERRORRECOVERY
  760. static void yy_parse_failed(
  761. yyParser *yypParser /* The parser */
  762. ){
  763. ParseARG_FETCH;
  764. #ifndef NDEBUG
  765. if( yyTraceFILE ){
  766. fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
  767. }
  768. #endif
  769. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  770. /* Here code is inserted which will be executed whenever the
  771. ** parser fails */
  772. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  773. }
  774. #endif /* YYNOERRORRECOVERY */
  775. /*
  776. ** The following code executes when a syntax error first occurs.
  777. */
  778. static void yy_syntax_error(
  779. yyParser *yypParser, /* The parser */
  780. int yymajor, /* The major type of the error token */
  781. YYMINORTYPE yyminor /* The minor type of the error token */
  782. ){
  783. ParseARG_FETCH;
  784. #define TOKEN (yyminor.yy0)
  785. #line 68 "NCDValueParser_parse.y"
  786. parser_out->syntax_error = 1;
  787. #line 831 "NCDValueParser_parse.c"
  788. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  789. }
  790. /*
  791. ** The following is executed when the parser accepts
  792. */
  793. static void yy_accept(
  794. yyParser *yypParser /* The parser */
  795. ){
  796. ParseARG_FETCH;
  797. #ifndef NDEBUG
  798. if( yyTraceFILE ){
  799. fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
  800. }
  801. #endif
  802. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  803. /* Here code is inserted which will be executed whenever the
  804. ** parser accepts */
  805. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  806. }
  807. /* The main parser program.
  808. ** The first argument is a pointer to a structure obtained from
  809. ** "ParseAlloc" which describes the current state of the parser.
  810. ** The second argument is the major token number. The third is
  811. ** the minor token. The fourth optional argument is whatever the
  812. ** user wants (and specified in the grammar) and is available for
  813. ** use by the action routines.
  814. **
  815. ** Inputs:
  816. ** <ul>
  817. ** <li> A pointer to the parser (an opaque structure.)
  818. ** <li> The major token number.
  819. ** <li> The minor token number.
  820. ** <li> An option argument of a grammar-specified type.
  821. ** </ul>
  822. **
  823. ** Outputs:
  824. ** None.
  825. */
  826. void Parse(
  827. void *yyp, /* The parser */
  828. int yymajor, /* The major token code number */
  829. ParseTOKENTYPE yyminor /* The value for the token */
  830. ParseARG_PDECL /* Optional %extra_argument parameter */
  831. ){
  832. YYMINORTYPE yyminorunion;
  833. int yyact; /* The parser action. */
  834. int yyendofinput; /* True if we are at the end of input */
  835. #ifdef YYERRORSYMBOL
  836. int yyerrorhit = 0; /* True if yymajor has invoked an error */
  837. #endif
  838. yyParser *yypParser; /* The parser */
  839. /* (re)initialize the parser, if necessary */
  840. yypParser = (yyParser*)yyp;
  841. if( yypParser->yyidx<0 ){
  842. #if YYSTACKDEPTH<=0
  843. if( yypParser->yystksz <=0 ){
  844. /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/
  845. yyminorunion = yyzerominor;
  846. yyStackOverflow(yypParser, &yyminorunion);
  847. return;
  848. }
  849. #endif
  850. yypParser->yyidx = 0;
  851. yypParser->yyerrcnt = -1;
  852. yypParser->yystack[0].stateno = 0;
  853. yypParser->yystack[0].major = 0;
  854. }
  855. yyminorunion.yy0 = yyminor;
  856. yyendofinput = (yymajor==0);
  857. ParseARG_STORE;
  858. #ifndef NDEBUG
  859. if( yyTraceFILE ){
  860. fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  861. }
  862. #endif
  863. do{
  864. yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
  865. if( yyact<YYNSTATE ){
  866. assert( !yyendofinput ); /* Impossible to shift the $ token */
  867. yy_shift(yypParser,yyact,yymajor,&yyminorunion);
  868. yypParser->yyerrcnt--;
  869. yymajor = YYNOCODE;
  870. }else if( yyact < YYNSTATE + YYNRULE ){
  871. yy_reduce(yypParser,yyact-YYNSTATE);
  872. }else{
  873. assert( yyact == YY_ERROR_ACTION );
  874. #ifdef YYERRORSYMBOL
  875. int yymx;
  876. #endif
  877. #ifndef NDEBUG
  878. if( yyTraceFILE ){
  879. fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
  880. }
  881. #endif
  882. #ifdef YYERRORSYMBOL
  883. /* A syntax error has occurred.
  884. ** The response to an error depends upon whether or not the
  885. ** grammar defines an error token "ERROR".
  886. **
  887. ** This is what we do if the grammar does define ERROR:
  888. **
  889. ** * Call the %syntax_error function.
  890. **
  891. ** * Begin popping the stack until we enter a state where
  892. ** it is legal to shift the error symbol, then shift
  893. ** the error symbol.
  894. **
  895. ** * Set the error count to three.
  896. **
  897. ** * Begin accepting and shifting new tokens. No new error
  898. ** processing will occur until three tokens have been
  899. ** shifted successfully.
  900. **
  901. */
  902. if( yypParser->yyerrcnt<0 ){
  903. yy_syntax_error(yypParser,yymajor,yyminorunion);
  904. }
  905. yymx = yypParser->yystack[yypParser->yyidx].major;
  906. if( yymx==YYERRORSYMBOL || yyerrorhit ){
  907. #ifndef NDEBUG
  908. if( yyTraceFILE ){
  909. fprintf(yyTraceFILE,"%sDiscard input token %s\n",
  910. yyTracePrompt,yyTokenName[yymajor]);
  911. }
  912. #endif
  913. yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
  914. yymajor = YYNOCODE;
  915. }else{
  916. while(
  917. yypParser->yyidx >= 0 &&
  918. yymx != YYERRORSYMBOL &&
  919. (yyact = yy_find_reduce_action(
  920. yypParser->yystack[yypParser->yyidx].stateno,
  921. YYERRORSYMBOL)) >= YYNSTATE
  922. ){
  923. yy_pop_parser_stack(yypParser);
  924. }
  925. if( yypParser->yyidx < 0 || yymajor==0 ){
  926. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  927. yy_parse_failed(yypParser);
  928. yymajor = YYNOCODE;
  929. }else if( yymx!=YYERRORSYMBOL ){
  930. YYMINORTYPE u2;
  931. u2.YYERRSYMDT = 0;
  932. yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
  933. }
  934. }
  935. yypParser->yyerrcnt = 3;
  936. yyerrorhit = 1;
  937. #elif defined(YYNOERRORRECOVERY)
  938. /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
  939. ** do any kind of error recovery. Instead, simply invoke the syntax
  940. ** error routine and continue going as if nothing had happened.
  941. **
  942. ** Applications can set this macro (for example inside %include) if
  943. ** they intend to abandon the parse upon the first syntax error seen.
  944. */
  945. yy_syntax_error(yypParser,yymajor,yyminorunion);
  946. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  947. yymajor = YYNOCODE;
  948. #else /* YYERRORSYMBOL is not defined */
  949. /* This is what we do if the grammar does not define ERROR:
  950. **
  951. ** * Report an error message, and throw away the input token.
  952. **
  953. ** * If the input token is $, then fail the parse.
  954. **
  955. ** As before, subsequent error messages are suppressed until
  956. ** three input tokens have been successfully shifted.
  957. */
  958. if( yypParser->yyerrcnt<=0 ){
  959. yy_syntax_error(yypParser,yymajor,yyminorunion);
  960. }
  961. yypParser->yyerrcnt = 3;
  962. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  963. if( yyendofinput ){
  964. yy_parse_failed(yypParser);
  965. }
  966. yymajor = YYNOCODE;
  967. #endif
  968. }
  969. }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
  970. return;
  971. }