PageRenderTime 53ms CodeModel.GetById 42ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 0ms

/Include/grammar.h

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