CHAPTER TEN FULL GRAMMAR SPECIFICATION This is the full Python grammar, derived directly from the grammar used to generate the CPython parser (see Gram- mar/python.gram). The version here omits details related to code generation and error recovery. The notation is a mixture of EBNF and PEG. In particular,$_{&}$followed by a symbol, token or parenthesized group indicates a positive lookahead (i.e., is required to match but not consumed), while$_{!}$indicates a negative lookahead (i.e., is required _not_ to match). We use the$_{|}$ separator to mean PEG’s “ordered choice” (written as$_{/}$in traditional PEG grammars). (continues on next page) 107 # PEG grammar for Python file: [statements] ENDMARKER interactive:statement_newline eval:expressions NEWLINE *ENDMARKER func_type : '(' [ type_expressions] ')' '->' expression NEWLINE *ENDMARKER fstring:star_expressions # type_expressions allow */** but ignore them type_expressions: | ',' .expression+',' '*' expression ',' '**' expression | ',' .expression+',' '*' expression | ',' .expression+',' '**' expression | '*' expression ',' '**' expression | '*' expression | '**' expression | ',' .expression+ statements:statement+ statement:compound_stmt| simple_stmt statement_newline : | compound_stmtNEWLINE | simple_stmt | NEWLINE | ENDMARKER simple_stmt : | small_stmt !';' NEWLINE # Not needed, there for speedup | ';' .small_stmt +[';'] NEWLINE # NOTE: assignment MUST precede expression, else parsing a simple assignment # will throw a SyntaxError. small_stmt : | assignment | star_expressions | return_stmt | import_stmt | raise_stmt | 'pass' | del_stmt | yield_stmt