Add a statement to Cpython source code: My Notes

Joannah Nanjekye
1 min readFeb 20, 2019

--

A quick disclaimer: I am not adding or proposing any new statements to Cpython. I was curiously tinkering to know the flow.

These are my notes, so I wasn’t keen on presentation here.

1. Edit the grammar in **Grammar/Grammar**. make
2. Add an AST node for the statement **Parser/Python.asdl** which is AST generation code. make
3. Write the code that converts the parse-tree node. Edit Python/ast.c
4. Note: Instead of creating a new AST for every node, you can use existing AST nodes.
5. Compile the AST into Python bytecode. Compilation results in a Control Flow Graph. Edit Python/compile.c
6. Update symbol table. Modify Python/symtable.c to add code that handles the new statement.

--

--

Joannah Nanjekye

Christian, I choose results over reasons, proud aviator, show me the code