You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Go over table-semantics description yet again
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
# Copyright (c) 2015-2017 by Rocky Bernstein
|
# Copyright (c) 2015-2017 by Rocky Bernstein
|
||||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
|
||||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
|
||||||
# Copyright (c) 1999 John Aycock
|
# Copyright (c) 1999 John Aycock
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@@ -97,7 +95,6 @@ TABLE_DIRECT_FRAGMENT = {
|
|||||||
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
|
'importfrom': ( '%|from %[2]{pattr}%x import %c\n', (2, (0, 1)), 3),
|
||||||
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
||||||
'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ),
|
'list_for': (' for %c%x in %c%c', 2, (2, (1, )), 0, 3 ),
|
||||||
'forstmt': ( '%|for%b %c%x in %c:\n%+%c%-\n\n', 0, 3, (3, (2, )), 1, 4 ),
|
|
||||||
'forelsestmt': (
|
'forelsestmt': (
|
||||||
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
'%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
||||||
'forelselaststmt': (
|
'forelselaststmt': (
|
||||||
|
@@ -25,21 +25,28 @@ Python.
|
|||||||
# of the nonterminal is suffixed with "_exit" it will be called after
|
# of the nonterminal is suffixed with "_exit" it will be called after
|
||||||
# all of its children are called.
|
# all of its children are called.
|
||||||
#
|
#
|
||||||
# However if this were done for all of the rules, this file would be even longer
|
# After a while writing methods this way, you'll find many routines which do similar
|
||||||
# than it is already.
|
# sorts of things, and soon you'll find you want a short notation to
|
||||||
|
# describe rules and not have to create methods at all.
|
||||||
#
|
#
|
||||||
# Another more compact way to specify a semantic rule for a nonterminal is via
|
# So another other way to specify a semantic rule for a nonterminal is via
|
||||||
# rule given in one of the tables MAP_R0, MAP_R, or MAP_DIRECT.
|
# one of the tables MAP_R0, MAP_R, or MAP_DIRECT where the key is the
|
||||||
|
# nonterminal name.
|
||||||
#
|
#
|
||||||
# These uses a printf-like syntax to direct substitution from attributes
|
# These dictionaries use a printf-like syntax to direct substitution
|
||||||
# of the nonterminal and its children..
|
# from attributes of the nonterminal and its children..
|
||||||
#
|
#
|
||||||
# The rest of the below describes how table-driven semantic actions work
|
# The rest of the below describes how table-driven semantic actions work
|
||||||
# and gives a list of the format specifiers. The default() and
|
# and gives a list of the format specifiers. The default() and
|
||||||
# template_engine() methods implement most of the below.
|
# template_engine() methods implement most of the below.
|
||||||
#
|
#
|
||||||
# Step 1 determines a table (T) and a path to a
|
# We allow for a couple of ways to interact with a node in a tree. So
|
||||||
# table key (K) from the node type (N) (other nodes are shown as O):
|
# step 1 after not seeing a custom method for a nonterminal is to
|
||||||
|
# determine from what point of view tree-wise the rule is applied.
|
||||||
|
# In the diagram below, "N" is a nonterminal name, and K is the table
|
||||||
|
# key name; we show where those are with respect to each other in the
|
||||||
|
# AST tree for N.
|
||||||
|
#
|
||||||
#
|
#
|
||||||
# N N N&K
|
# N N N&K
|
||||||
# / | ... \ / | ... \ / | ... \
|
# / | ... \ / | ... \ / | ... \
|
||||||
@@ -49,7 +56,10 @@ Python.
|
|||||||
#
|
#
|
||||||
# MAP_R0 (TABLE_R0) MAP_R (TABLE_R) MAP_DIRECT (TABLE_DIRECT)
|
# MAP_R0 (TABLE_R0) MAP_R (TABLE_R) MAP_DIRECT (TABLE_DIRECT)
|
||||||
#
|
#
|
||||||
# The default is a direct mapping. The key K is then extracted from the
|
# The default is a "TABLE_DIRECT" mapping By far, most rules used work this way.
|
||||||
|
# TABLE_R0 is rarely used.
|
||||||
|
#
|
||||||
|
# The key K is then extracted from the
|
||||||
# subtree and used to find a table entry T[K], if any. The result is a
|
# subtree and used to find a table entry T[K], if any. The result is a
|
||||||
# format string and arguments (a la printf()) for the formatting engine.
|
# format string and arguments (a la printf()) for the formatting engine.
|
||||||
# Escapes in the format string are:
|
# Escapes in the format string are:
|
||||||
|
Reference in New Issue
Block a user