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