[Python] Text generator from BNF in Python

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 2025.

  1. Stack

    Stack Membro Participativo

    I need to generate sentences according to BNF. Assuming there is BNF like

    sentence := [prefix] root
    prefix := "prefix1" | "prefix2"
    root := "root0"


    Output should be

    root0
    prefix1 root0
    prefix2 root0


    The best solution is to generic code reading BNF and generating text, but some workaround like providing BNF in form of Python code is also acceptable.

    Thanks.

    Continue reading...

Compartilhe esta Página