I know there are some vaguely similar questions already relating to BNF (Backus-Naur Form) grammars in Python, but none of them help me much in terms of my application.
I have multiple BNFs that I need to write code for. The code should be able to both generate and recognize legal strings using the BNF grammar.
The first BNF I'm working with is for all real numbers in Python. It is as follows:
<real number> ::= <sign><natural number> |
<sign><natural number>'.'<digit sequence> |
<sign>'.'<digit><digit sequence> |
<sign><real number>'e'<natural number>
<sign> ::= ‘’ | ‘+’ | ‘-‘
<natural number> ::= ‘0’ | <nonzero digit><digit sequence>
<nonzero digit> ::= 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
<digit sequence> ::= ‘’ | <digit><digit sequence>
<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
Any BNF parsers I've found for Python seem extraordinarily complex, or use outside libraries. Is there any simpler way to check against and generate using BNF grammar in Python?