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