Python 2.6 a == b or c == d == 3 grammar bug

This commit is contained in:
rocky
2017-02-28 09:18:36 -05:00
parent 65913778a5
commit e1111e3f50
3 changed files with 7 additions and 2 deletions

View File

@@ -112,7 +112,7 @@ with handling control flow. All of the Python decompilers I have looked
at have the same problem. In some cases we can detect an erroneous
decompilation and report that.
About 90% of the decompilation of Python standard library packages in
Over 98% of the decompilation of Python standard library packages in
Python 2.7.12 verifies correctly. Over 99% of Python 2.7 and 3.3-3.5
"weakly" verify. Python 2.6 drops down to 96% weakly verifying.
Other versions drop off in quality too.

View File

@@ -38,6 +38,12 @@ class PythonParser(GenericASTBuilder):
# PyPy:
'kvlist_n'])
def ast_first_offset(self, ast):
if hasattr(ast, 'offset'):
return ast.offset
else:
return self.ast_first_offset(ast[0])
def add_unique_rule(self, rule, opname, count, customize):
"""Add rule to grammar, but only if it hasn't been added previously
opname and count are used in the customize() semantic the actions

View File

@@ -157,7 +157,6 @@ class Python26Parser(Python2Parser):
# Semantic actions want the else to be at position 3
ifelsestmt ::= testexpr c_stmts_opt jf_cf_pop else_suite come_froms
ifelsestmt ::= testexpr_then c_stmts_opt jf_cf_pop else_suite come_froms
ifelsestmt ::= testexpr c_stmts_opt filler else_suitel come_froms POP_TOP
ifelsestmt ::= testexpr_then c_stmts_opt filler else_suitel come_froms POP_TOP
# Semantic actions want else_suitel to be at index 3