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