NCDConfigParser_parse.c 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198
  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 0
  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. #line 62 "NCDConfigParser_parse.y"
  580. if (yypMinor) {
  581. free(yypMinor->yy0);
  582. }
  583. #line 614 "NCDConfigParser_parse.c"
  584. ParseARG_STORE; /* Suppress warning about unused %extra_argument var */
  585. }
  586. /*
  587. ** Perform a shift action.
  588. */
  589. static void yy_shift(
  590. yyParser *yypParser, /* The parser to be shifted */
  591. int yyNewState, /* The new state to shift in */
  592. int yyMajor, /* The major token to shift in */
  593. YYMINORTYPE *yypMinor /* Pointer to the minor token to shift in */
  594. ){
  595. yyStackEntry *yytos;
  596. yypParser->yyidx++;
  597. #ifdef YYTRACKMAXSTACKDEPTH
  598. if( yypParser->yyidx>yypParser->yyidxMax ){
  599. yypParser->yyidxMax = yypParser->yyidx;
  600. }
  601. #endif
  602. #if YYSTACKDEPTH>0
  603. if( yypParser->yyidx>=YYSTACKDEPTH ){
  604. yyStackOverflow(yypParser, yypMinor);
  605. return;
  606. }
  607. #else
  608. if( yypParser->yyidx>=yypParser->yystksz ){
  609. yyGrowStack(yypParser);
  610. if( yypParser->yyidx>=yypParser->yystksz ){
  611. yyStackOverflow(yypParser, yypMinor);
  612. return;
  613. }
  614. }
  615. #endif
  616. yytos = &yypParser->yystack[yypParser->yyidx];
  617. yytos->stateno = (YYACTIONTYPE)yyNewState;
  618. yytos->major = (YYCODETYPE)yyMajor;
  619. yytos->minor = *yypMinor;
  620. #ifndef NDEBUG
  621. if( yyTraceFILE && yypParser->yyidx>0 ){
  622. int i;
  623. fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
  624. fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
  625. for(i=1; i<=yypParser->yyidx; i++)
  626. fprintf(yyTraceFILE," %s",yyTokenName[yypParser->yystack[i].major]);
  627. fprintf(yyTraceFILE,"\n");
  628. }
  629. #endif
  630. }
  631. /* The following table contains information about every rule that
  632. ** is used during the reduce.
  633. */
  634. static const struct {
  635. YYCODETYPE lhs; /* Symbol on the left-hand side of the rule */
  636. unsigned char nrhs; /* Number of right-hand side symbols in the rule */
  637. } yyRuleInfo[] = {
  638. { 16, 1 },
  639. { 12, 5 },
  640. { 12, 6 },
  641. { 13, 4 },
  642. { 13, 5 },
  643. { 13, 5 },
  644. { 13, 6 },
  645. { 13, 5 },
  646. { 13, 6 },
  647. { 13, 6 },
  648. { 13, 7 },
  649. { 14, 1 },
  650. { 14, 3 },
  651. { 15, 1 },
  652. { 15, 1 },
  653. { 15, 3 },
  654. { 15, 3 },
  655. };
  656. static void yy_accept(yyParser*); /* Forward Declaration */
  657. /*
  658. ** Perform a reduce action and the shift that must immediately
  659. ** follow the reduce.
  660. */
  661. static void yy_reduce(
  662. yyParser *yypParser, /* The parser */
  663. int yyruleno /* Number of the rule by which to reduce */
  664. ){
  665. int yygoto; /* The next state */
  666. int yyact; /* The next action */
  667. YYMINORTYPE yygotominor; /* The LHS of the rule reduced */
  668. yyStackEntry *yymsp; /* The top of the parser's stack */
  669. int yysize; /* Amount to pop the stack */
  670. ParseARG_FETCH;
  671. yymsp = &yypParser->yystack[yypParser->yyidx];
  672. #ifndef NDEBUG
  673. if( yyTraceFILE && yyruleno>=0
  674. && yyruleno<(int)(sizeof(yyRuleName)/sizeof(yyRuleName[0])) ){
  675. fprintf(yyTraceFILE, "%sReduce [%s].\n", yyTracePrompt,
  676. yyRuleName[yyruleno]);
  677. }
  678. #endif /* NDEBUG */
  679. /* Silence complaints from purify about yygotominor being uninitialized
  680. ** in some cases when it is copied into the stack after the following
  681. ** switch. yygotominor is uninitialized when a rule reduces that does
  682. ** not set the value of its left-hand side nonterminal. Leaving the
  683. ** value of the nonterminal uninitialized is utterly harmless as long
  684. ** as the value is never used. So really the only thing this code
  685. ** accomplishes is to quieten purify.
  686. **
  687. ** 2007-01-16: The wireshark project (www.wireshark.org) reports that
  688. ** without this code, their parser segfaults. I'm not sure what there
  689. ** parser is doing to make this happen. This is the second bug report
  690. ** from wireshark this week. Clearly they are stressing Lemon in ways
  691. ** that it has not been previously stressed... (SQLite ticket #2172)
  692. */
  693. /*memset(&yygotominor, 0, sizeof(yygotominor));*/
  694. yygotominor = yyzerominor;
  695. switch( yyruleno ){
  696. /* Beginning here are the reduction cases. A typical example
  697. ** follows:
  698. ** case 0:
  699. ** #line <lineno> <grammarfile>
  700. ** { ... } // User supplied code
  701. ** #line <lineno> <thisfile>
  702. ** break;
  703. */
  704. case 0: /* input ::= interfaces */
  705. #line 68 "NCDConfigParser_parse.y"
  706. {
  707. parser_out->ast = yymsp[0].minor.yy32;
  708. if (!yymsp[0].minor.yy32) {
  709. parser_out->out_of_memory = 1;
  710. }
  711. }
  712. #line 751 "NCDConfigParser_parse.c"
  713. break;
  714. case 1: /* interfaces ::= PROCESS NAME CURLY_OPEN statements CURLY_CLOSE */
  715. #line 76 "NCDConfigParser_parse.y"
  716. {
  717. yygotominor.yy32 = NCDConfig_make_interfaces(yymsp[-3].minor.yy0, yymsp[-1].minor.yy18, 0, NULL);
  718. if (!yygotominor.yy32) {
  719. parser_out->out_of_memory = 1;
  720. }
  721. yy_destructor(yypParser,1,&yymsp[-4].minor);
  722. yy_destructor(yypParser,3,&yymsp[-2].minor);
  723. yy_destructor(yypParser,4,&yymsp[0].minor);
  724. }
  725. #line 764 "NCDConfigParser_parse.c"
  726. break;
  727. case 2: /* interfaces ::= PROCESS NAME CURLY_OPEN statements CURLY_CLOSE interfaces */
  728. #line 83 "NCDConfigParser_parse.y"
  729. {
  730. yygotominor.yy32 = NCDConfig_make_interfaces(yymsp[-4].minor.yy0, yymsp[-2].minor.yy18, 1, yymsp[0].minor.yy32);
  731. if (!yygotominor.yy32) {
  732. parser_out->out_of_memory = 1;
  733. }
  734. yy_destructor(yypParser,1,&yymsp[-5].minor);
  735. yy_destructor(yypParser,3,&yymsp[-3].minor);
  736. yy_destructor(yypParser,4,&yymsp[-1].minor);
  737. }
  738. #line 777 "NCDConfigParser_parse.c"
  739. break;
  740. case 3: /* statements ::= statement_names ROUND_OPEN ROUND_CLOSE SEMICOLON */
  741. #line 90 "NCDConfigParser_parse.y"
  742. {
  743. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-3].minor.yy10, NULL, NULL, NULL);
  744. if (!yygotominor.yy18) {
  745. parser_out->out_of_memory = 1;
  746. }
  747. yy_destructor(yypParser,5,&yymsp[-2].minor);
  748. yy_destructor(yypParser,6,&yymsp[-1].minor);
  749. yy_destructor(yypParser,7,&yymsp[0].minor);
  750. }
  751. #line 790 "NCDConfigParser_parse.c"
  752. break;
  753. case 4: /* statements ::= statement_names ROUND_OPEN statement_args ROUND_CLOSE SEMICOLON */
  754. #line 97 "NCDConfigParser_parse.y"
  755. {
  756. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-4].minor.yy10, yymsp[-2].minor.yy34, NULL, NULL);
  757. if (!yygotominor.yy18) {
  758. parser_out->out_of_memory = 1;
  759. }
  760. yy_destructor(yypParser,5,&yymsp[-3].minor);
  761. yy_destructor(yypParser,6,&yymsp[-1].minor);
  762. yy_destructor(yypParser,7,&yymsp[0].minor);
  763. }
  764. #line 803 "NCDConfigParser_parse.c"
  765. break;
  766. case 5: /* statements ::= statement_names ROUND_OPEN ROUND_CLOSE SEMICOLON statements */
  767. #line 104 "NCDConfigParser_parse.y"
  768. {
  769. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-4].minor.yy10, NULL, NULL, yymsp[0].minor.yy18);
  770. if (!yygotominor.yy18) {
  771. parser_out->out_of_memory = 1;
  772. }
  773. yy_destructor(yypParser,5,&yymsp[-3].minor);
  774. yy_destructor(yypParser,6,&yymsp[-2].minor);
  775. yy_destructor(yypParser,7,&yymsp[-1].minor);
  776. }
  777. #line 816 "NCDConfigParser_parse.c"
  778. break;
  779. case 6: /* statements ::= statement_names ROUND_OPEN statement_args ROUND_CLOSE SEMICOLON statements */
  780. #line 111 "NCDConfigParser_parse.y"
  781. {
  782. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-5].minor.yy10, yymsp[-3].minor.yy34, NULL, yymsp[0].minor.yy18);
  783. if (!yygotominor.yy18) {
  784. parser_out->out_of_memory = 1;
  785. }
  786. yy_destructor(yypParser,5,&yymsp[-4].minor);
  787. yy_destructor(yypParser,6,&yymsp[-2].minor);
  788. yy_destructor(yypParser,7,&yymsp[-1].minor);
  789. }
  790. #line 829 "NCDConfigParser_parse.c"
  791. break;
  792. case 7: /* statements ::= statement_names ROUND_OPEN ROUND_CLOSE NAME SEMICOLON */
  793. #line 118 "NCDConfigParser_parse.y"
  794. {
  795. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-4].minor.yy10, NULL, yymsp[-1].minor.yy0, NULL);
  796. if (!yygotominor.yy18) {
  797. parser_out->out_of_memory = 1;
  798. }
  799. yy_destructor(yypParser,5,&yymsp[-3].minor);
  800. yy_destructor(yypParser,6,&yymsp[-2].minor);
  801. yy_destructor(yypParser,7,&yymsp[0].minor);
  802. }
  803. #line 842 "NCDConfigParser_parse.c"
  804. break;
  805. case 8: /* statements ::= statement_names ROUND_OPEN statement_args ROUND_CLOSE NAME SEMICOLON */
  806. #line 125 "NCDConfigParser_parse.y"
  807. {
  808. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-5].minor.yy10, yymsp[-3].minor.yy34, yymsp[-1].minor.yy0, NULL);
  809. if (!yygotominor.yy18) {
  810. parser_out->out_of_memory = 1;
  811. }
  812. yy_destructor(yypParser,5,&yymsp[-4].minor);
  813. yy_destructor(yypParser,6,&yymsp[-2].minor);
  814. yy_destructor(yypParser,7,&yymsp[0].minor);
  815. }
  816. #line 855 "NCDConfigParser_parse.c"
  817. break;
  818. case 9: /* statements ::= statement_names ROUND_OPEN ROUND_CLOSE NAME SEMICOLON statements */
  819. #line 132 "NCDConfigParser_parse.y"
  820. {
  821. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-5].minor.yy10, NULL, yymsp[-2].minor.yy0, yymsp[0].minor.yy18);
  822. if (!yygotominor.yy18) {
  823. parser_out->out_of_memory = 1;
  824. }
  825. yy_destructor(yypParser,5,&yymsp[-4].minor);
  826. yy_destructor(yypParser,6,&yymsp[-3].minor);
  827. yy_destructor(yypParser,7,&yymsp[-1].minor);
  828. }
  829. #line 868 "NCDConfigParser_parse.c"
  830. break;
  831. case 10: /* statements ::= statement_names ROUND_OPEN statement_args ROUND_CLOSE NAME SEMICOLON statements */
  832. #line 139 "NCDConfigParser_parse.y"
  833. {
  834. yygotominor.yy18 = NCDConfig_make_statements(yymsp[-6].minor.yy10, yymsp[-4].minor.yy34, yymsp[-2].minor.yy0, yymsp[0].minor.yy18);
  835. if (!yygotominor.yy18) {
  836. parser_out->out_of_memory = 1;
  837. }
  838. yy_destructor(yypParser,5,&yymsp[-5].minor);
  839. yy_destructor(yypParser,6,&yymsp[-3].minor);
  840. yy_destructor(yypParser,7,&yymsp[-1].minor);
  841. }
  842. #line 881 "NCDConfigParser_parse.c"
  843. break;
  844. case 11: /* statement_names ::= NAME */
  845. #line 146 "NCDConfigParser_parse.y"
  846. {
  847. yygotominor.yy10 = NCDConfig_make_strings(yymsp[0].minor.yy0, 0, NULL);
  848. if (!yygotominor.yy10) {
  849. parser_out->out_of_memory = 1;
  850. }
  851. }
  852. #line 891 "NCDConfigParser_parse.c"
  853. break;
  854. case 12: /* statement_names ::= NAME DOT statement_names */
  855. #line 153 "NCDConfigParser_parse.y"
  856. {
  857. yygotominor.yy10 = NCDConfig_make_strings(yymsp[-2].minor.yy0, 1, yymsp[0].minor.yy10);
  858. if (!yygotominor.yy10) {
  859. parser_out->out_of_memory = 1;
  860. }
  861. yy_destructor(yypParser,8,&yymsp[-1].minor);
  862. }
  863. #line 902 "NCDConfigParser_parse.c"
  864. break;
  865. case 13: /* statement_args ::= STRING */
  866. #line 160 "NCDConfigParser_parse.y"
  867. {
  868. yygotominor.yy34 = NCDConfig_make_arguments_string(yymsp[0].minor.yy0, 0, NULL);
  869. if (!yygotominor.yy34) {
  870. parser_out->out_of_memory = 1;
  871. }
  872. }
  873. #line 912 "NCDConfigParser_parse.c"
  874. break;
  875. case 14: /* statement_args ::= statement_names */
  876. #line 167 "NCDConfigParser_parse.y"
  877. {
  878. yygotominor.yy34 = NCDConfig_make_arguments_var(yymsp[0].minor.yy10, 0, NULL);
  879. if (!yygotominor.yy34) {
  880. parser_out->out_of_memory = 1;
  881. }
  882. }
  883. #line 922 "NCDConfigParser_parse.c"
  884. break;
  885. case 15: /* statement_args ::= STRING COMMA statement_args */
  886. #line 174 "NCDConfigParser_parse.y"
  887. {
  888. yygotominor.yy34 = NCDConfig_make_arguments_string(yymsp[-2].minor.yy0, 1, yymsp[0].minor.yy34);
  889. if (!yygotominor.yy34) {
  890. parser_out->out_of_memory = 1;
  891. }
  892. yy_destructor(yypParser,10,&yymsp[-1].minor);
  893. }
  894. #line 933 "NCDConfigParser_parse.c"
  895. break;
  896. case 16: /* statement_args ::= statement_names COMMA statement_args */
  897. #line 181 "NCDConfigParser_parse.y"
  898. {
  899. yygotominor.yy34 = NCDConfig_make_arguments_var(yymsp[-2].minor.yy10, 1, yymsp[0].minor.yy34);
  900. if (!yygotominor.yy34) {
  901. parser_out->out_of_memory = 1;
  902. }
  903. yy_destructor(yypParser,10,&yymsp[-1].minor);
  904. }
  905. #line 944 "NCDConfigParser_parse.c"
  906. break;
  907. default:
  908. break;
  909. };
  910. yygoto = yyRuleInfo[yyruleno].lhs;
  911. yysize = yyRuleInfo[yyruleno].nrhs;
  912. yypParser->yyidx -= yysize;
  913. yyact = yy_find_reduce_action(yymsp[-yysize].stateno,(YYCODETYPE)yygoto);
  914. if( yyact < YYNSTATE ){
  915. #ifdef NDEBUG
  916. /* If we are not debugging and the reduce action popped at least
  917. ** one element off the stack, then we can push the new element back
  918. ** onto the stack here, and skip the stack overflow test in yy_shift().
  919. ** That gives a significant speed improvement. */
  920. if( yysize ){
  921. yypParser->yyidx++;
  922. yymsp -= yysize-1;
  923. yymsp->stateno = (YYACTIONTYPE)yyact;
  924. yymsp->major = (YYCODETYPE)yygoto;
  925. yymsp->minor = yygotominor;
  926. }else
  927. #endif
  928. {
  929. yy_shift(yypParser,yyact,yygoto,&yygotominor);
  930. }
  931. }else{
  932. assert( yyact == YYNSTATE + YYNRULE + 1 );
  933. yy_accept(yypParser);
  934. }
  935. }
  936. /*
  937. ** The following code executes when the parse fails
  938. */
  939. #ifndef YYNOERRORRECOVERY
  940. static void yy_parse_failed(
  941. yyParser *yypParser /* The parser */
  942. ){
  943. ParseARG_FETCH;
  944. #ifndef NDEBUG
  945. if( yyTraceFILE ){
  946. fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
  947. }
  948. #endif
  949. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  950. /* Here code is inserted which will be executed whenever the
  951. ** parser fails */
  952. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  953. }
  954. #endif /* YYNOERRORRECOVERY */
  955. /*
  956. ** The following code executes when a syntax error first occurs.
  957. */
  958. static void yy_syntax_error(
  959. yyParser *yypParser, /* The parser */
  960. int yymajor, /* The major type of the error token */
  961. YYMINORTYPE yyminor /* The minor type of the error token */
  962. ){
  963. ParseARG_FETCH;
  964. #define TOKEN (yyminor.yy0)
  965. #line 57 "NCDConfigParser_parse.y"
  966. parser_out->syntax_error = 1;
  967. #line 1009 "NCDConfigParser_parse.c"
  968. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  969. }
  970. /*
  971. ** The following is executed when the parser accepts
  972. */
  973. static void yy_accept(
  974. yyParser *yypParser /* The parser */
  975. ){
  976. ParseARG_FETCH;
  977. #ifndef NDEBUG
  978. if( yyTraceFILE ){
  979. fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
  980. }
  981. #endif
  982. while( yypParser->yyidx>=0 ) yy_pop_parser_stack(yypParser);
  983. /* Here code is inserted which will be executed whenever the
  984. ** parser accepts */
  985. ParseARG_STORE; /* Suppress warning about unused %extra_argument variable */
  986. }
  987. /* The main parser program.
  988. ** The first argument is a pointer to a structure obtained from
  989. ** "ParseAlloc" which describes the current state of the parser.
  990. ** The second argument is the major token number. The third is
  991. ** the minor token. The fourth optional argument is whatever the
  992. ** user wants (and specified in the grammar) and is available for
  993. ** use by the action routines.
  994. **
  995. ** Inputs:
  996. ** <ul>
  997. ** <li> A pointer to the parser (an opaque structure.)
  998. ** <li> The major token number.
  999. ** <li> The minor token number.
  1000. ** <li> An option argument of a grammar-specified type.
  1001. ** </ul>
  1002. **
  1003. ** Outputs:
  1004. ** None.
  1005. */
  1006. void Parse(
  1007. void *yyp, /* The parser */
  1008. int yymajor, /* The major token code number */
  1009. ParseTOKENTYPE yyminor /* The value for the token */
  1010. ParseARG_PDECL /* Optional %extra_argument parameter */
  1011. ){
  1012. YYMINORTYPE yyminorunion;
  1013. int yyact; /* The parser action. */
  1014. int yyendofinput; /* True if we are at the end of input */
  1015. #ifdef YYERRORSYMBOL
  1016. int yyerrorhit = 0; /* True if yymajor has invoked an error */
  1017. #endif
  1018. yyParser *yypParser; /* The parser */
  1019. /* (re)initialize the parser, if necessary */
  1020. yypParser = (yyParser*)yyp;
  1021. if( yypParser->yyidx<0 ){
  1022. #if YYSTACKDEPTH<=0
  1023. if( yypParser->yystksz <=0 ){
  1024. /*memset(&yyminorunion, 0, sizeof(yyminorunion));*/
  1025. yyminorunion = yyzerominor;
  1026. yyStackOverflow(yypParser, &yyminorunion);
  1027. return;
  1028. }
  1029. #endif
  1030. yypParser->yyidx = 0;
  1031. yypParser->yyerrcnt = -1;
  1032. yypParser->yystack[0].stateno = 0;
  1033. yypParser->yystack[0].major = 0;
  1034. }
  1035. yyminorunion.yy0 = yyminor;
  1036. yyendofinput = (yymajor==0);
  1037. ParseARG_STORE;
  1038. #ifndef NDEBUG
  1039. if( yyTraceFILE ){
  1040. fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  1041. }
  1042. #endif
  1043. do{
  1044. yyact = yy_find_shift_action(yypParser,(YYCODETYPE)yymajor);
  1045. if( yyact<YYNSTATE ){
  1046. assert( !yyendofinput ); /* Impossible to shift the $ token */
  1047. yy_shift(yypParser,yyact,yymajor,&yyminorunion);
  1048. yypParser->yyerrcnt--;
  1049. yymajor = YYNOCODE;
  1050. }else if( yyact < YYNSTATE + YYNRULE ){
  1051. yy_reduce(yypParser,yyact-YYNSTATE);
  1052. }else{
  1053. assert( yyact == YY_ERROR_ACTION );
  1054. #ifdef YYERRORSYMBOL
  1055. int yymx;
  1056. #endif
  1057. #ifndef NDEBUG
  1058. if( yyTraceFILE ){
  1059. fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
  1060. }
  1061. #endif
  1062. #ifdef YYERRORSYMBOL
  1063. /* A syntax error has occurred.
  1064. ** The response to an error depends upon whether or not the
  1065. ** grammar defines an error token "ERROR".
  1066. **
  1067. ** This is what we do if the grammar does define ERROR:
  1068. **
  1069. ** * Call the %syntax_error function.
  1070. **
  1071. ** * Begin popping the stack until we enter a state where
  1072. ** it is legal to shift the error symbol, then shift
  1073. ** the error symbol.
  1074. **
  1075. ** * Set the error count to three.
  1076. **
  1077. ** * Begin accepting and shifting new tokens. No new error
  1078. ** processing will occur until three tokens have been
  1079. ** shifted successfully.
  1080. **
  1081. */
  1082. if( yypParser->yyerrcnt<0 ){
  1083. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1084. }
  1085. yymx = yypParser->yystack[yypParser->yyidx].major;
  1086. if( yymx==YYERRORSYMBOL || yyerrorhit ){
  1087. #ifndef NDEBUG
  1088. if( yyTraceFILE ){
  1089. fprintf(yyTraceFILE,"%sDiscard input token %s\n",
  1090. yyTracePrompt,yyTokenName[yymajor]);
  1091. }
  1092. #endif
  1093. yy_destructor(yypParser, (YYCODETYPE)yymajor,&yyminorunion);
  1094. yymajor = YYNOCODE;
  1095. }else{
  1096. while(
  1097. yypParser->yyidx >= 0 &&
  1098. yymx != YYERRORSYMBOL &&
  1099. (yyact = yy_find_reduce_action(
  1100. yypParser->yystack[yypParser->yyidx].stateno,
  1101. YYERRORSYMBOL)) >= YYNSTATE
  1102. ){
  1103. yy_pop_parser_stack(yypParser);
  1104. }
  1105. if( yypParser->yyidx < 0 || yymajor==0 ){
  1106. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1107. yy_parse_failed(yypParser);
  1108. yymajor = YYNOCODE;
  1109. }else if( yymx!=YYERRORSYMBOL ){
  1110. YYMINORTYPE u2;
  1111. u2.YYERRSYMDT = 0;
  1112. yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
  1113. }
  1114. }
  1115. yypParser->yyerrcnt = 3;
  1116. yyerrorhit = 1;
  1117. #elif defined(YYNOERRORRECOVERY)
  1118. /* If the YYNOERRORRECOVERY macro is defined, then do not attempt to
  1119. ** do any kind of error recovery. Instead, simply invoke the syntax
  1120. ** error routine and continue going as if nothing had happened.
  1121. **
  1122. ** Applications can set this macro (for example inside %include) if
  1123. ** they intend to abandon the parse upon the first syntax error seen.
  1124. */
  1125. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1126. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1127. yymajor = YYNOCODE;
  1128. #else /* YYERRORSYMBOL is not defined */
  1129. /* This is what we do if the grammar does not define ERROR:
  1130. **
  1131. ** * Report an error message, and throw away the input token.
  1132. **
  1133. ** * If the input token is $, then fail the parse.
  1134. **
  1135. ** As before, subsequent error messages are suppressed until
  1136. ** three input tokens have been successfully shifted.
  1137. */
  1138. if( yypParser->yyerrcnt<=0 ){
  1139. yy_syntax_error(yypParser,yymajor,yyminorunion);
  1140. }
  1141. yypParser->yyerrcnt = 3;
  1142. yy_destructor(yypParser,(YYCODETYPE)yymajor,&yyminorunion);
  1143. if( yyendofinput ){
  1144. yy_parse_failed(yypParser);
  1145. }
  1146. yymajor = YYNOCODE;
  1147. #endif
  1148. }
  1149. }while( yymajor!=YYNOCODE && yypParser->yyidx>=0 );
  1150. return;
  1151. }