| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
#ifndef Py_GRAMMAR_H |
| 5 |
#define Py_GRAMMAR_H |
| 6 |
#ifdef __cplusplus |
| 7 |
extern "C" { |
| 8 |
#endif |
| 9 |
|
| 10 |
#include "bitset.h" |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
typedef struct { |
| 15 |
int lb_type; |
| 16 |
char *lb_str; |
| 17 |
} label; |
| 18 |
|
| 19 |
#define EMPTY 0 |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
typedef struct { |
| 24 |
int ll_nlabels; |
| 25 |
label *ll_label; |
| 26 |
} labellist; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
typedef struct { |
| 31 |
short a_lbl; |
| 32 |
short a_arrow; |
| 33 |
} arc; |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
typedef struct { |
| 38 |
int s_narcs; |
| 39 |
arc *s_arc; |
| 40 |
|
| 41 |
|
| 42 |
int s_lower; |
| 43 |
int s_upper; |
| 44 |
int *s_accel; |
| 45 |
int s_accept; |
| 46 |
} state; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
typedef struct { |
| 51 |
int d_type; |
| 52 |
char *d_name; |
| 53 |
int d_initial; |
| 54 |
int d_nstates; |
| 55 |
state *d_state; |
| 56 |
bitset d_first; |
| 57 |
} dfa; |
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
typedef struct { |
| 62 |
int g_ndfas; |
| 63 |
dfa *g_dfa; |
| 64 |
labellist g_ll; |
| 65 |
int g_start; |
| 66 |
int g_accel; |
| 67 |
} grammar; |
| 68 |
|
| 69 |
|
| 70 |
|
| 71 |
grammar *newgrammar(int start); |
| 72 |
void freegrammar(grammar *g); |
| 73 |
dfa *adddfa(grammar *g, int type, char *name); |
| 74 |
int addstate(dfa *d); |
| 75 |
void addarc(dfa *d, int from, int to, int lbl); |
| 76 |
dfa *PyGrammar_FindDFA(grammar *g, int type); |
| 77 |
|
| 78 |
int addlabel(labellist *ll, int type, char *str); |
| 79 |
int findlabel(labellist *ll, int type, char *str); |
| 80 |
char *PyGrammar_LabelRepr(label *lb); |
| 81 |
void translatelabels(grammar *g); |
| 82 |
|
| 83 |
void addfirstsets(grammar *g); |
| 84 |
|
| 85 |
void PyGrammar_AddAccelerators(grammar *g); |
| 86 |
void PyGrammar_RemoveAccelerators(grammar *); |
| 87 |
|
| 88 |
void printgrammar(grammar *g, FILE *fp); |
| 89 |
void printnonterminals(grammar *g, FILE *fp); |
| 90 |
|
| 91 |
#ifdef __cplusplus |
| 92 |
} |
| 93 |
#endif |
| 94 |
#endif |