3 ms·
That only means that the railroad diagram is not a direct translation of the original grammar. Conversely, there are more than enough BNF variants that can do t
by lifthrasiir 3y ago
That only means that the railroad diagram is not a direct translation of the original grammar. Conversely, there are more than enough BNF variants that can do the equivalent inlining. I will personally denote your example as:
if_stmt:
'if' named_expression ':' block
('elif' named_expression ':' block)*
('else' ':' block)?
...which is no more complex than the original diagram, and reads much easily at least for me. In fact, that "original grammar" does support the equivalent syntax because it's a direct input to Python's PEG code generator. I don't know why `if_stmt` was described in that way, but such duplication is often done for readability and hardly surprising.