Skip to content

Commit 1b304f9

Browse files
tyomitchpablogsal
authored andcommitted
Remove d_initial from the parser as it is unused (GH-12212)
d_initial, the first state of a particular DFA in the parser has always been initialized to 0 in the old pgen as well as the new pgen. As this value is not used and the first state of each DFA is assumed to be the first element in the array representing it, remove d_initial from the parser to reduce complexity.
1 parent d70a359 commit 1b304f9

File tree

4 files changed

+94
-95
lines changed

4 files changed

+94
-95
lines changed

Include/grammar.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ typedef struct {
5050
typedef struct {
5151
int d_type; /* Non-terminal this represents */
5252
char *d_name; /* For printing */
53-
int d_initial; /* Initial state */
5453
int d_nstates;
5554
state *d_state; /* Array of states */
5655
bitset d_first;

Modules/parsermodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ validate_node(node *tree)
662662
REQ(tree, nt_dfa->d_type);
663663

664664
/* Run the DFA for this nonterminal. */
665-
dfa_state = &nt_dfa->d_state[nt_dfa->d_initial];
665+
dfa_state = nt_dfa->d_state;
666666
for (pos = 0; pos < nch; ++pos) {
667667
node *ch = CHILD(tree, pos);
668668
int ch_type = TYPE(ch);

Parser/pgen/grammar.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def print_dfas(self, writer):
9797
' {{{dfa_symbol}, "{symbol_name}", '.format(
9898
dfa_symbol=symbol, symbol_name=self.number2symbol[symbol]
9999
)
100-
+ "0, {n_states}, states_{dfa_index},\n".format(
100+
+ "{n_states}, states_{dfa_index},\n".format(
101101
n_states=len(dfa), dfa_index=dfaindex
102102
)
103103
+ ' "'

Python/graminit.c

Lines changed: 92 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -2110,189 +2110,189 @@ static state states_91[11] = {
21102110
{2, arcs_91_10},
21112111
};
21122112
static dfa dfas[92] = {
2113-
{256, "single_input", 0, 3, states_0,
2113+
{256, "single_input", 3, states_0,
21142114
"\344\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2115-
{257, "file_input", 0, 2, states_1,
2115+
{257, "file_input", 2, states_1,
21162116
"\344\377\377\377\377\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2117-
{258, "eval_input", 0, 3, states_2,
2117+
{258, "eval_input", 3, states_2,
21182118
"\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2119-
{259, "decorator", 0, 7, states_3,
2119+
{259, "decorator", 7, states_3,
21202120
"\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2121-
{260, "decorators", 0, 2, states_4,
2121+
{260, "decorators", 2, states_4,
21222122
"\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2123-
{261, "decorated", 0, 3, states_5,
2123+
{261, "decorated", 3, states_5,
21242124
"\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2125-
{262, "async_funcdef", 0, 3, states_6,
2125+
{262, "async_funcdef", 3, states_6,
21262126
"\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2127-
{263, "funcdef", 0, 9, states_7,
2127+
{263, "funcdef", 9, states_7,
21282128
"\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2129-
{264, "parameters", 0, 4, states_8,
2129+
{264, "parameters", 4, states_8,
21302130
"\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2131-
{265, "typedargslist", 0, 22, states_9,
2131+
{265, "typedargslist", 22, states_9,
21322132
"\100\000\000\000\000\001\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2133-
{266, "tfpdef", 0, 4, states_10,
2133+
{266, "tfpdef", 4, states_10,
21342134
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2135-
{267, "varargslist", 0, 18, states_11,
2135+
{267, "varargslist", 18, states_11,
21362136
"\100\000\000\000\000\001\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2137-
{268, "vfpdef", 0, 2, states_12,
2137+
{268, "vfpdef", 2, states_12,
21382138
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2139-
{269, "stmt", 0, 2, states_13,
2139+
{269, "stmt", 2, states_13,
21402140
"\340\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2141-
{270, "simple_stmt", 0, 4, states_14,
2141+
{270, "simple_stmt", 4, states_14,
21422142
"\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2143-
{271, "small_stmt", 0, 2, states_15,
2143+
{271, "small_stmt", 2, states_15,
21442144
"\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2145-
{272, "expr_stmt", 0, 6, states_16,
2145+
{272, "expr_stmt", 6, states_16,
21462146
"\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2147-
{273, "annassign", 0, 5, states_17,
2147+
{273, "annassign", 5, states_17,
21482148
"\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2149-
{274, "testlist_star_expr", 0, 3, states_18,
2149+
{274, "testlist_star_expr", 3, states_18,
21502150
"\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2151-
{275, "augassign", 0, 2, states_19,
2151+
{275, "augassign", 2, states_19,
21522152
"\000\000\000\000\000\000\000\000\000\000\340\377\003\000\000\000\000\000\000\000\000\000\000"},
2153-
{276, "del_stmt", 0, 3, states_20,
2153+
{276, "del_stmt", 3, states_20,
21542154
"\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2155-
{277, "pass_stmt", 0, 2, states_21,
2155+
{277, "pass_stmt", 2, states_21,
21562156
"\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2157-
{278, "flow_stmt", 0, 2, states_22,
2157+
{278, "flow_stmt", 2, states_22,
21582158
"\000\000\005\300\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2159-
{279, "break_stmt", 0, 2, states_23,
2159+
{279, "break_stmt", 2, states_23,
21602160
"\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2161-
{280, "continue_stmt", 0, 2, states_24,
2161+
{280, "continue_stmt", 2, states_24,
21622162
"\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2163-
{281, "return_stmt", 0, 3, states_25,
2163+
{281, "return_stmt", 3, states_25,
21642164
"\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2165-
{282, "yield_stmt", 0, 2, states_26,
2165+
{282, "yield_stmt", 2, states_26,
21662166
"\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2167-
{283, "raise_stmt", 0, 5, states_27,
2167+
{283, "raise_stmt", 5, states_27,
21682168
"\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2169-
{284, "import_stmt", 0, 2, states_28,
2169+
{284, "import_stmt", 2, states_28,
21702170
"\000\000\100\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2171-
{285, "import_name", 0, 3, states_29,
2171+
{285, "import_name", 3, states_29,
21722172
"\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2173-
{286, "import_from", 0, 8, states_30,
2173+
{286, "import_from", 8, states_30,
21742174
"\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2175-
{287, "import_as_name", 0, 4, states_31,
2175+
{287, "import_as_name", 4, states_31,
21762176
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2177-
{288, "dotted_as_name", 0, 4, states_32,
2177+
{288, "dotted_as_name", 4, states_32,
21782178
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2179-
{289, "import_as_names", 0, 3, states_33,
2179+
{289, "import_as_names", 3, states_33,
21802180
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2181-
{290, "dotted_as_names", 0, 2, states_34,
2181+
{290, "dotted_as_names", 2, states_34,
21822182
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2183-
{291, "dotted_name", 0, 2, states_35,
2183+
{291, "dotted_name", 2, states_35,
21842184
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2185-
{292, "global_stmt", 0, 3, states_36,
2185+
{292, "global_stmt", 3, states_36,
21862186
"\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2187-
{293, "nonlocal_stmt", 0, 3, states_37,
2187+
{293, "nonlocal_stmt", 3, states_37,
21882188
"\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2189-
{294, "assert_stmt", 0, 5, states_38,
2189+
{294, "assert_stmt", 5, states_38,
21902190
"\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2191-
{295, "compound_stmt", 0, 2, states_39,
2191+
{295, "compound_stmt", 2, states_39,
21922192
"\000\004\052\001\107\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2193-
{296, "async_stmt", 0, 3, states_40,
2193+
{296, "async_stmt", 3, states_40,
21942194
"\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2195-
{297, "if_stmt", 0, 8, states_41,
2195+
{297, "if_stmt", 8, states_41,
21962196
"\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2197-
{298, "while_stmt", 0, 8, states_42,
2197+
{298, "while_stmt", 8, states_42,
21982198
"\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2199-
{299, "for_stmt", 0, 11, states_43,
2199+
{299, "for_stmt", 11, states_43,
22002200
"\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2201-
{300, "try_stmt", 0, 13, states_44,
2201+
{300, "try_stmt", 13, states_44,
22022202
"\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2203-
{301, "with_stmt", 0, 6, states_45,
2203+
{301, "with_stmt", 6, states_45,
22042204
"\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2205-
{302, "with_item", 0, 4, states_46,
2205+
{302, "with_item", 4, states_46,
22062206
"\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2207-
{303, "except_clause", 0, 5, states_47,
2207+
{303, "except_clause", 5, states_47,
22082208
"\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
2209-
{304, "suite", 0, 5, states_48,
2209+
{304, "suite", 5, states_48,
22102210
"\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2211-
{305, "namedexpr_test", 0, 4, states_49,
2211+
{305, "namedexpr_test", 4, states_49,
22122212
"\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2213-
{306, "test", 0, 6, states_50,
2213+
{306, "test", 6, states_50,
22142214
"\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2215-
{307, "test_nocond", 0, 2, states_51,
2215+
{307, "test_nocond", 2, states_51,
22162216
"\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2217-
{308, "lambdef", 0, 5, states_52,
2217+
{308, "lambdef", 5, states_52,
22182218
"\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2219-
{309, "lambdef_nocond", 0, 5, states_53,
2219+
{309, "lambdef_nocond", 5, states_53,
22202220
"\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2221-
{310, "or_test", 0, 2, states_54,
2221+
{310, "or_test", 2, states_54,
22222222
"\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2223-
{311, "and_test", 0, 2, states_55,
2223+
{311, "and_test", 2, states_55,
22242224
"\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2225-
{312, "not_test", 0, 3, states_56,
2225+
{312, "not_test", 3, states_56,
22262226
"\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2227-
{313, "comparison", 0, 2, states_57,
2227+
{313, "comparison", 2, states_57,
22282228
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2229-
{314, "comp_op", 0, 4, states_58,
2229+
{314, "comp_op", 4, states_58,
22302230
"\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\004\000\340\017\000\000\000\000"},
2231-
{315, "star_expr", 0, 3, states_59,
2231+
{315, "star_expr", 3, states_59,
22322232
"\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2233-
{316, "expr", 0, 2, states_60,
2233+
{316, "expr", 2, states_60,
22342234
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2235-
{317, "xor_expr", 0, 2, states_61,
2235+
{317, "xor_expr", 2, states_61,
22362236
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2237-
{318, "and_expr", 0, 2, states_62,
2237+
{318, "and_expr", 2, states_62,
22382238
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2239-
{319, "shift_expr", 0, 2, states_63,
2239+
{319, "shift_expr", 2, states_63,
22402240
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2241-
{320, "arith_expr", 0, 2, states_64,
2241+
{320, "arith_expr", 2, states_64,
22422242
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2243-
{321, "term", 0, 2, states_65,
2243+
{321, "term", 2, states_65,
22442244
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2245-
{322, "factor", 0, 3, states_66,
2245+
{322, "factor", 3, states_66,
22462246
"\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2247-
{323, "power", 0, 4, states_67,
2247+
{323, "power", 4, states_67,
22482248
"\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2249-
{324, "atom_expr", 0, 3, states_68,
2249+
{324, "atom_expr", 3, states_68,
22502250
"\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2251-
{325, "atom", 0, 9, states_69,
2251+
{325, "atom", 9, states_69,
22522252
"\040\172\000\000\020\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2253-
{326, "testlist_comp", 0, 5, states_70,
2253+
{326, "testlist_comp", 5, states_70,
22542254
"\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2255-
{327, "trailer", 0, 7, states_71,
2255+
{327, "trailer", 7, states_71,
22562256
"\040\100\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"},
2257-
{328, "subscriptlist", 0, 3, states_72,
2257+
{328, "subscriptlist", 3, states_72,
22582258
"\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2259-
{329, "subscript", 0, 5, states_73,
2259+
{329, "subscript", 5, states_73,
22602260
"\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2261-
{330, "sliceop", 0, 3, states_74,
2261+
{330, "sliceop", 3, states_74,
22622262
"\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2263-
{331, "exprlist", 0, 3, states_75,
2263+
{331, "exprlist", 3, states_75,
22642264
"\340\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2265-
{332, "testlist", 0, 3, states_76,
2265+
{332, "testlist", 3, states_76,
22662266
"\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2267-
{333, "dictorsetmaker", 0, 14, states_77,
2267+
{333, "dictorsetmaker", 14, states_77,
22682268
"\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2269-
{334, "classdef", 0, 8, states_78,
2269+
{334, "classdef", 8, states_78,
22702270
"\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2271-
{335, "arglist", 0, 3, states_79,
2271+
{335, "arglist", 3, states_79,
22722272
"\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2273-
{336, "argument", 0, 4, states_80,
2273+
{336, "argument", 4, states_80,
22742274
"\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2275-
{337, "comp_iter", 0, 2, states_81,
2275+
{337, "comp_iter", 2, states_81,
22762276
"\000\000\040\001\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2277-
{338, "sync_comp_for", 0, 6, states_82,
2277+
{338, "sync_comp_for", 6, states_82,
22782278
"\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2279-
{339, "comp_for", 0, 3, states_83,
2279+
{339, "comp_for", 3, states_83,
22802280
"\000\000\040\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2281-
{340, "comp_if", 0, 4, states_84,
2281+
{340, "comp_if", 4, states_84,
22822282
"\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2283-
{341, "encoding_decl", 0, 2, states_85,
2283+
{341, "encoding_decl", 2, states_85,
22842284
"\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2285-
{342, "yield_expr", 0, 3, states_86,
2285+
{342, "yield_expr", 3, states_86,
22862286
"\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2287-
{343, "yield_arg", 0, 3, states_87,
2287+
{343, "yield_arg", 3, states_87,
22882288
"\340\173\100\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2289-
{344, "func_body_suite", 0, 7, states_88,
2289+
{344, "func_body_suite", 7, states_88,
22902290
"\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2291-
{345, "func_type_input", 0, 3, states_89,
2291+
{345, "func_type_input", 3, states_89,
22922292
"\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2293-
{346, "func_type", 0, 6, states_90,
2293+
{346, "func_type", 6, states_90,
22942294
"\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
2295-
{347, "typelist", 0, 11, states_91,
2295+
{347, "typelist", 11, states_91,
22962296
"\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
22972297
};
22982298
static label labels[183] = {

0 commit comments

Comments
 (0)