Commit | Line | Data |
---|---|---|
86530b38 AT |
1 | #ifndef Py_GRAMMAR_H |
2 | #define Py_GRAMMAR_H | |
3 | #ifdef __cplusplus | |
4 | extern "C" { | |
5 | #endif | |
6 | ||
7 | #include "bitset.h" /* Sigh... */ | |
8 | ||
9 | /* A label of an arc */ | |
10 | ||
11 | typedef struct { | |
12 | int lb_type; | |
13 | char *lb_str; | |
14 | } label; | |
15 | ||
16 | #define EMPTY 0 /* Label number 0 is by definition the empty label */ | |
17 | ||
18 | /* A list of labels */ | |
19 | ||
20 | typedef struct { | |
21 | int ll_nlabels; | |
22 | label *ll_label; | |
23 | } labellist; | |
24 | ||
25 | /* An arc from one state to another */ | |
26 | ||
27 | typedef struct { | |
28 | short a_lbl; /* Label of this arc */ | |
29 | short a_arrow; /* State where this arc goes to */ | |
30 | } arc; | |
31 | ||
32 | /* A state in a DFA */ | |
33 | ||
34 | typedef struct { | |
35 | int s_narcs; | |
36 | arc *s_arc; /* Array of arcs */ | |
37 | ||
38 | /* Optional accelerators */ | |
39 | int s_lower; /* Lowest label index */ | |
40 | int s_upper; /* Highest label index */ | |
41 | int *s_accel; /* Accelerator */ | |
42 | int s_accept; /* Nonzero for accepting state */ | |
43 | } state; | |
44 | ||
45 | /* A DFA */ | |
46 | ||
47 | typedef struct { | |
48 | int d_type; /* Non-terminal this represents */ | |
49 | char *d_name; /* For printing */ | |
50 | int d_initial; /* Initial state */ | |
51 | int d_nstates; | |
52 | state *d_state; /* Array of states */ | |
53 | bitset d_first; | |
54 | } dfa; | |
55 | ||
56 | /* A grammar */ | |
57 | ||
58 | typedef struct { | |
59 | int g_ndfas; | |
60 | dfa *g_dfa; /* Array of DFAs */ | |
61 | labellist g_ll; | |
62 | int g_start; /* Start symbol of the grammar */ | |
63 | int g_accel; /* Set if accelerators present */ | |
64 | } grammar; | |
65 | ||
66 | /* FUNCTIONS */ | |
67 | ||
68 | grammar *newgrammar(int start); | |
69 | dfa *adddfa(grammar *g, int type, char *name); | |
70 | int addstate(dfa *d); | |
71 | void addarc(dfa *d, int from, int to, int lbl); | |
72 | dfa *PyGrammar_FindDFA(grammar *g, int type); | |
73 | ||
74 | int addlabel(labellist *ll, int type, char *str); | |
75 | int findlabel(labellist *ll, int type, char *str); | |
76 | char *PyGrammar_LabelRepr(label *lb); | |
77 | void translatelabels(grammar *g); | |
78 | ||
79 | void addfirstsets(grammar *g); | |
80 | ||
81 | void PyGrammar_AddAccelerators(grammar *g); | |
82 | void PyGrammar_RemoveAccelerators(grammar *); | |
83 | ||
84 | void printgrammar(grammar *g, FILE *fp); | |
85 | void printnonterminals(grammar *g, FILE *fp); | |
86 | ||
87 | #ifdef __cplusplus | |
88 | } | |
89 | #endif | |
90 | #endif /* !Py_GRAMMAR_H */ |