NCDConfigParser_parse.c 40 KB

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