Some Python 3.4 grammar rules apply to Python 3.3

This commit is contained in:
rocky
2016-11-06 10:00:10 -05:00
parent 41f360e3dc
commit fef0567746
2 changed files with 16 additions and 17 deletions

View File

@@ -12,8 +12,21 @@ class Python33Parser(Python32Parser):
def p_33on(self, args):
"""
# Python 3.3+ adds yield from.
expr ::= yield_from
yield_from ::= expr expr YIELD_FROM
expr ::= yield_from
yield_from ::= expr expr YIELD_FROM
# We do the grammar hackery below for semantics
# actions that want c_stmts_opt at index 1
iflaststmt ::= testexpr c_stmts_opt33
iflaststmtl ::= testexpr c_stmts_opt
c_stmts_opt33 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
# Python 3.3+ has more loop optimization that removes
# JUMP_FORWARD in some cases, and hence we also don't
# see COME_FROM
_ifstmts_jump ::= c_stmts_opt
"""
class Python33ParserSingle(Python33Parser, PythonParserSingle):

View File

@@ -15,26 +15,12 @@ class Python34Parser(Python33Parser):
def p_misc34(self, args):
"""
# Python 3.5+ optimizes the trailing two JUMPS away
# Python 3.4+ optimizes the trailing two JUMPS away
for_block ::= l_stmts
iflaststmtl ::= testexpr c_stmts_opt
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD _come_from
# We do the grammar hackery below for semantics
# actions that want c_stmts_opt at index 1
iflaststmt ::= testexpr c_stmts_opt34
c_stmts_opt34 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
# Is this 3.4 only?
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
# Python 3.4+ has more loop optimization that removes
# JUMP_FORWARD in some cases, and hence we also don't
# see COME_FROM
_ifstmts_jump ::= c_stmts_opt
"""
class Python34ParserSingle(Python34Parser, PythonParserSingle):
pass