grammar reduction of while loops

This commit is contained in:
rocky
2017-11-23 10:51:22 -05:00
parent 1823513841
commit e2a6c0435d
5 changed files with 13 additions and 20 deletions

Binary file not shown.

View File

@@ -372,25 +372,6 @@ class PythonParser(GenericASTBuilder):
for_block POP_BLOCK else_suitel _come_from
"""
def p_whilestmt(self, args):
"""
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK
POP_BLOCK _come_from
whilestmt ::= SETUP_LOOP testexpr return_stmts
POP_BLOCK COME_FROM
whileelsestmt ::= SETUP_LOOP testexpr
l_stmts_opt JUMP_BACK
POP_BLOCK
else_suite COME_FROM
whileelselaststmt ::= SETUP_LOOP testexpr
l_stmts_opt JUMP_BACK
POP_BLOCK
else_suitec COME_FROM
"""
def p_import20(self, args):
"""
stmt ::= importstmt

View File

@@ -143,6 +143,7 @@ class Python26Parser(Python2Parser):
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK _come_from
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_cf_pop bp_come_from
whilestmt ::= SETUP_LOOP testexpr return_stmts come_froms POP_TOP bp_come_from
whilestmt ::= SETUP_LOOP testexpr return_stmts POP_BLOCK COME_FROM
whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt jb_pop POP_BLOCK
else_suite COME_FROM

View File

@@ -103,9 +103,12 @@ class Python27Parser(Python2Parser):
WITH_CLEANUP END_FINALLY
while1stmt ::= SETUP_LOOP return_stmts bp_come_from
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK else_suite COME_FROM
while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK COME_FROM
whilestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK _come_from
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK POP_BLOCK
else_suite COME_FROM
whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
else_suite COME_FROM
# Common with 2.6
return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM

View File

@@ -17,6 +17,14 @@ class Python34Parser(Python33Parser):
"""
expr ::= LOAD_ASSERT
# FIXME the below masks a bug in not detecting COME_FROM_LOOP
# grammar rules with COME_FROM -> COME_FROM_LOOP alreadly exist
whileelselaststmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
else_suitec COME_FROM
whileelsestmt ::= SETUP_LOOP testexpr l_stmts_opt JUMP_BACK POP_BLOCK
else_suite COME_FROM
# Python 3.4+ optimizes the trailing two JUMPS away
# Is this 3.4 only?