[Python-checkins] python/dist/src/Python compile.txt,1.1.2.4,1.1.2.5
bcannon@users.sourceforge.net
bcannon@users.sourceforge.net
Tue, 08 Jul 2003 21:18:04 -0700
Update of /cvsroot/python/python/dist/src/Python
In directory sc8-pr-cvs1:/tmp/cvs-serv22899/Python
Modified Files:
Tag: ast-branch
compile.txt
Log Message:
Basic grammar corrections and add a new CST->AST section.
Index: compile.txt
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/Attic/compile.txt,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -d -r1.1.2.4 -r1.1.2.5
*** compile.txt 29 Apr 2003 00:44:41 -0000 1.1.2.4
--- compile.txt 9 Jul 2003 04:18:02 -0000 1.1.2.5
***************
*** 4,7 ****
--- 4,8 ----
Parsing
-------
+ XXX Fill in
Abstract Syntax Tree (AST)
***************
*** 81,84 ****
--- 82,88 ----
initializes the ``name``, ``args``, and ``body`` fields.
+ CST to AST
+ ----------
+
The parser generates a concrete syntax tree represented by a ``node
*`` defined in ``Include/node.h``. The abstract syntax is generated
***************
*** 87,90 ****
--- 91,109 ----
mod_ty PyAST_FromNode(const node *n);
+ It does this by calling various functions in the file that all have the
+ name ast_for_xxx where xxx is what the rule of the grammar (as defined
+ in ``Grammar/Grammar``) that the function handles (alias_for_import_name
+ is the exception to this). These in turn call the constructor functions
+ as defined by the ASDL grammar to create the nodes of the AST.
+
+ Common macros used as defined in ``Include/node.h``:
+ - CHILD(node, n) -- Returns the nth child of node using zero-offset
+ indexing
+ - NCH(node) -- Number of children node has
+ - STR(node) -- String representation of node
+ - TYPE(node) -- The type of node as listed in ``Include/graminit.h``
+ - REQ(node, type) -- Assert that the node is the type that is expected
+
+
Code Generation and Basic Blocks
--------------------------------
***************
*** 93,97 ****
and the helper functions and macros.
! - for each ast type (mod, stmt, expr, ...) define function with a
switch statement. inline code generation for simple things,
call function compiler_xxx where xxx is kind name for others.
--- 112,116 ----
and the helper functions and macros.
! - for each ast type (mod, stmt, expr, ...), define a function with a
switch statement. inline code generation for simple things,
call function compiler_xxx where xxx is kind name for others.
***************
*** 116,125 ****
- all functions return true on success, false on failure
! Code is generate using a simple basic block interface.
! - each block has single entry point
- possibly multiple exit points
- when generating jumps, always jump to a block
! - for code unit, blocks identified by int id
- NEW_BLOCK() -- create block and set it as current
--- 135,144 ----
- all functions return true on success, false on failure
! Code is generated using a simple, basic block interface.
! - each block has a single entry point
- possibly multiple exit points
- when generating jumps, always jump to a block
! - for a code unit, blocks are identified by its int id
- NEW_BLOCK() -- create block and set it as current
***************
*** 134,138 ****
ADDOP(c, opcode) -- opcode with no arguments
ADDOP_I(c, opcode, oparg) -- oparg is a C int
! ADDOP_O(c, opcode, oparg, namespace) -- oparg is a PyObject *
namespace is the name of a code object member that contains
the set of objects. For example,
--- 153,157 ----
ADDOP(c, opcode) -- opcode with no arguments
ADDOP_I(c, opcode, oparg) -- oparg is a C int
! ADDOP_O(c, opcode, oparg, namespace) -- oparg is a PyObject * ,
namespace is the name of a code object member that contains
the set of objects. For example,
***************
*** 186,190 ****
- ast.c
! Converts Python's concrete syntax tree into abstract syntax.
- compile.txt
--- 205,209 ----
- ast.c
! Converts Python's concrete syntax tree into the abstract syntax tree.
- compile.txt