NCDValueParser_parse.c 32 KB

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