NCDConfigParser_parse.c 39 KB

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