NT "_for" -> "for_iter" reduces confusion w/ "for"

This commit is contained in:
rocky
2017-12-12 12:41:44 -05:00
parent b544827192
commit 84b4ac1c51
8 changed files with 27 additions and 27 deletions

View File

@@ -376,20 +376,20 @@ class PythonParser(GenericASTBuilder):
def p_forstmt(self, args): def p_forstmt(self, args):
""" """
_for ::= GET_ITER FOR_ITER for_iter ::= GET_ITER FOR_ITER
for_block ::= l_stmts_opt _come_froms JUMP_BACK for_block ::= l_stmts_opt _come_froms JUMP_BACK
for ::= SETUP_LOOP expr _for store for ::= SETUP_LOOP expr for_iter store
for_block POP_BLOCK _come_froms for_block POP_BLOCK _come_froms
forelsestmt ::= SETUP_LOOP expr _for store forelsestmt ::= SETUP_LOOP expr for_iter store
for_block POP_BLOCK else_suite _come_froms for_block POP_BLOCK else_suite _come_froms
forelselaststmt ::= SETUP_LOOP expr _for store forelselaststmt ::= SETUP_LOOP expr for_iter store
for_block POP_BLOCK else_suitec _come_froms for_block POP_BLOCK else_suitec _come_froms
forelselaststmtl ::= SETUP_LOOP expr _for store forelselaststmtl ::= SETUP_LOOP expr for_iter store
for_block POP_BLOCK else_suitel _come_froms for_block POP_BLOCK else_suitel _come_froms
""" """

View File

@@ -246,7 +246,7 @@ class Python2Parser(PythonParser):
stmt ::= assign2_pypy stmt ::= assign2_pypy
assign3_pypy ::= expr expr expr store store store assign3_pypy ::= expr expr expr store store store
assign2_pypy ::= expr expr store store assign2_pypy ::= expr expr store store
list_comp ::= expr BUILD_LIST_FROM_ARG _for store list_iter list_comp ::= expr BUILD_LIST_FROM_ARG for_iter store list_iter
JUMP_BACK JUMP_BACK
""", nop_func) """, nop_func)

View File

@@ -13,11 +13,11 @@ class Python21Parser(Python22Parser):
def p_forstmt21(self, args): def p_forstmt21(self, args):
""" """
_for ::= LOAD_CONST FOR_LOOP for_iter ::= LOAD_CONST FOR_LOOP
for ::= SETUP_LOOP expr _for store for ::= SETUP_LOOP expr for_iter store
return_stmts return_stmts
POP_BLOCK COME_FROM POP_BLOCK COME_FROM
for ::= SETUP_LOOP expr _for store for ::= SETUP_LOOP expr for_iter store
l_stmts_opt _jump_back l_stmts_opt _jump_back
POP_BLOCK COME_FROM POP_BLOCK COME_FROM

View File

@@ -13,10 +13,10 @@ class Python22Parser(Python23Parser):
def p_misc22(self, args): def p_misc22(self, args):
''' '''
_for ::= LOAD_CONST FOR_LOOP for_iter ::= LOAD_CONST FOR_LOOP
list_iter ::= list_if JUMP_FORWARD list_iter ::= list_if JUMP_FORWARD
COME_FROM POP_TOP COME_FROM COME_FROM POP_TOP COME_FROM
list_for ::= expr _for store list_iter CONTINUE JUMP_FORWARD list_for ::= expr for_iter store list_iter CONTINUE JUMP_FORWARD
COME_FROM POP_TOP COME_FROM COME_FROM POP_TOP COME_FROM
''' '''

View File

@@ -36,7 +36,7 @@ class Python23Parser(Python24Parser):
COME_FROM POP_TOP POP_BLOCK COME_FROM COME_FROM POP_TOP POP_BLOCK COME_FROM
list_comp ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt list_comp ::= BUILD_LIST_0 DUP_TOP LOAD_ATTR store list_iter del_stmt
list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK list_for ::= expr for_iter store list_iter JUMP_BACK come_froms POP_TOP JUMP_BACK
lc_body ::= LOAD_NAME expr CALL_FUNCTION_1 POP_TOP lc_body ::= LOAD_NAME expr CALL_FUNCTION_1 POP_TOP
lc_body ::= LOAD_FAST expr CALL_FUNCTION_1 POP_TOP lc_body ::= LOAD_FAST expr CALL_FUNCTION_1 POP_TOP

View File

@@ -180,23 +180,23 @@ class Python26Parser(Python2Parser):
def p_comp26(self, args): def p_comp26(self, args):
''' '''
list_for ::= expr _for store list_iter JUMP_BACK come_froms POP_TOP list_for ::= expr for_iter store list_iter JUMP_BACK come_froms POP_TOP
# The JUMP FORWARD below jumps to the JUMP BACK. It seems to happen # The JUMP FORWARD below jumps to the JUMP BACK. It seems to happen
# in rare cases that may have to with length of code # in rare cases that may have to with length of code
# FIXME: we can add a reduction check for this # FIXME: we can add a reduction check for this
list_for ::= expr _for store list_iter JUMP_FORWARD come_froms POP_TOP list_for ::= expr for_iter store list_iter JUMP_FORWARD come_froms POP_TOP
COME_FROM JUMP_BACK COME_FROM JUMP_BACK
list_for ::= expr _for store list_iter jb_cont list_for ::= expr for_iter store list_iter jb_cont
# This is for a really funky: # This is for a really funky:
# [ x for x in range(10) if x % 2 if x % 3 ] # [ x for x in range(10) if x % 2 if x % 3 ]
# the JUMP_ABSOLUTE is to the instruction after the last POP_TOP # the JUMP_ABSOLUTE is to the instruction after the last POP_TOP
# we have a reduction check for this # we have a reduction check for this
list_for ::= expr _for store list_iter JUMP_ABSOLUTE come_froms list_for ::= expr for_iter store list_iter JUMP_ABSOLUTE come_froms
POP_TOP jb_pop POP_TOP jb_pop
list_iter ::= list_if JUMP_BACK list_iter ::= list_if JUMP_BACK
@@ -208,7 +208,7 @@ class Python26Parser(Python2Parser):
lc_body ::= LOAD_NAME expr LIST_APPEND lc_body ::= LOAD_NAME expr LIST_APPEND
lc_body ::= LOAD_FAST expr LIST_APPEND lc_body ::= LOAD_FAST expr LIST_APPEND
comp_for ::= SETUP_LOOP expr _for store comp_iter jb_pb_come_from comp_for ::= SETUP_LOOP expr for_iter store comp_iter jb_pb_come_from
comp_body ::= gen_comp_body comp_body ::= gen_comp_body
@@ -314,7 +314,7 @@ class Python26Parser(Python2Parser):
tokens[last].pattr == jmp_false.pattr) tokens[last].pattr == jmp_false.pattr)
elif rule == ( elif rule == (
'list_for', 'list_for',
('expr', '_for', 'store', 'list_iter', ('expr', 'for_iter', 'store', 'list_iter',
'JUMP_ABSOLUTE', 'come_froms', 'POP_TOP', 'jb_pop')): 'JUMP_ABSOLUTE', 'come_froms', 'POP_TOP', 'jb_pop')):
# The JUMP_ABSOLUTE has to be to the last POP_TOP or this is invalid # The JUMP_ABSOLUTE has to be to the last POP_TOP or this is invalid
ja_attr = ast[4].attr ja_attr = ast[4].attr

View File

@@ -14,7 +14,7 @@ class Python27Parser(Python2Parser):
def p_comprehension27(self, args): def p_comprehension27(self, args):
""" """
list_for ::= expr _for store list_iter JUMP_BACK list_for ::= expr for_iter store list_iter JUMP_BACK
list_comp ::= BUILD_LIST_0 list_iter list_comp ::= BUILD_LIST_0 list_iter
lc_body ::= expr LIST_APPEND lc_body ::= expr LIST_APPEND
@@ -33,7 +33,7 @@ class Python27Parser(Python2Parser):
comp_body ::= dict_comp_body comp_body ::= dict_comp_body
comp_body ::= set_comp_body comp_body ::= set_comp_body
comp_for ::= expr _for store comp_iter JUMP_BACK comp_for ::= expr for_iter store comp_iter JUMP_BACK
dict_comp_body ::= expr expr MAP_ADD dict_comp_body ::= expr expr MAP_ADD
set_comp_body ::= expr SET_ADD set_comp_body ::= expr SET_ADD

View File

@@ -38,8 +38,8 @@ class Python3Parser(PythonParser):
# one may be a continue - sometimes classifies a JUMP_BACK # one may be a continue - sometimes classifies a JUMP_BACK
# as a CONTINUE. The two are kind of the same in a comprehension. # as a CONTINUE. The two are kind of the same in a comprehension.
comp_for ::= expr _for store comp_iter CONTINUE comp_for ::= expr for_iter store comp_iter CONTINUE
comp_for ::= expr _for store comp_iter JUMP_BACK comp_for ::= expr for_iter store comp_iter JUMP_BACK
list_comp ::= BUILD_LIST_0 list_iter list_comp ::= BUILD_LIST_0 list_iter
lc_body ::= expr LIST_APPEND lc_body ::= expr LIST_APPEND
@@ -328,16 +328,16 @@ class Python3Parser(PythonParser):
def p_loop_stmt3(self, args): def p_loop_stmt3(self, args):
""" """
for ::= SETUP_LOOP expr _for store for_block POP_BLOCK for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK
COME_FROM_LOOP COME_FROM_LOOP
forelsestmt ::= SETUP_LOOP expr _for store for_block POP_BLOCK else_suite forelsestmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suite
COME_FROM_LOOP COME_FROM_LOOP
forelselaststmt ::= SETUP_LOOP expr _for store for_block POP_BLOCK else_suitec forelselaststmt ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitec
COME_FROM_LOOP COME_FROM_LOOP
forelselaststmtl ::= SETUP_LOOP expr _for store for_block POP_BLOCK else_suitel forelselaststmtl ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK else_suitel
COME_FROM_LOOP COME_FROM_LOOP
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK whilestmt ::= SETUP_LOOP testexpr l_stmts_opt COME_FROM JUMP_BACK POP_BLOCK
@@ -372,7 +372,7 @@ class Python3Parser(PythonParser):
COME_FROM_LOOP COME_FROM_LOOP
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP
COME_FROM_LOOP COME_FROM_LOOP
for ::= SETUP_LOOP expr _for store for_block POP_BLOCK NOP for ::= SETUP_LOOP expr for_iter store for_block POP_BLOCK NOP
COME_FROM_LOOP COME_FROM_LOOP
""" """