Guido van Rossum | f70e43a | 1991-02-19 12:39:46 +0000 | [diff] [blame] | 1 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 2 | /* Grammar interface */ |
| 3 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 4 | #ifndef Py_GRAMMAR_H |
| 5 | #define Py_GRAMMAR_H |
| 6 | #ifdef __cplusplus |
| 7 | extern "C" { |
| 8 | #endif |
| 9 | |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 10 | #include "bitset.h" /* Sigh... */ |
| 11 | |
| 12 | /* A label of an arc */ |
| 13 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 14 | typedef struct { |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 15 | int lb_type; |
| 16 | char *lb_str; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 17 | } label; |
| 18 | |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 19 | #define EMPTY 0 /* Label number 0 is by definition the empty label */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 20 | |
| 21 | /* A list of labels */ |
| 22 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 23 | typedef struct { |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 24 | int ll_nlabels; |
| 25 | label *ll_label; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 26 | } labellist; |
| 27 | |
| 28 | /* An arc from one state to another */ |
| 29 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 30 | typedef struct { |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 31 | short a_lbl; /* Label of this arc */ |
| 32 | short a_arrow; /* State where this arc goes to */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 33 | } arc; |
| 34 | |
| 35 | /* A state in a DFA */ |
| 36 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 37 | typedef struct { |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 38 | int s_narcs; |
| 39 | arc *s_arc; /* Array of arcs */ |
Serhiy Storchaka | f402775 | 2015-03-21 09:25:53 +0200 | [diff] [blame] | 40 | |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 41 | /* Optional accelerators */ |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 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 */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 46 | } state; |
| 47 | |
| 48 | /* A DFA */ |
| 49 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 50 | typedef struct { |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 51 | int d_type; /* Non-terminal this represents */ |
| 52 | char *d_name; /* For printing */ |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 53 | int d_nstates; |
| 54 | state *d_state; /* Array of states */ |
| 55 | bitset d_first; |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 56 | } dfa; |
| 57 | |
| 58 | /* A grammar */ |
| 59 | |
Guido van Rossum | b6775db | 1994-08-01 11:34:53 +0000 | [diff] [blame] | 60 | typedef struct { |
Serhiy Storchaka | 598ceae | 2017-11-28 17:56:10 +0200 | [diff] [blame] | 61 | int g_ndfas; |
| 62 | dfa *g_dfa; /* Array of DFAs */ |
| 63 | labellist g_ll; |
| 64 | int g_start; /* Start symbol of the grammar */ |
| 65 | int g_accel; /* Set if accelerators present */ |
Guido van Rossum | 85a5fbb | 1990-10-14 12:07:46 +0000 | [diff] [blame] | 66 | } grammar; |
| 67 | |
| 68 | /* FUNCTIONS */ |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 69 | dfa *PyGrammar_FindDFA(grammar *g, int type); |
Benjamin Peterson | 742b2f8 | 2012-10-31 13:36:13 -0400 | [diff] [blame] | 70 | const char *PyGrammar_LabelRepr(label *lb); |
Fred Drake | ea9cb5a | 2000-07-09 00:20:36 +0000 | [diff] [blame] | 71 | void PyGrammar_AddAccelerators(grammar *g); |
| 72 | void PyGrammar_RemoveAccelerators(grammar *); |
Guido van Rossum | 3f5da24 | 1990-12-20 15:06:42 +0000 | [diff] [blame] | 73 | |
Guido van Rossum | a330996 | 1993-07-28 09:05:47 +0000 | [diff] [blame] | 74 | #ifdef __cplusplus |
| 75 | } |
| 76 | #endif |
| 77 | #endif /* !Py_GRAMMAR_H */ |