jpayne@69: jpayne@69: /* Grammar interface */ jpayne@69: jpayne@69: #ifndef Py_GRAMMAR_H jpayne@69: #define Py_GRAMMAR_H jpayne@69: #ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: #endif jpayne@69: jpayne@69: #include "bitset.h" /* Sigh... */ jpayne@69: jpayne@69: /* A label of an arc */ jpayne@69: jpayne@69: typedef struct { jpayne@69: int lb_type; jpayne@69: const char *lb_str; jpayne@69: } label; jpayne@69: jpayne@69: #define EMPTY 0 /* Label number 0 is by definition the empty label */ jpayne@69: jpayne@69: /* A list of labels */ jpayne@69: jpayne@69: typedef struct { jpayne@69: int ll_nlabels; jpayne@69: const label *ll_label; jpayne@69: } labellist; jpayne@69: jpayne@69: /* An arc from one state to another */ jpayne@69: jpayne@69: typedef struct { jpayne@69: short a_lbl; /* Label of this arc */ jpayne@69: short a_arrow; /* State where this arc goes to */ jpayne@69: } arc; jpayne@69: jpayne@69: /* A state in a DFA */ jpayne@69: jpayne@69: typedef struct { jpayne@69: int s_narcs; jpayne@69: const arc *s_arc; /* Array of arcs */ jpayne@69: jpayne@69: /* Optional accelerators */ jpayne@69: int s_lower; /* Lowest label index */ jpayne@69: int s_upper; /* Highest label index */ jpayne@69: int *s_accel; /* Accelerator */ jpayne@69: int s_accept; /* Nonzero for accepting state */ jpayne@69: } state; jpayne@69: jpayne@69: /* A DFA */ jpayne@69: jpayne@69: typedef struct { jpayne@69: int d_type; /* Non-terminal this represents */ jpayne@69: char *d_name; /* For printing */ jpayne@69: int d_nstates; jpayne@69: state *d_state; /* Array of states */ jpayne@69: bitset d_first; jpayne@69: } dfa; jpayne@69: jpayne@69: /* A grammar */ jpayne@69: jpayne@69: typedef struct { jpayne@69: int g_ndfas; jpayne@69: const dfa *g_dfa; /* Array of DFAs */ jpayne@69: const labellist g_ll; jpayne@69: int g_start; /* Start symbol of the grammar */ jpayne@69: int g_accel; /* Set if accelerators present */ jpayne@69: } grammar; jpayne@69: jpayne@69: /* FUNCTIONS */ jpayne@69: const dfa *PyGrammar_FindDFA(grammar *g, int type); jpayne@69: const char *PyGrammar_LabelRepr(label *lb); jpayne@69: void PyGrammar_AddAccelerators(grammar *g); jpayne@69: void PyGrammar_RemoveAccelerators(grammar *); jpayne@69: jpayne@69: #ifdef __cplusplus jpayne@69: } jpayne@69: #endif jpayne@69: #endif /* !Py_GRAMMAR_H */