diff -r ac2b3bafd41c compiler.rst --- a/compiler.rst Sat Jan 09 16:35:11 2016 +0200 +++ b/compiler.rst Sun Jan 10 14:51:01 2016 +0200 @@ -39,10 +39,10 @@ implementation laid out in the Dragon Book [Aho86]_. The grammar file for Python can be found in Grammar/Grammar with the -numeric value of grammar rules are stored in Include/graminit.h. The +numeric value of grammar rules stored in Include/graminit.h. The numeric values for types of tokens (literal tokens, such as ``:``, -numbers, etc.) are kept in Include/token.h). The parse tree made up of -``node *`` structs (as defined in Include/node.h). +numbers, etc.) are kept in Include/token.h). The parse tree is made up +of ``node *`` structs (as defined in Include/node.h). Querying data from the node structs can be done with the following macros (which are all defined in Include/node.h): @@ -65,14 +65,14 @@ retrieve the line number of the source code that led to the creation of the parse rule; defined in Python/ast.c -To tie all of this example, consider the rule for 'while':: +For example, consider the rule for 'while':: while_stmt: 'while' test ':' suite ['else' ':' suite] The node representing this will have ``TYPE(node) == while_stmt`` and -the number of children can be 4 or 7 depending on if there is an 'else' -statement. To access what should be the first ':' and require it be an -actual ':' token, `(REQ(CHILD(node, 2), COLON)``. +the number of children can be 4 or 7 depending on whether there is an +'else' statement. ``(REQ(CHILD(node, 2), COLON)`` can be used to access +what should be the first ``:`` and require it be an actual ``:`` token. Abstract Syntax Trees (AST) @@ -175,7 +175,7 @@ PyArena_New() will create a new arena. The returned PyArena structure will store pointers to all memory given to it. This does the bookkeeping of what memory needs to be freed when the compiler is finished with the memory it used. -That freeing is done with PyArena_Free(). This needs to only be called in +That freeing is done with PyArena_Free(). This only needs to be called in strategic areas where the compiler exits. As stated above, in general you should not have to worry about memory @@ -209,7 +209,7 @@ you need to watch out for the ':' token to find the end of the conditional). The functions called to generate AST nodes from the parse tree all have -the name ast_for_xx where xx is what the grammar rule that the function +the name ast_for_xx where xx is the grammar rule 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 and contained in Python/Python-ast.c (which was generated by @@ -218,7 +218,7 @@ Function and macros for creating and using ``asdl_seq *`` types as found -in Python/asdl.c and Include/asdl.h: +in Python/asdl.c and Include/asdl.h are as follows: ``asdl_seq_new()`` Allocate memory for an asdl_seq for the specified length @@ -435,8 +435,8 @@ Python-ast.c Creates C structs corresponding to the ASDL types. Also - contains code for marshaling AST nodes (core ASDL types have - marshaling code in asdl.c). "File automatically generated by + contains code for marshalling AST nodes (core ASDL types have + marshalling code in asdl.c). "File automatically generated by Parser/asdl_c.py". This file must be committed separately after every grammar change is committed since the __version__ value is set to the latest grammar change revision number. @@ -444,7 +444,7 @@ asdl.c Contains code to handle the ASDL sequence type. Also has code to handle marshalling the core ASDL types, such as number and - identifier. used by Python-ast.c for marshaling AST nodes. + identifier. Used by Python-ast.c for marshalling AST nodes. ast.c Converts Python's parse tree into the abstract syntax tree. @@ -504,16 +504,6 @@ opcode.py One of the files that must be modified if Include/opcode.h is. - compiler/ - - pyassem.py - One of the files that must be modified if Include/opcode.h is - changed. - - pycodegen.py - One of the files that must be modified if Include/opcode.h is - changed. - Known Compiler-related Experiments ----------------------------------