NCDConfigParser_parse.c 41 KB

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