/* Driver template for the LEMON parser generator.
** Copyright 1991-1995 by D. Richard Hipp.
**
** This library is free software; you can redistribute it and/or
** modify it under the terms of the GNU Library General Public
** License as published by the Free Software Foundation; either
** version 2 of the License, or (at your option) any later version.
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
** Library General Public License for more details.
**
** You should have received a copy of the GNU Library General Public
** License along with this library; if not, write to the
** Free Software Foundation, Inc., 59 Temple Place - Suite 330,
** Boston, MA  02111-1307, USA.
**
** Modified 1997 to make it suitable for use with makeheaders.
*/
/* First off, code is include which follows the "include" declaration
** in the input file. */
#line 1 "./dtd_grammar.lemon"


/* dtd_parser.lemon
* XML dissector for ethereal 
* XML's DTD grammar
*
* Copyright 2005, Luis E. Garcia Ontanon <luis.ontanon@gmail.com>
*
* $Id: dtd_grammar.lemon 16147 2005-10-06 22:01:52Z lego $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

#include <stdio.h>
#include <glib.h>
#include "dtd.h"
#include "dtd_parse.h"

static dtd_named_list_t* dtd_named_list_new(gchar* name, GPtrArray* list) {
	dtd_named_list_t* nl = g_malloc(sizeof(dtd_named_list_t));

	nl->name = name;
	nl->list = list;
	
	return nl;
}

static GPtrArray* g_ptr_array_join(GPtrArray* a, GPtrArray* b){
	
	while(b->len > 0) {
		g_ptr_array_add(a,g_ptr_array_remove_index_fast(b,0));
	}
	
	g_ptr_array_free(b,TRUE);

	return a;
}


#line 80 "dtd_grammar.c"
#include <stdio.h>
/* Next is all token values, in a form suitable for use by makeheaders.
** This section will be null unless lemon is run with the -m switch.
*/
/*
** These constants (all generated automatically by the parser generator)
** specify the various kinds of tokens (terminals) that the parser
** understands.
**
** Each symbol here is a terminal symbol in the grammar.
*/
/* Make sure the INTERFACE macro is defined.
*/
#ifndef INTERFACE
# define INTERFACE 1
#endif
/* The next thing included is series of defines which control
** various aspects of the generated parser.
**    YYCODETYPE         is the data type used for storing terminal
**                       and nonterminal numbers.  "unsigned char" is
**                       used if there are fewer than 250 terminals
**                       and nonterminals.  "int" is used otherwise.
**    YYNOCODE           is a number of type YYCODETYPE which corresponds
**                       to no legal terminal or nonterminal number.  This
**                       number is used to fill in empty slots of the hash
**                       table.
**    YYACTIONTYPE       is the data type used for storing terminal
**                       and nonterminal numbers.  "unsigned char" is
**                       used if there are fewer than 250 rules and
**                       states combined.  "int" is used otherwise.
**    DtdParseTOKENTYPE     is the data type used for minor tokens given
**                       directly to the parser from the tokenizer.
**    YYMINORTYPE        is the data type used for all minor tokens.
**                       This is typically a union of many types, one of
**                       which is DtdParseTOKENTYPE.  The entry in the union
**                       for base tokens is called "yy0".
**    YYSTACKDEPTH       is the maximum depth of the parser's stack.
**    DtdParseARGDECL       is a declaration of a 3rd argument to the
**                       parser, or null if there is no extra argument.
**    DtdParseKRARGDECL     A version of DtdParseARGDECL for K&R C.
**    DtdParseANSIARGDECL   A version of DtdParseARGDECL for ANSI C.
**    YYNSTATE           the combined number of states.
**    YYNRULE            the number of rules in the grammar
**    YYERRORSYMBOL      is the code number of the error symbol.  If not
**                       defined, then do no error processing.
*/
/*  */
#define YYCODETYPE unsigned char
#define YYNOCODE 41
#define YYACTIONTYPE unsigned char
#define DtdParseTOKENTYPE  dtd_token_data_t* 
typedef union {
  DtdParseTOKENTYPE yy0;
  dtd_named_list_t* yy21;
  gchar* yy44;
  GPtrArray* yy71;
  int yy81;
} YYMINORTYPE;
#define YYSTACKDEPTH 100
#define DtdParseARGDECL ,bd 
#define DtdParseXARGDECL  dtd_build_data_t *bd ;
#define DtdParseANSIARGDECL , dtd_build_data_t *bd 
#define YYNSTATE 71
#define YYNRULE 44
#define YYERRORSYMBOL 38
#define YYERRSYMDT yy81
#define YY_NO_ACTION      (YYNSTATE+YYNRULE+2)
#define YY_ACCEPT_ACTION  (YYNSTATE+YYNRULE+1)
#define YY_ERROR_ACTION   (YYNSTATE+YYNRULE)
/* Next is the action table.  Each entry in this table contains
**
**  +  An integer which is the number representing the look-ahead
**     token
**
**  +  An integer indicating what action to take.  Number (N) between
**     0 and YYNSTATE-1 mean shift the look-ahead and go to state N.
**     Numbers between YYNSTATE and YYNSTATE+YYNRULE-1 mean reduce by
**     rule N-YYNSTATE.  Number YYNSTATE+YYNRULE means that a syntax
**     error has occurred.  Number YYNSTATE+YYNRULE+1 means the parser
**     accepts its input.
**
**  +  A pointer to the next entry with the same hash value.
**
** The action table is really a series of hash tables.  Each hash
** table contains a number of entries which is a power of two.  The
** "state" table (which follows) contains information about the starting
** point and size of each hash table.
*/
struct yyActionEntry {
  YYCODETYPE   lookahead;   /* The value of the look-ahead token */
  YYACTIONTYPE action;      /* Action to take for this look-ahead */
  struct yyActionEntry *next; /* Next look-ahead with the same hash, or NULL */
};
static struct yyActionEntry yyActionTable[] = {
/* State 0 */
  {  32,  69, 0                    }, /*                element shift  69 */
  {  22,  62, 0                    }, /*              TAG_START shift  62 */
  {  26,  70, 0                    }, /*                attlist shift  70 */
  {YYNOCODE,0,0}, /* Unused */
  {YYNOCODE,0,0}, /* Unused */
  {  29,   1, 0                    }, /*                doctype shift  1 */
  {  30, 116, &yyActionTable[   1] }, /*                    dtd accept */
  {  31,   2, 0                    }, /*              dtd_parts shift  2 */
/* State 1 */
  {   0,  71, 0                    }, /*                      $ reduce 0 */
/* State 2 */
  {  32,   3, &yyActionTable[  10] }, /*                element shift  3 */
  {   0,  72, 0                    }, /*                      $ reduce 1 */
  {  26,   4, &yyActionTable[  12] }, /*                attlist shift  4 */
  {  22,   5, 0                    }, /*              TAG_START shift  5 */
/* State 3 */
  {YYNOCODE,0,0}, /* Unused */
/* State 4 */
  {YYNOCODE,0,0}, /* Unused */
/* State 5 */
  {   1,   6, 0                    }, /*             ATTLIST_KW shift  6 */
  {   9,  33, &yyActionTable[  15] }, /*             ELEMENT_KW shift  33 */
/* State 6 */
  {  13,   7, 0                    }, /*                   NAME shift  7 */
/* State 7 */
  {  28,   8, 0                    }, /*            attrib_list shift  8 */
  {  13,  11, 0                    }, /*                   NAME shift  11 */
  {YYNOCODE,0,0}, /* Unused */
  {  27,  32, 0                    }, /*                 attrib shift  32 */
/* State 8 */
  {  23,   9, 0                    }, /*               TAG_STOP shift  9 */
  {  13,  11, 0                    }, /*                   NAME shift  11 */
  {YYNOCODE,0,0}, /* Unused */
  {  27,  10, &yyActionTable[  22] }, /*                 attrib shift  10 */
/* State 9 */
  {YYNOCODE,0,0}, /* Unused */
/* State 10 */
  {YYNOCODE,0,0}, /* Unused */
/* State 11 */
  {   4,  20, 0                    }, /*               ATT_TYPE shift  20 */
  {  37,  21, &yyActionTable[  30] }, /*            enumeration shift  21 */
  {  25,  12, 0                    }, /*               att_type shift  12 */
  {  15,  22, 0                    }, /*            OPEN_PARENS shift  22 */
/* State 12 */
  {  24,  13, 0                    }, /*            att_default shift  13 */
  {   3,  15, 0                    }, /*     ATT_DEF_WITH_VALUE shift  15 */
  {   2,  14, 0                    }, /*                ATT_DEF shift  14 */
  {  19,  17, &yyActionTable[  33] }, /*                 QUOTED shift  17 */
  {  20,  19, &yyActionTable[  37] }, /*            REQUIRED_KW shift  19 */
  {  12,  18, 0                    }, /*             IMPLIED_KW shift  18 */
  {YYNOCODE,0,0}, /* Unused */
  {YYNOCODE,0,0}, /* Unused */
/* State 13 */
  {YYNOCODE,0,0}, /* Unused */
/* State 14 */
  {YYNOCODE,0,0}, /* Unused */
/* State 15 */
  {  19,  16, 0                    }, /*                 QUOTED shift  16 */
/* State 16 */
  {YYNOCODE,0,0}, /* Unused */
/* State 17 */
  {YYNOCODE,0,0}, /* Unused */
/* State 18 */
  {YYNOCODE,0,0}, /* Unused */
/* State 19 */
  {YYNOCODE,0,0}, /* Unused */
/* State 20 */
  {YYNOCODE,0,0}, /* Unused */
/* State 21 */
  {YYNOCODE,0,0}, /* Unused */
/* State 22 */
  {  19,  29, 0                    }, /*                 QUOTED shift  29 */
  {  13,  28, 0                    }, /*                   NAME shift  28 */
  {YYNOCODE,0,0}, /* Unused */
  {  35,  30, &yyActionTable[  49] }, /*              enum_item shift  30 */
  {  36,  23, 0                    }, /*              enum_list shift  23 */
  {  37,  31, &yyActionTable[  50] }, /*            enumeration shift  31 */
  {YYNOCODE,0,0}, /* Unused */
  {  15,  22, 0                    }, /*            OPEN_PARENS shift  22 */
/* State 23 */
  {  16,  25, &yyActionTable[  58] }, /*                   PIPE shift  25 */
  {   6,  24, 0                    }, /*           CLOSE_PARENS shift  24 */
/* State 24 */
  {YYNOCODE,0,0}, /* Unused */
/* State 25 */
  {  19,  29, 0                    }, /*                 QUOTED shift  29 */
  {  13,  28, 0                    }, /*                   NAME shift  28 */
  {YYNOCODE,0,0}, /* Unused */
  {  35,  26, &yyActionTable[  60] }, /*              enum_item shift  26 */
  {YYNOCODE,0,0}, /* Unused */
  {  37,  27, &yyActionTable[  61] }, /*            enumeration shift  27 */
  {YYNOCODE,0,0}, /* Unused */
  {  15,  22, 0                    }, /*            OPEN_PARENS shift  22 */
/* State 26 */
  {YYNOCODE,0,0}, /* Unused */
/* State 27 */
  {YYNOCODE,0,0}, /* Unused */
/* State 28 */
  {YYNOCODE,0,0}, /* Unused */
/* State 29 */
  {YYNOCODE,0,0}, /* Unused */
/* State 30 */
  {YYNOCODE,0,0}, /* Unused */
/* State 31 */
  {YYNOCODE,0,0}, /* Unused */
/* State 32 */
  {YYNOCODE,0,0}, /* Unused */
/* State 33 */
  {  13,  34, 0                    }, /*                   NAME shift  34 */
/* State 34 */
  {  15,  40, &yyActionTable[  77] }, /*            OPEN_PARENS shift  40 */
  {  11,  49, 0                    }, /*               EMPTY_KW shift  49 */
  {YYNOCODE,0,0}, /* Unused */
  {  39,  35, &yyActionTable[  76] }, /*           sub_elements shift  35 */
/* State 35 */
  {  17,  38, 0                    }, /*                   PLUS shift  38 */
  {  21,  37, &yyActionTable[  80] }, /*                   STAR shift  37 */
  {  18,  39, 0                    }, /*               QUESTION shift  39 */
  {  23,  36, 0                    }, /*               TAG_STOP shift  36 */
/* State 36 */
  {YYNOCODE,0,0}, /* Unused */
/* State 37 */
  {YYNOCODE,0,0}, /* Unused */
/* State 38 */
  {YYNOCODE,0,0}, /* Unused */
/* State 39 */
  {YYNOCODE,0,0}, /* Unused */
/* State 40 */
  {  10,  42, 0                    }, /*              ELEM_DATA shift  42 */
  {  33,  61, 0                    }, /*          element_child shift  61 */
  {  34,  44, &yyActionTable[  88] }, /*           element_list shift  44 */
  {  11,  49, 0                    }, /*               EMPTY_KW shift  49 */
  {  15,  40, 0                    }, /*            OPEN_PARENS shift  40 */
  {  13,  51, 0                    }, /*                   NAME shift  51 */
  {YYNOCODE,0,0}, /* Unused */
  {  39,  41, &yyActionTable[  92] }, /*           sub_elements shift  41 */
/* State 41 */
  {  17,  38, 0                    }, /*                   PLUS shift  38 */
  {  21,  37, &yyActionTable[  96] }, /*                   STAR shift  37 */
  {  18,  39, 0                    }, /*               QUESTION shift  39 */
  {YYNOCODE,0,0}, /* Unused */
/* State 42 */
  {   6,  43, 0                    }, /*           CLOSE_PARENS shift  43 */
/* State 43 */
  {YYNOCODE,0,0}, /* Unused */
/* State 44 */
  {  16,  55, 0                    }, /*                   PIPE shift  55 */
  {YYNOCODE,0,0}, /* Unused */
  {   6,  60, 0                    }, /*           CLOSE_PARENS shift  60 */
  {   7,  45, 0                    }, /*                  COMMA shift  45 */
/* State 45 */
  {  15,  40, 0                    }, /*            OPEN_PARENS shift  40 */
  {  33,  50, 0                    }, /*          element_child shift  50 */
  {  10,  47, 0                    }, /*              ELEM_DATA shift  47 */
  {  11,  49, 0                    }, /*               EMPTY_KW shift  49 */
  {YYNOCODE,0,0}, /* Unused */
  {  13,  51, 0                    }, /*                   NAME shift  51 */
  {YYNOCODE,0,0}, /* Unused */
  {  39,  46, &yyActionTable[ 106] }, /*           sub_elements shift  46 */
/* State 46 */
  {  17,  38, 0                    }, /*                   PLUS shift  38 */
  {  21,  37, &yyActionTable[ 114] }, /*                   STAR shift  37 */
  {  18,  39, 0                    }, /*               QUESTION shift  39 */
  {YYNOCODE,0,0}, /* Unused */
/* State 47 */
  {   6,  48, 0                    }, /*           CLOSE_PARENS shift  48 */
/* State 48 */
  {YYNOCODE,0,0}, /* Unused */
/* State 49 */
  {YYNOCODE,0,0}, /* Unused */
/* State 50 */
  {YYNOCODE,0,0}, /* Unused */
/* State 51 */
  {  17,  54, 0                    }, /*                   PLUS shift  54 */
  {  21,  52, &yyActionTable[ 122] }, /*                   STAR shift  52 */
  {  18,  53, 0                    }, /*               QUESTION shift  53 */
  {YYNOCODE,0,0}, /* Unused */
/* State 52 */
  {YYNOCODE,0,0}, /* Unused */
/* State 53 */
  {YYNOCODE,0,0}, /* Unused */
/* State 54 */
  {YYNOCODE,0,0}, /* Unused */
/* State 55 */
  {  15,  40, 0                    }, /*            OPEN_PARENS shift  40 */
  {  33,  59, 0                    }, /*          element_child shift  59 */
  {  10,  57, 0                    }, /*              ELEM_DATA shift  57 */
  {  11,  49, 0                    }, /*               EMPTY_KW shift  49 */
  {YYNOCODE,0,0}, /* Unused */
  {  13,  51, 0                    }, /*                   NAME shift  51 */
  {YYNOCODE,0,0}, /* Unused */
  {  39,  56, &yyActionTable[ 129] }, /*           sub_elements shift  56 */
/* State 56 */
  {  17,  38, 0                    }, /*                   PLUS shift  38 */
  {  21,  37, &yyActionTable[ 137] }, /*                   STAR shift  37 */
  {  18,  39, 0                    }, /*               QUESTION shift  39 */
  {YYNOCODE,0,0}, /* Unused */
/* State 57 */
  {   6,  58, 0                    }, /*           CLOSE_PARENS shift  58 */
/* State 58 */
  {YYNOCODE,0,0}, /* Unused */
/* State 59 */
  {YYNOCODE,0,0}, /* Unused */
/* State 60 */
  {YYNOCODE,0,0}, /* Unused */
/* State 61 */
  {YYNOCODE,0,0}, /* Unused */
/* State 62 */
  {   8,  63, 0                    }, /*             DOCTYPE_KW shift  63 */
  {   9,  33, &yyActionTable[ 148] }, /*             ELEMENT_KW shift  33 */
  {   1,   6, 0                    }, /*             ATTLIST_KW shift  6 */
  {YYNOCODE,0,0}, /* Unused */
/* State 63 */
  {  13,  64, 0                    }, /*                   NAME shift  64 */
/* State 64 */
  {  14,  65, 0                    }, /*           OPEN_BRACKET shift  65 */
/* State 65 */
  {  32,  69, 0                    }, /*                element shift  69 */
  {  22,   5, 0                    }, /*              TAG_START shift  5 */
  {  26,  70, &yyActionTable[ 153] }, /*                attlist shift  70 */
  {  31,  66, 0                    }, /*              dtd_parts shift  66 */
/* State 66 */
  {  32,   3, 0                    }, /*                element shift  3 */
  {   5,  67, 0                    }, /*          CLOSE_BRACKET shift  67 */
  {  26,   4, &yyActionTable[ 159] }, /*                attlist shift  4 */
  {  22,   5, 0                    }, /*              TAG_START shift  5 */
/* State 67 */
  {  23,  68, 0                    }, /*               TAG_STOP shift  68 */
/* State 68 */
  {   0,  73, 0                    }, /*                      $ reduce 2 */
/* State 69 */
  {YYNOCODE,0,0}, /* Unused */
/* State 70 */
  {YYNOCODE,0,0}, /* Unused */
};

/* The state table contains information needed to look up the correct
** action in the action table, given the current state of the parser.
** Information needed includes:
**
**  +  A pointer to the start of the action hash table in yyActionTable.
**
**  +  A mask used to hash the look-ahead token.  The mask is an integer
**     which is one less than the size of the hash table.
**
**  +  The default action.  This is the action to take if no entry for
**     the given look-ahead is found in the action hash table.
*/
struct yyStateEntry {
  struct yyActionEntry *hashtbl; /* Start of the hash table in yyActionTable */
  int mask;                      /* Mask used for hashing the look-ahead */
  YYACTIONTYPE actionDefault;    /* Default action if look-ahead not found */
};
static struct yyStateEntry yyStateTable[] = {
  { &yyActionTable[0], 7, 115},
  { &yyActionTable[8], 0, 115},
  { &yyActionTable[9], 3, 115},
  { &yyActionTable[13], 0, 74},
  { &yyActionTable[14], 0, 75},
  { &yyActionTable[15], 1, 115},
  { &yyActionTable[17], 0, 115},
  { &yyActionTable[18], 3, 115},
  { &yyActionTable[22], 3, 115},
  { &yyActionTable[26], 0, 78},
  { &yyActionTable[27], 0, 80},
  { &yyActionTable[28], 3, 115},
  { &yyActionTable[32], 7, 115},
  { &yyActionTable[40], 0, 82},
  { &yyActionTable[41], 0, 85},
  { &yyActionTable[42], 0, 115},
  { &yyActionTable[43], 0, 86},
  { &yyActionTable[44], 0, 87},
  { &yyActionTable[45], 0, 88},
  { &yyActionTable[46], 0, 89},
  { &yyActionTable[47], 0, 83},
  { &yyActionTable[48], 0, 84},
  { &yyActionTable[49], 7, 115},
  { &yyActionTable[57], 1, 115},
  { &yyActionTable[59], 0, 90},
  { &yyActionTable[60], 7, 115},
  { &yyActionTable[68], 0, 91},
  { &yyActionTable[69], 0, 94},
  { &yyActionTable[70], 0, 95},
  { &yyActionTable[71], 0, 96},
  { &yyActionTable[72], 0, 92},
  { &yyActionTable[73], 0, 93},
  { &yyActionTable[74], 0, 81},
  { &yyActionTable[75], 0, 115},
  { &yyActionTable[76], 3, 115},
  { &yyActionTable[80], 3, 115},
  { &yyActionTable[84], 0, 79},
  { &yyActionTable[85], 0, 97},
  { &yyActionTable[86], 0, 98},
  { &yyActionTable[87], 0, 99},
  { &yyActionTable[88], 7, 115},
  { &yyActionTable[96], 3, 108},
  { &yyActionTable[100], 0, 115},
  { &yyActionTable[101], 0, 100},
  { &yyActionTable[102], 3, 115},
  { &yyActionTable[106], 7, 115},
  { &yyActionTable[114], 3, 109},
  { &yyActionTable[118], 0, 115},
  { &yyActionTable[119], 0, 101},
  { &yyActionTable[120], 0, 104},
  { &yyActionTable[121], 0, 105},
  { &yyActionTable[122], 3, 111},
  { &yyActionTable[126], 0, 112},
  { &yyActionTable[127], 0, 113},
  { &yyActionTable[128], 0, 114},
  { &yyActionTable[129], 7, 115},
  { &yyActionTable[137], 3, 110},
  { &yyActionTable[141], 0, 115},
  { &yyActionTable[142], 0, 102},
  { &yyActionTable[143], 0, 106},
  { &yyActionTable[144], 0, 103},
  { &yyActionTable[145], 0, 107},
  { &yyActionTable[146], 3, 115},
  { &yyActionTable[150], 0, 115},
  { &yyActionTable[151], 0, 115},
  { &yyActionTable[152], 3, 115},
  { &yyActionTable[156], 3, 115},
  { &yyActionTable[160], 0, 115},
  { &yyActionTable[161], 0, 115},
  { &yyActionTable[162], 0, 76},
  { &yyActionTable[163], 0, 77},
};

/* The following structure represents a single element of the
** parser's stack.  Information stored includes:
**
**   +  The state number for the parser at this level of the stack.
**
**   +  The value of the token stored at this level of the stack.
**      (In other words, the "major" token.)
**
**   +  The semantic value stored at this level of the stack.  This is
**      the information used by the action routines in the grammar.
**      It is sometimes called the "minor" token.
*/
struct yyStackEntry {
  int stateno;       /* The state-number */
  int major;         /* The major token value.  This is the code
                     ** number for the token at this stack level */
  YYMINORTYPE minor; /* The user-supplied minor token value.  This
                     ** is the value of the token  */
};

/* The state of the parser is completely contained in an instance of
** the following structure */
struct yyParser {
  int idx;                            /* Index of top element in stack */
  int errcnt;                         /* Shifts left before out of the error */
  struct yyStackEntry *top;           /* Pointer to the top stack element */
  struct yyStackEntry stack[YYSTACKDEPTH];  /* The parser's stack */
};
typedef struct yyParser yyParser;

#ifndef NDEBUG
#include <stdio.h>
static FILE *yyTraceFILE = 0;
static char *yyTracePrompt = 0;

/*
** Turn parser tracing on by giving a stream to which to write the trace
** and a prompt to preface each trace message.  Tracing is turned off
** by making either argument NULL
**
** Inputs:
** <ul>
** <li> A FILE* to which trace output should be written.
**      If NULL, then tracing is turned off.
** <li> A prefix string written at the beginning of every
**      line of trace output.  If NULL, then tracing is
**      turned off.
** </ul>
**
** Outputs:
** None.
*/
void DtdParseTrace(FILE *TraceFILE, char *zTracePrompt){
  yyTraceFILE = TraceFILE;
  yyTracePrompt = zTracePrompt;
  if( yyTraceFILE==0 ) yyTracePrompt = 0;
  else if( yyTracePrompt==0 ) yyTraceFILE = 0;
}

/* For tracing shifts, the names of all terminals and nonterminals
** are required.  The following table supplies these names */
static const char *yyTokenName[] = {
  "$",             "ATTLIST_KW",    "ATT_DEF",       "ATT_DEF_WITH_VALUE",
  "ATT_TYPE",      "CLOSE_BRACKET",  "CLOSE_PARENS",  "COMMA",       
  "DOCTYPE_KW",    "ELEMENT_KW",    "ELEM_DATA",     "EMPTY_KW",    
  "IMPLIED_KW",    "NAME",          "OPEN_BRACKET",  "OPEN_PARENS", 
  "PIPE",          "PLUS",          "QUESTION",      "QUOTED",      
  "REQUIRED_KW",   "STAR",          "TAG_START",     "TAG_STOP",    
  "att_default",   "att_type",      "attlist",       "attrib",      
  "attrib_list",   "doctype",       "dtd",           "dtd_parts",   
  "element",       "element_child",  "element_list",  "enum_item",   
  "enum_list",     "enumeration",   "error",         "sub_elements",
};
#define YYTRACE(X) if( yyTraceFILE ) fprintf(yyTraceFILE,"%sReduce [%s].\n",yyTracePrompt,X);
#else
#define YYTRACE(X)
#endif

/*
** This function allocates a new parser.
** The only argument is a pointer to a function which works like
** malloc.
**
** Inputs:
** A pointer to the function used to allocate memory.
**
** Outputs:
** A pointer to a parser.  This pointer is used in subsequent calls
** to DtdParse and DtdParseFree.
*/
void *DtdParseAlloc(void *(*mallocProc)(gulong)){
  yyParser *pParser;
  pParser = (yyParser*)(*mallocProc)( sizeof(yyParser) );
  if( pParser ){
    pParser->idx = -1;
  }
  return pParser;
}

/* The following function deletes the value associated with a
** symbol.  The symbol can be either a terminal or nonterminal.
** "yymajor" is the symbol code, and "yypminor" is a pointer to
** the value.
*/
static void yy_destructor(YYCODETYPE yymajor, YYMINORTYPE *yypminor){
  switch( yymajor ){
    /* Here is inserted the actions which take place when a
    ** terminal or non-terminal is destroyed.  This can happen
    ** when the symbol is popped from the stack during a
    ** reduce or during error processing or when a parser is
    ** being destroyed before it is finished parsing.
    **
    ** Note: during a reduce, the only symbols destroyed are those
    ** which appear on the RHS of the rule, but which are not used
    ** inside the C code.
    */
    case 1:
    case 2:
    case 3:
    case 4:
    case 5:
    case 6:
    case 7:
    case 8:
    case 9:
    case 10:
    case 11:
    case 12:
    case 13:
    case 14:
    case 15:
    case 16:
    case 17:
    case 18:
    case 19:
    case 20:
    case 21:
    case 22:
    case 23:
#line 61 "./dtd_grammar.lemon"
{ 
	if ((yypminor->yy0)) {
		if ((yypminor->yy0)->text) g_free((yypminor->yy0)->text);
		if ((yypminor->yy0)->location) g_free((yypminor->yy0)->location);
		g_free((yypminor->yy0));
	}
}
#line 649 "dtd_grammar.c"
      break;
    default:  break;   /* If no destructor action specified: do nothing */
  }
}

/*
** Pop the parser's stack once.
**
** If there is a destructor routine associated with the token which
** is popped from the stack, then call it.
**
** Return the major token number for the symbol popped.
*/
static int yy_pop_parser_stack(yyParser *pParser){
  YYCODETYPE yymajor;

  if( pParser->idx<0 ) return 0;
#ifndef NDEBUG
  if( yyTraceFILE && pParser->idx>=0 ){
    fprintf(yyTraceFILE,"%sPopping %s\n",
      yyTracePrompt,
      yyTokenName[pParser->top->major]);
  }
#endif
  yymajor = pParser->top->major;
  yy_destructor( yymajor, &pParser->top->minor);
  pParser->idx--;
  pParser->top--;
  return yymajor;
}

/*
** Deallocate and destroy a parser.  Destructors are all called for
** all stack elements before shutting the parser down.
**
** Inputs:
** <ul>
** <li>  A pointer to the parser.  This should be a pointer
**       obtained from DtdParseAlloc.
** <li>  A pointer to a function used to reclaim memory obtained
**       from malloc.
** </ul>
*/
void DtdParseFree(
  void *p,                 /* The parser to be deleted */
  void (*freeProc)(void *) /* Function used to reclaim memory */
){
  yyParser *pParser = (yyParser*)p;
  if( pParser==0 ) return;
  while( pParser->idx>=0 ) yy_pop_parser_stack(pParser);
  (*freeProc)(pParser);
}

/*
** Find the appropriate action for a parser given the look-ahead token.
**
** If the look-ahead token is YYNOCODE, then check to see if the action is
** independent of the look-ahead.  If it is, return the action, otherwise
** return YY_NO_ACTION.
*/
static int yy_find_parser_action(
  yyParser *pParser,        /* The parser */
  int iLookAhead             /* The look-ahead token */
){
  struct yyStateEntry *pState;   /* Appropriate entry in the state table */
  struct yyActionEntry *pAction; /* Action appropriate for the look-ahead */

  /* if( pParser->idx<0 ) return YY_NO_ACTION;  */
  pState = &yyStateTable[pParser->top->stateno];
  if( iLookAhead!=YYNOCODE ){
    pAction = &pState->hashtbl[iLookAhead & pState->mask];
    while( pAction ){
      if( pAction->lookahead==iLookAhead ) return pAction->action;
      pAction = pAction->next;
    }
  }else if( pState->mask!=0 || pState->hashtbl->lookahead!=YYNOCODE ){
    return YY_NO_ACTION;
  }
  return pState->actionDefault;
}

/*
** Perform a shift action.
*/
static void yy_shift(
  yyParser *yypParser,          /* The parser to be shifted */
  int yyNewState,               /* The new state to shift in */
  int yyMajor,                  /* The major token to shift in */
  YYMINORTYPE *yypMinor         /* Pointer ot the minor token to shift in */
){
  yypParser->idx++;
  yypParser->top++;
  if( yypParser->idx>=YYSTACKDEPTH ){
     yypParser->idx--;
     yypParser->top--;
#ifndef NDEBUG
     if( yyTraceFILE ){
       fprintf(yyTraceFILE,"%sStack Overflow!\n",yyTracePrompt);
     }
#endif
     while( yypParser->idx>=0 ) yy_pop_parser_stack(yypParser);
     /* Here code is inserted which will execute if the parser
     ** stack every overflows */
     return;
  }
  yypParser->top->stateno = yyNewState;
  yypParser->top->major = yyMajor;
  yypParser->top->minor = *yypMinor;
#ifndef NDEBUG
  if( yyTraceFILE && yypParser->idx>0 ){
    int i;
    fprintf(yyTraceFILE,"%sShift %d\n",yyTracePrompt,yyNewState);
    fprintf(yyTraceFILE,"%sStack:",yyTracePrompt);
    for(i=1; i<=yypParser->idx; i++)
      fprintf(yyTraceFILE," %s",yyTokenName[yypParser->stack[i].major]);
    fprintf(yyTraceFILE,"\n");
  }
#endif
}

/* The following table contains information about every rule that
** is used during the reduce.
*/
static struct {
  YYCODETYPE lhs;         /* Symbol on the left-hand side of the rule */
  unsigned char nrhs;     /* Number of right-hand side symbols in the rule */
} yyRuleInfo[] = {
  { 30, 1 },
  { 30, 1 },
  { 29, 7 },
  { 31, 2 },
  { 31, 2 },
  { 31, 1 },
  { 31, 1 },
  { 26, 5 },
  { 32, 5 },
  { 28, 2 },
  { 28, 1 },
  { 27, 3 },
  { 25, 1 },
  { 25, 1 },
  { 24, 1 },
  { 24, 2 },
  { 24, 1 },
  { 24, 1 },
  { 24, 1 },
  { 37, 3 },
  { 36, 3 },
  { 36, 1 },
  { 36, 1 },
  { 36, 3 },
  { 35, 1 },
  { 35, 1 },
  { 39, 2 },
  { 39, 2 },
  { 39, 2 },
  { 39, 3 },
  { 39, 5 },
  { 39, 5 },
  { 39, 3 },
  { 39, 1 },
  { 34, 3 },
  { 34, 3 },
  { 34, 1 },
  { 34, 1 },
  { 34, 3 },
  { 34, 3 },
  { 33, 1 },
  { 33, 2 },
  { 33, 2 },
  { 33, 2 },
};

static void yy_accept(
  yyParser *yypParser           /* The parser */
  DtdParseANSIARGDECL _U_          /* Extra arguments (if any) */
);  /* Forward declaration */

/*
** Perform a reduce action and the shift that must immediately
** follow the reduce.
*/
static void yy_reduce(
  yyParser *yypParser,         /* The parser */
  int yyruleno                 /* Number of the rule by which to reduce */
  DtdParseANSIARGDECL
){
  int yygoto;                     /* The next state */
  int yyact;                      /* The next action */
  YYMINORTYPE yygotominor;        /* The LHS of the rule reduced */
  struct yyStackEntry *yymsp;     /* The top of the parser's stack */
  int yysize;                     /* Amount to pop the stack */
  yymsp = yypParser->top;
  switch( yyruleno ){
  /* Beginning here are the reduction cases.  A typical example
  ** follows:
  **   case 0:
  **     YYTRACE("<text of the rule>");
  **  #line <lineno> <grammarfile>
  **     { ... }           // User supplied code
  **  #line <lineno> <thisfile>
  **     break;
  */
      case 0:
        YYTRACE("dtd ::= doctype")
        /* No destructor defined for doctype */
        break;
      case 1:
        YYTRACE("dtd ::= dtd_parts")
        /* No destructor defined for dtd_parts */
        break;
      case 2:
        YYTRACE("doctype ::= TAG_START DOCTYPE_KW NAME OPEN_BRACKET dtd_parts CLOSE_BRACKET TAG_STOP")
#line 87 "./dtd_grammar.lemon"
{
    dtd_named_list_t* root;
    GPtrArray* root_elems = g_ptr_array_new();
    guint i;

    if(! bd->proto_name) {
        bd->proto_name = yymsp[-4].minor.yy0->text;
    }

    if(bd->proto_root)
        g_free(bd->proto_root);

	bd->proto_root = g_strdup(yymsp[-4].minor.yy0->text);
    
	g_strdown(bd->proto_name);
    
    for( i = 0; i< bd->elements->len; i++) {
        dtd_named_list_t* el = g_ptr_array_index(bd->elements,i);
        
        g_ptr_array_add(root_elems,g_strdup(el->name));
    }
    
    root = dtd_named_list_new(g_strdup(yymsp[-4].minor.yy0->text),root_elems);
    
    g_ptr_array_add(bd->elements,root);
    
    g_free(yymsp[-4].minor.yy0->location);
    g_free(yymsp[-4].minor.yy0);

}
#line 894 "dtd_grammar.c"
  yy_destructor(22,&yymsp[-6].minor);
  yy_destructor(8,&yymsp[-5].minor);
  yy_destructor(14,&yymsp[-3].minor);
        /* No destructor defined for dtd_parts */
  yy_destructor(5,&yymsp[-1].minor);
  yy_destructor(23,&yymsp[0].minor);
        break;
      case 3:
        YYTRACE("dtd_parts ::= dtd_parts element")
#line 118 "./dtd_grammar.lemon"
{ g_ptr_array_add(bd->elements,yymsp[0].minor.yy21); }
#line 906 "dtd_grammar.c"
        /* No destructor defined for dtd_parts */
        break;
      case 4:
        YYTRACE("dtd_parts ::= dtd_parts attlist")
#line 119 "./dtd_grammar.lemon"
{ g_ptr_array_add(bd->attributes,yymsp[0].minor.yy21); }
#line 913 "dtd_grammar.c"
        /* No destructor defined for dtd_parts */
        break;
      case 5:
        YYTRACE("dtd_parts ::= element")
#line 120 "./dtd_grammar.lemon"
{ g_ptr_array_add(bd->elements,yymsp[0].minor.yy21); }
#line 920 "dtd_grammar.c"
        break;
      case 6:
        YYTRACE("dtd_parts ::= attlist")
#line 121 "./dtd_grammar.lemon"
{ g_ptr_array_add(bd->attributes,yymsp[0].minor.yy21); }
#line 926 "dtd_grammar.c"
        break;
      case 7:
        YYTRACE("attlist ::= TAG_START ATTLIST_KW NAME attrib_list TAG_STOP")
#line 124 "./dtd_grammar.lemon"
{
    g_strdown(yymsp[-2].minor.yy0->text);
    yygotominor.yy21 = dtd_named_list_new(yymsp[-2].minor.yy0->text,yymsp[-1].minor.yy71);
    g_free(yymsp[-2].minor.yy0->location);
    g_free(yymsp[-2].minor.yy0);
}
#line 937 "dtd_grammar.c"
  yy_destructor(22,&yymsp[-4].minor);
  yy_destructor(1,&yymsp[-3].minor);
  yy_destructor(23,&yymsp[0].minor);
        break;
      case 8:
        YYTRACE("element ::= TAG_START ELEMENT_KW NAME sub_elements TAG_STOP")
#line 132 "./dtd_grammar.lemon"
{
    g_strdown(yymsp[-2].minor.yy0->text);
    yygotominor.yy21 = dtd_named_list_new(yymsp[-2].minor.yy0->text,yymsp[-1].minor.yy71);
    g_free(yymsp[-2].minor.yy0->location);
    g_free(yymsp[-2].minor.yy0);
}
#line 951 "dtd_grammar.c"
  yy_destructor(22,&yymsp[-4].minor);
  yy_destructor(9,&yymsp[-3].minor);
  yy_destructor(23,&yymsp[0].minor);
        break;
      case 9:
        YYTRACE("attrib_list ::= attrib_list attrib")
#line 140 "./dtd_grammar.lemon"
{ g_ptr_array_add(yymsp[-1].minor.yy71,yymsp[0].minor.yy44); yygotominor.yy71 = yymsp[-1].minor.yy71; }
#line 960 "dtd_grammar.c"
        break;
      case 10:
        YYTRACE("attrib_list ::= attrib")
#line 141 "./dtd_grammar.lemon"
{ yygotominor.yy71 = g_ptr_array_new(); g_ptr_array_add(yygotominor.yy71,yymsp[0].minor.yy44);  }
#line 966 "dtd_grammar.c"
        break;
      case 11:
        YYTRACE("attrib ::= NAME att_type att_default")
#line 144 "./dtd_grammar.lemon"
{
	yygotominor.yy44 = yymsp[-2].minor.yy0->text;
	g_strdown(yygotominor.yy44);
    g_free(yymsp[-2].minor.yy0->location);
    g_free(yymsp[-2].minor.yy0);
}
#line 977 "dtd_grammar.c"
        /* No destructor defined for att_type */
        /* No destructor defined for att_default */
        break;
      case 12:
        YYTRACE("att_type ::= ATT_TYPE")
  yy_destructor(4,&yymsp[0].minor);
        break;
      case 13:
        YYTRACE("att_type ::= enumeration")
        /* No destructor defined for enumeration */
        break;
      case 14:
        YYTRACE("att_default ::= ATT_DEF")
  yy_destructor(2,&yymsp[0].minor);
        break;
      case 15:
        YYTRACE("att_default ::= ATT_DEF_WITH_VALUE QUOTED")
  yy_destructor(3,&yymsp[-1].minor);
  yy_destructor(19,&yymsp[0].minor);
        break;
      case 16:
        YYTRACE("att_default ::= QUOTED")
  yy_destructor(19,&yymsp[0].minor);
        break;
      case 17:
        YYTRACE("att_default ::= IMPLIED_KW")
  yy_destructor(12,&yymsp[0].minor);
        break;
      case 18:
        YYTRACE("att_default ::= REQUIRED_KW")
  yy_destructor(20,&yymsp[0].minor);
        break;
      case 19:
        YYTRACE("enumeration ::= OPEN_PARENS enum_list CLOSE_PARENS")
  yy_destructor(15,&yymsp[-2].minor);
        /* No destructor defined for enum_list */
  yy_destructor(6,&yymsp[0].minor);
        break;
      case 20:
        YYTRACE("enum_list ::= enum_list PIPE enum_item")
        /* No destructor defined for enum_list */
  yy_destructor(16,&yymsp[-1].minor);
        /* No destructor defined for enum_item */
        break;
      case 21:
        YYTRACE("enum_list ::= enum_item")
        /* No destructor defined for enum_item */
        break;
      case 22:
        YYTRACE("enum_list ::= enumeration")
        /* No destructor defined for enumeration */
        break;
      case 23:
        YYTRACE("enum_list ::= enum_list PIPE enumeration")
        /* No destructor defined for enum_list */
  yy_destructor(16,&yymsp[-1].minor);
        /* No destructor defined for enumeration */
        break;
      case 24:
        YYTRACE("enum_item ::= NAME")
  yy_destructor(13,&yymsp[0].minor);
        break;
      case 25:
        YYTRACE("enum_item ::= QUOTED")
  yy_destructor(19,&yymsp[0].minor);
        break;
      case 26:
        YYTRACE("sub_elements ::= sub_elements STAR")
#line 172 "./dtd_grammar.lemon"
{yygotominor.yy71=yymsp[-1].minor.yy71;}
#line 1048 "dtd_grammar.c"
  yy_destructor(21,&yymsp[0].minor);
        break;
      case 27:
        YYTRACE("sub_elements ::= sub_elements PLUS")
#line 173 "./dtd_grammar.lemon"
{yygotominor.yy71=yymsp[-1].minor.yy71;}
#line 1055 "dtd_grammar.c"
  yy_destructor(17,&yymsp[0].minor);
        break;
      case 28:
        YYTRACE("sub_elements ::= sub_elements QUESTION")
#line 174 "./dtd_grammar.lemon"
{yygotominor.yy71=yymsp[-1].minor.yy71;}
#line 1062 "dtd_grammar.c"
  yy_destructor(18,&yymsp[0].minor);
        break;
      case 29:
        YYTRACE("sub_elements ::= OPEN_PARENS ELEM_DATA CLOSE_PARENS")
#line 175 "./dtd_grammar.lemon"
{ yygotominor.yy71 = g_ptr_array_new(); }
#line 1069 "dtd_grammar.c"
  yy_destructor(15,&yymsp[-2].minor);
  yy_destructor(10,&yymsp[-1].minor);
  yy_destructor(6,&yymsp[0].minor);
        break;
      case 30:
        YYTRACE("sub_elements ::= OPEN_PARENS element_list COMMA ELEM_DATA CLOSE_PARENS")
#line 176 "./dtd_grammar.lemon"
{ yygotominor.yy71 = yymsp[-3].minor.yy71; }
#line 1078 "dtd_grammar.c"
  yy_destructor(15,&yymsp[-4].minor);
  yy_destructor(7,&yymsp[-2].minor);
  yy_destructor(10,&yymsp[-1].minor);
  yy_destructor(6,&yymsp[0].minor);
        break;
      case 31:
        YYTRACE("sub_elements ::= OPEN_PARENS element_list PIPE ELEM_DATA CLOSE_PARENS")
#line 177 "./dtd_grammar.lemon"
{ yygotominor.yy71 = yymsp[-3].minor.yy71; }
#line 1088 "dtd_grammar.c"
  yy_destructor(15,&yymsp[-4].minor);
  yy_destructor(16,&yymsp[-2].minor);
  yy_destructor(10,&yymsp[-1].minor);
  yy_destructor(6,&yymsp[0].minor);
        break;
      case 32:
        YYTRACE("sub_elements ::= OPEN_PARENS element_list CLOSE_PARENS")
#line 178 "./dtd_grammar.lemon"
{ yygotominor.yy71 = yymsp[-1].minor.yy71; }
#line 1098 "dtd_grammar.c"
  yy_destructor(15,&yymsp[-2].minor);
  yy_destructor(6,&yymsp[0].minor);
        break;
      case 33:
        YYTRACE("sub_elements ::= EMPTY_KW")
#line 179 "./dtd_grammar.lemon"
{ yygotominor.yy71 = g_ptr_array_new(); }
#line 1106 "dtd_grammar.c"
  yy_destructor(11,&yymsp[0].minor);
        break;
      case 34:
        YYTRACE("element_list ::= element_list COMMA element_child")
#line 182 "./dtd_grammar.lemon"
{ g_ptr_array_add(yymsp[-2].minor.yy71,yymsp[0].minor.yy44); yygotominor.yy71 = yymsp[-2].minor.yy71; }
#line 1113 "dtd_grammar.c"
  yy_destructor(7,&yymsp[-1].minor);
        break;
      case 35:
        YYTRACE("element_list ::= element_list PIPE element_child")
#line 183 "./dtd_grammar.lemon"
{ g_ptr_array_add(yymsp[-2].minor.yy71,yymsp[0].minor.yy44); yygotominor.yy71 = yymsp[-2].minor.yy71; }
#line 1120 "dtd_grammar.c"
  yy_destructor(16,&yymsp[-1].minor);
        break;
      case 36:
        YYTRACE("element_list ::= element_child")
#line 184 "./dtd_grammar.lemon"
{ yygotominor.yy71 = g_ptr_array_new(); g_ptr_array_add(yygotominor.yy71,yymsp[0].minor.yy44); }
#line 1127 "dtd_grammar.c"
        break;
      case 37:
        YYTRACE("element_list ::= sub_elements")
#line 185 "./dtd_grammar.lemon"
{ yygotominor.yy71 = yymsp[0].minor.yy71; }
#line 1133 "dtd_grammar.c"
        break;
      case 38:
        YYTRACE("element_list ::= element_list COMMA sub_elements")
#line 186 "./dtd_grammar.lemon"
{ yygotominor.yy71 = g_ptr_array_join(yymsp[-2].minor.yy71,yymsp[0].minor.yy71); }
#line 1139 "dtd_grammar.c"
  yy_destructor(7,&yymsp[-1].minor);
        break;
      case 39:
        YYTRACE("element_list ::= element_list PIPE sub_elements")
#line 187 "./dtd_grammar.lemon"
{ yygotominor.yy71 = g_ptr_array_join(yymsp[-2].minor.yy71,yymsp[0].minor.yy71); }
#line 1146 "dtd_grammar.c"
  yy_destructor(16,&yymsp[-1].minor);
        break;
      case 40:
        YYTRACE("element_child ::= NAME")
#line 190 "./dtd_grammar.lemon"
{
	yygotominor.yy44 = yymsp[0].minor.yy0->text;
	g_strdown(yygotominor.yy44);
    g_free(yymsp[0].minor.yy0->location);
    g_free(yymsp[0].minor.yy0);
}
#line 1158 "dtd_grammar.c"
        break;
      case 41:
        YYTRACE("element_child ::= NAME STAR")
#line 197 "./dtd_grammar.lemon"
{
	yygotominor.yy44 = yymsp[-1].minor.yy0->text;
	g_strdown(yygotominor.yy44);
    g_free(yymsp[-1].minor.yy0->location);
    g_free(yymsp[-1].minor.yy0);
}
#line 1169 "dtd_grammar.c"
  yy_destructor(21,&yymsp[0].minor);
        break;
      case 42:
        YYTRACE("element_child ::= NAME QUESTION")
#line 204 "./dtd_grammar.lemon"
{
	yygotominor.yy44 = yymsp[-1].minor.yy0->text;
	g_strdown(yygotominor.yy44);
    g_free(yymsp[-1].minor.yy0->location);
    g_free(yymsp[-1].minor.yy0);
}
#line 1181 "dtd_grammar.c"
  yy_destructor(18,&yymsp[0].minor);
        break;
      case 43:
        YYTRACE("element_child ::= NAME PLUS")
#line 211 "./dtd_grammar.lemon"
{
	yygotominor.yy44 = yymsp[-1].minor.yy0->text;
	g_strdown(yygotominor.yy44);
    g_free(yymsp[-1].minor.yy0->location);
    g_free(yymsp[-1].minor.yy0);
}
#line 1193 "dtd_grammar.c"
  yy_destructor(17,&yymsp[0].minor);
        break;
  };
  yygoto = yyRuleInfo[yyruleno].lhs;
  yysize = yyRuleInfo[yyruleno].nrhs;
  yypParser->idx -= yysize;
  yypParser->top -= yysize;
  yyact = yy_find_parser_action(yypParser,yygoto);
  if( yyact < YYNSTATE ){
    yy_shift(yypParser,yyact,yygoto,&yygotominor);
  }else if( yyact == YYNSTATE + YYNRULE + 1 ){
    yy_accept(yypParser DtdParseARGDECL);
  }
}

/*
** The following code executes when the parse fails
*/
static void yy_parse_failed(
  yyParser *yypParser           /* The parser */
  DtdParseANSIARGDECL              /* Extra arguments (if any) */
){
#ifndef NDEBUG
  if( yyTraceFILE ){
    fprintf(yyTraceFILE,"%sFail!\n",yyTracePrompt);
  }
#endif
  while( yypParser->idx>=0 ) yy_pop_parser_stack(yypParser);
  /* Here code is inserted which will be executed whenever the
  ** parser fails */
#line 76 "./dtd_grammar.lemon"

	g_string_sprintfa(bd->error,"DTD parsing failure\n");

#line 1228 "dtd_grammar.c"
}

/*
** The following code executes when a syntax error first occurs.
*/
static void yy_syntax_error(
  yyParser *yypParser _U_,       /* The parser */
  int yymajor _U_,               /* The major type of the error token */
  YYMINORTYPE yyminor            /* The minor type of the error token */
  DtdParseANSIARGDECL _U_           /* Extra arguments (if any) */
){
#define TOKEN (yyminor.yy0)
#line 69 "./dtd_grammar.lemon"

	if (!TOKEN)
		g_string_sprintfa(bd->error,"syntax error at end of file");
	else 
		g_string_sprintfa(bd->error,"syntax error in %s at or before '%s': \n", TOKEN->location,TOKEN->text);

#line 1248 "dtd_grammar.c"
}

/*
** The following is executed when the parser accepts
*/
static void yy_accept(
  yyParser *yypParser           /* The parser */
  DtdParseANSIARGDECL _U_          /* Extra arguments (if any) */
){
#ifndef NDEBUG
  if( yyTraceFILE ){
    fprintf(yyTraceFILE,"%sAccept!\n",yyTracePrompt);
  }
#endif
  while( yypParser->idx>=0 ) yy_pop_parser_stack(yypParser);
  /* Here code is inserted which will be executed whenever the
  ** parser accepts */
}

/* The main parser program.
** The first argument is a pointer to a structure obtained from
** "DtdParseAlloc" which describes the current state of the parser.
** The second argument is the major token number.  The third is
** the minor token.  The fourth optional argument is whatever the
** user wants (and specified in the grammar) and is available for
** use by the action routines.
**
** Inputs:
** <ul>
** <li> A pointer to the parser (an opaque structure.)
** <li> The major token number.
** <li> The minor token number.
** <li> An option argument of a grammar-specified type.
** </ul>
**
** Outputs:
** None.
*/
void DtdParse(
  void *yyp,                   /* The parser */
  int yymajor,                 /* The major token code number */
  DtdParseTOKENTYPE yyminor       /* The value for the token */
  DtdParseANSIARGDECL
){
  YYMINORTYPE yyminorunion;
  int yyact;            /* The parser action. */
  int yyendofinput;     /* True if we are at the end of input */
  int yyerrorhit = 0;   /* True if yymajor has invoked an error */
  yyParser *yypParser;  /* The parser */

  /* (re)initialize the parser, if necessary */
  yypParser = (yyParser*)yyp;
  if( yypParser->idx<0 ){
    if( yymajor==0 ) return;
    yypParser->idx = 0;
    yypParser->errcnt = -1;
    yypParser->top = &yypParser->stack[0];
    yypParser->top->stateno = 0;
    yypParser->top->major = 0;
  }
  yyminorunion.yy0 = yyminor;
  yyendofinput = (yymajor==0);

#ifndef NDEBUG
  if( yyTraceFILE ){
    fprintf(yyTraceFILE,"%sInput %s\n",yyTracePrompt,yyTokenName[yymajor]);
  }
#endif

  do{
    yyact = yy_find_parser_action(yypParser,yymajor);
    if( yyact<YYNSTATE ){
      yy_shift(yypParser,yyact,yymajor,&yyminorunion);
      yypParser->errcnt--;
      if( yyendofinput && yypParser->idx>=0 ){
        yymajor = 0;
      }else{
        yymajor = YYNOCODE;
      }
    }else if( yyact < YYNSTATE + YYNRULE ){
      yy_reduce(yypParser,yyact-YYNSTATE DtdParseARGDECL);
    }else if( yyact == YY_ERROR_ACTION ){
#ifndef NDEBUG
      if( yyTraceFILE ){
        fprintf(yyTraceFILE,"%sSyntax Error!\n",yyTracePrompt);
      }
#endif
#ifdef YYERRORSYMBOL
      /* A syntax error has occurred.
      ** The response to an error depends upon whether or not the
      ** grammar defines an error token "ERROR".
      **
      ** This is what we do if the grammar does define ERROR:
      **
      **  * Call the %syntax_error function.
      **
      **  * Begin popping the stack until we enter a state where
      **    it is legal to shift the error symbol, then shift
      **    the error symbol.
      **
      **  * Set the error count to three.
      **
      **  * Begin accepting and shifting new tokens.  No new error
      **    processing will occur until three tokens have been
      **    shifted successfully.
      **
      */
      if( yypParser->errcnt<0 ){
        yy_syntax_error(yypParser,yymajor,yyminorunion DtdParseARGDECL);
      }
      if( yypParser->top->major==YYERRORSYMBOL || yyerrorhit ){
#ifndef NDEBUG
        if( yyTraceFILE ){
          fprintf(yyTraceFILE,"%sDiscard input token %s\n",
             yyTracePrompt,yyTokenName[yymajor]);
        }
#endif
        yy_destructor(yymajor,&yyminorunion);
        yymajor = YYNOCODE;
      }else{
         while(
          yypParser->idx >= 0 &&
          yypParser->top->major != YYERRORSYMBOL &&
          (yyact = yy_find_parser_action(yypParser,YYERRORSYMBOL)) >= YYNSTATE
        ){
          yy_pop_parser_stack(yypParser);
        }
        if( yypParser->idx < 0 || yymajor==0 ){
          yy_destructor(yymajor,&yyminorunion);
          yy_parse_failed(yypParser DtdParseARGDECL);
          yymajor = YYNOCODE;
        }else if( yypParser->top->major!=YYERRORSYMBOL ){
          YYMINORTYPE u2;
          u2.YYERRSYMDT = 0;
          yy_shift(yypParser,yyact,YYERRORSYMBOL,&u2);
        }
      }
      yypParser->errcnt = 3;
      yyerrorhit = 1;
#else  /* YYERRORSYMBOL is not defined */
      /* This is what we do if the grammar does not define ERROR:
      **
      **  * Report an error message, and throw away the input token.
      **
      **  * If the input token is $, then fail the parse.
      **
      ** As before, subsequent error messages are suppressed until
      ** three input tokens have been successfully shifted.
      */
      if( yypParser->errcnt<=0 ){
        yy_syntax_error(yypParser,yymajor,yyminorunion DtdParseARGDECL);
      }
      yypParser->errcnt = 3;
      yy_destructor(yymajor,&yyminorunion);
      if( yyendofinput ){
        yy_parse_failed(yypParser DtdParseARGDECL);
      }
      yymajor = YYNOCODE;
#endif
    }else{
      yy_accept(yypParser DtdParseARGDECL);
      yymajor = YYNOCODE;
    }
  }while( yymajor!=YYNOCODE && yypParser->idx>=0 );
  return;
}
