1 /**
2   Mirror _grammar.h
3 
4   Grammar interface
5   */
6 module deimos.python.grammar;
7 
8 import core.stdc.stdio;
9 
10 extern(C):
11 // Python-header-file: Include/object.h:
12 
13 /** A label of an arc */
14 struct label{
15     /// _
16     int		 lb_type;
17     /// _
18     char*	lb_str;
19 }
20 
21 /** Label number 0 is by definition the empty label */
22 enum EMPTY = 0;
23 
24 /** A list of labels */
25 struct labellist{
26     /// _
27     int		 ll_nlabels;
28     /// _
29     label*	ll_label;
30 }
31 
32 /** An arc from one state to another */
33 struct arc{
34     /** Label of this arc */
35     short	a_lbl;
36     /** State where this arc goes to */
37     short	a_arrow;
38 }
39 
40 /** A state in a DFA */
41 struct state{
42     /// _
43     int		 s_narcs;
44     /** Array of arcs */
45     arc*	 s_arc;
46 
47     /* Optional accelerators */
48     /** Lowest label index */
49     int		 s_lower;
50     /** Highest label index */
51     int		 s_upper;
52     /** Accelerator */
53     int*	 s_accel;
54     /** Nonzero for accepting state */
55     int		 s_accept;
56 }
57 
58 /** A DFA */
59 struct dfa{
60     /** Non-terminal this represents */
61     int		 d_type;
62     /** For printing */
63     char*	 d_name;
64     /** Initial state */
65     int		 d_initial;
66     /// _
67     int		 d_nstates;
68     /** Array of states */
69     state*	 d_state;
70     /// _
71     void*/*bitset*/	 d_first;
72 }
73 
74 /** A grammar */
75 struct grammar{
76     /// _
77     int		 g_ndfas;
78     /** Array of DFAs */
79     dfa*	 g_dfa;
80     /// _
81     labellist	 g_ll;
82     /** Start symbol of the grammar */
83     int		 g_start;
84     /** Set if accelerators present */
85     int		 g_accel;
86 }
87 
88 /* FUNCTIONS */
89 
90 /// _
91 grammar* newgrammar(int start);
92 /// _
93 dfa* adddfa(grammar* g, int type, char* name);
94 /// _
95 int addstate(dfa* d);
96 /// _
97 void addarc(dfa* d, int from, int to, int lbl);
98 /// _
99 dfa *PyGrammar_FindDFA(grammar* g, int type);
100 
101 /// _
102 int addlabel(labellist* ll, int type, char* str);
103 /// _
104 int findlabel(labellist* ll, int type, char* str);
105 /// _
106 char* PyGrammar_LabelRepr(label* lb);
107 /// _
108 void translatelabels(grammar* g);
109 
110 /// _
111 void addfirstsets(grammar* g);
112 
113 /// _
114 void PyGrammar_AddAccelerators(grammar* g);
115 /// _
116 void PyGrammar_RemoveAccelerators(grammar*);
117 
118 /// _
119 void printgrammar(grammar* g, FILE* fp);
120 /// _
121 void printnonterminals(grammar* g, FILE* fp);
122