NCDConfigParser_parse.c 40 KB

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