[Python-checkins] Remove d_initial from the parser as it is unused (GH-12212)

Pablo Galindo webhook-mailer at python.org
Sat Mar 9 10:35:53 EST 2019


https://github.com/python/cpython/commit/1b304f992ddfc1cc40758dd633bc6a2595399189
commit: 1b304f992ddfc1cc40758dd633bc6a2595399189
branch: master
author: tyomitch <tyomitch at gmail.com>
committer: Pablo Galindo <Pablogsal at gmail.com>
date: 2019-03-09T15:35:50Z
summary:

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.

files:
M Include/grammar.h
M Modules/parsermodule.c
M Parser/pgen/grammar.py
M Python/graminit.c

diff --git a/Include/grammar.h b/Include/grammar.h
index e1703f4b3603..68b928c97189 100644
--- a/Include/grammar.h
+++ b/Include/grammar.h
@@ -50,7 +50,6 @@ typedef struct {
 typedef struct {
     int          d_type;        /* Non-terminal this represents */
     char        *d_name;        /* For printing */
-    int          d_initial;     /* Initial state */
     int          d_nstates;
     state       *d_state;       /* Array of states */
     bitset       d_first;
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index d4e2be643e71..b0a749a3bc17 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -662,7 +662,7 @@ validate_node(node *tree)
     REQ(tree, nt_dfa->d_type);
 
     /* Run the DFA for this nonterminal. */
-    dfa_state = &nt_dfa->d_state[nt_dfa->d_initial];
+    dfa_state = nt_dfa->d_state;
     for (pos = 0; pos < nch; ++pos) {
         node *ch = CHILD(tree, pos);
         int ch_type = TYPE(ch);
diff --git a/Parser/pgen/grammar.py b/Parser/pgen/grammar.py
index 05a37d67832d..340bf64f6d23 100644
--- a/Parser/pgen/grammar.py
+++ b/Parser/pgen/grammar.py
@@ -97,7 +97,7 @@ def print_dfas(self, writer):
                 '    {{{dfa_symbol}, "{symbol_name}", '.format(
                     dfa_symbol=symbol, symbol_name=self.number2symbol[symbol]
                 )
-                + "0, {n_states}, states_{dfa_index},\n".format(
+                + "{n_states}, states_{dfa_index},\n".format(
                     n_states=len(dfa), dfa_index=dfaindex
                 )
                 + '     "'
diff --git a/Python/graminit.c b/Python/graminit.c
index 24f6f6c72a6b..441502e90876 100644
--- a/Python/graminit.c
+++ b/Python/graminit.c
@@ -2110,189 +2110,189 @@ static state states_91[11] = {
     {2, arcs_91_10},
 };
 static dfa dfas[92] = {
-    {256, "single_input", 0, 3, states_0,
+    {256, "single_input", 3, states_0,
      "\344\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {257, "file_input", 0, 2, states_1,
+    {257, "file_input", 2, states_1,
      "\344\377\377\377\377\027\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {258, "eval_input", 0, 3, states_2,
+    {258, "eval_input", 3, states_2,
      "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {259, "decorator", 0, 7, states_3,
+    {259, "decorator", 7, states_3,
      "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {260, "decorators", 0, 2, states_4,
+    {260, "decorators", 2, states_4,
      "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {261, "decorated", 0, 3, states_5,
+    {261, "decorated", 3, states_5,
      "\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {262, "async_funcdef", 0, 3, states_6,
+    {262, "async_funcdef", 3, states_6,
      "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {263, "funcdef", 0, 9, states_7,
+    {263, "funcdef", 9, states_7,
      "\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {264, "parameters", 0, 4, states_8,
+    {264, "parameters", 4, states_8,
      "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {265, "typedargslist", 0, 22, states_9,
+    {265, "typedargslist", 22, states_9,
      "\100\000\000\000\000\001\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {266, "tfpdef", 0, 4, states_10,
+    {266, "tfpdef", 4, states_10,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {267, "varargslist", 0, 18, states_11,
+    {267, "varargslist", 18, states_11,
      "\100\000\000\000\000\001\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {268, "vfpdef", 0, 2, states_12,
+    {268, "vfpdef", 2, states_12,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {269, "stmt", 0, 2, states_13,
+    {269, "stmt", 2, states_13,
      "\340\377\377\377\377\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {270, "simple_stmt", 0, 4, states_14,
+    {270, "simple_stmt", 4, states_14,
      "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {271, "small_stmt", 0, 2, states_15,
+    {271, "small_stmt", 2, states_15,
      "\340\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {272, "expr_stmt", 0, 6, states_16,
+    {272, "expr_stmt", 6, states_16,
      "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {273, "annassign", 0, 5, states_17,
+    {273, "annassign", 5, states_17,
      "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {274, "testlist_star_expr", 0, 3, states_18,
+    {274, "testlist_star_expr", 3, states_18,
      "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {275, "augassign", 0, 2, states_19,
+    {275, "augassign", 2, states_19,
      "\000\000\000\000\000\000\000\000\000\000\340\377\003\000\000\000\000\000\000\000\000\000\000"},
-    {276, "del_stmt", 0, 3, states_20,
+    {276, "del_stmt", 3, states_20,
      "\000\000\020\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {277, "pass_stmt", 0, 2, states_21,
+    {277, "pass_stmt", 2, states_21,
      "\000\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {278, "flow_stmt", 0, 2, states_22,
+    {278, "flow_stmt", 2, states_22,
      "\000\000\005\300\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {279, "break_stmt", 0, 2, states_23,
+    {279, "break_stmt", 2, states_23,
      "\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {280, "continue_stmt", 0, 2, states_24,
+    {280, "continue_stmt", 2, states_24,
      "\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {281, "return_stmt", 0, 3, states_25,
+    {281, "return_stmt", 3, states_25,
      "\000\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {282, "yield_stmt", 0, 2, states_26,
+    {282, "yield_stmt", 2, states_26,
      "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {283, "raise_stmt", 0, 5, states_27,
+    {283, "raise_stmt", 5, states_27,
      "\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {284, "import_stmt", 0, 2, states_28,
+    {284, "import_stmt", 2, states_28,
      "\000\000\100\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {285, "import_name", 0, 3, states_29,
+    {285, "import_name", 3, states_29,
      "\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {286, "import_from", 0, 8, states_30,
+    {286, "import_from", 8, states_30,
      "\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {287, "import_as_name", 0, 4, states_31,
+    {287, "import_as_name", 4, states_31,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {288, "dotted_as_name", 0, 4, states_32,
+    {288, "dotted_as_name", 4, states_32,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {289, "import_as_names", 0, 3, states_33,
+    {289, "import_as_names", 3, states_33,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {290, "dotted_as_names", 0, 2, states_34,
+    {290, "dotted_as_names", 2, states_34,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {291, "dotted_name", 0, 2, states_35,
+    {291, "dotted_name", 2, states_35,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {292, "global_stmt", 0, 3, states_36,
+    {292, "global_stmt", 3, states_36,
      "\000\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {293, "nonlocal_stmt", 0, 3, states_37,
+    {293, "nonlocal_stmt", 3, states_37,
      "\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {294, "assert_stmt", 0, 5, states_38,
+    {294, "assert_stmt", 5, states_38,
      "\000\200\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {295, "compound_stmt", 0, 2, states_39,
+    {295, "compound_stmt", 2, states_39,
      "\000\004\052\001\107\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {296, "async_stmt", 0, 3, states_40,
+    {296, "async_stmt", 3, states_40,
      "\000\000\000\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {297, "if_stmt", 0, 8, states_41,
+    {297, "if_stmt", 8, states_41,
      "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {298, "while_stmt", 0, 8, states_42,
+    {298, "while_stmt", 8, states_42,
      "\000\000\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {299, "for_stmt", 0, 11, states_43,
+    {299, "for_stmt", 11, states_43,
      "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {300, "try_stmt", 0, 13, states_44,
+    {300, "try_stmt", 13, states_44,
      "\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {301, "with_stmt", 0, 6, states_45,
+    {301, "with_stmt", 6, states_45,
      "\000\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {302, "with_item", 0, 4, states_46,
+    {302, "with_item", 4, states_46,
      "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {303, "except_clause", 0, 5, states_47,
+    {303, "except_clause", 5, states_47,
      "\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\200\000\000\000\000\000\000\000"},
-    {304, "suite", 0, 5, states_48,
+    {304, "suite", 5, states_48,
      "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {305, "namedexpr_test", 0, 4, states_49,
+    {305, "namedexpr_test", 4, states_49,
      "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {306, "test", 0, 6, states_50,
+    {306, "test", 6, states_50,
      "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {307, "test_nocond", 0, 2, states_51,
+    {307, "test_nocond", 2, states_51,
      "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {308, "lambdef", 0, 5, states_52,
+    {308, "lambdef", 5, states_52,
      "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {309, "lambdef_nocond", 0, 5, states_53,
+    {309, "lambdef_nocond", 5, states_53,
      "\000\000\000\004\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {310, "or_test", 0, 2, states_54,
+    {310, "or_test", 2, states_54,
      "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {311, "and_test", 0, 2, states_55,
+    {311, "and_test", 2, states_55,
      "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {312, "not_test", 0, 3, states_56,
+    {312, "not_test", 3, states_56,
      "\240\173\000\020\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {313, "comparison", 0, 2, states_57,
+    {313, "comparison", 2, states_57,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {314, "comp_op", 0, 4, states_58,
+    {314, "comp_op", 4, states_58,
      "\000\000\000\020\000\000\000\000\000\000\000\000\000\000\000\004\000\340\017\000\000\000\000"},
-    {315, "star_expr", 0, 3, states_59,
+    {315, "star_expr", 3, states_59,
      "\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {316, "expr", 0, 2, states_60,
+    {316, "expr", 2, states_60,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {317, "xor_expr", 0, 2, states_61,
+    {317, "xor_expr", 2, states_61,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {318, "and_expr", 0, 2, states_62,
+    {318, "and_expr", 2, states_62,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {319, "shift_expr", 0, 2, states_63,
+    {319, "shift_expr", 2, states_63,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {320, "arith_expr", 0, 2, states_64,
+    {320, "arith_expr", 2, states_64,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {321, "term", 0, 2, states_65,
+    {321, "term", 2, states_65,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {322, "factor", 0, 3, states_66,
+    {322, "factor", 3, states_66,
      "\240\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {323, "power", 0, 4, states_67,
+    {323, "power", 4, states_67,
      "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {324, "atom_expr", 0, 3, states_68,
+    {324, "atom_expr", 3, states_68,
      "\040\172\000\000\220\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {325, "atom", 0, 9, states_69,
+    {325, "atom", 9, states_69,
      "\040\172\000\000\020\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {326, "testlist_comp", 0, 5, states_70,
+    {326, "testlist_comp", 5, states_70,
      "\340\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {327, "trailer", 0, 7, states_71,
+    {327, "trailer", 7, states_71,
      "\040\100\000\000\000\000\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000"},
-    {328, "subscriptlist", 0, 3, states_72,
+    {328, "subscriptlist", 3, states_72,
      "\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {329, "subscript", 0, 5, states_73,
+    {329, "subscript", 5, states_73,
      "\240\173\000\024\260\007\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {330, "sliceop", 0, 3, states_74,
+    {330, "sliceop", 3, states_74,
      "\000\000\000\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {331, "exprlist", 0, 3, states_75,
+    {331, "exprlist", 3, states_75,
      "\340\173\000\000\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {332, "testlist", 0, 3, states_76,
+    {332, "testlist", 3, states_76,
      "\240\173\000\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {333, "dictorsetmaker", 0, 14, states_77,
+    {333, "dictorsetmaker", 14, states_77,
      "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {334, "classdef", 0, 8, states_78,
+    {334, "classdef", 8, states_78,
      "\000\000\002\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {335, "arglist", 0, 3, states_79,
+    {335, "arglist", 3, states_79,
      "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {336, "argument", 0, 4, states_80,
+    {336, "argument", 4, states_80,
      "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {337, "comp_iter", 0, 2, states_81,
+    {337, "comp_iter", 2, states_81,
      "\000\000\040\001\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {338, "sync_comp_for", 0, 6, states_82,
+    {338, "sync_comp_for", 6, states_82,
      "\000\000\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {339, "comp_for", 0, 3, states_83,
+    {339, "comp_for", 3, states_83,
      "\000\000\040\000\100\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {340, "comp_if", 0, 4, states_84,
+    {340, "comp_if", 4, states_84,
      "\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {341, "encoding_decl", 0, 2, states_85,
+    {341, "encoding_decl", 2, states_85,
      "\000\000\000\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {342, "yield_expr", 0, 3, states_86,
+    {342, "yield_expr", 3, states_86,
      "\000\000\000\000\010\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {343, "yield_arg", 0, 3, states_87,
+    {343, "yield_arg", 3, states_87,
      "\340\173\100\024\260\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {344, "func_body_suite", 0, 7, states_88,
+    {344, "func_body_suite", 7, states_88,
      "\344\373\325\376\270\007\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {345, "func_type_input", 0, 3, states_89,
+    {345, "func_type_input", 3, states_89,
      "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {346, "func_type", 0, 6, states_90,
+    {346, "func_type", 6, states_90,
      "\040\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
-    {347, "typelist", 0, 11, states_91,
+    {347, "typelist", 11, states_91,
      "\340\173\000\024\260\007\000\000\001\000\000\000\000\000\000\000\000\000\000\000\000\000\000"},
 };
 static label labels[183] = {



More information about the Python-checkins mailing list