Add a statement to Cpython source code: My Notes
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.