Jun-02-2022, 06:45 PM
Hello, I am an undergraduate student who's doing undergrad research on language grammars. My specific task is to convert different language grammars to BNF grammar so that those can be used on Bison. Python grammar till 3.8.x was LL(1) grammar that could be converted to BNF without much effort. But the new PEG and EBNF is a bit confusing for me. I'm having hard time converting
Original:
BNF:
`
This was done by keeping in mind that single
However, this becomes far complicated when there are more than one
Is there any algorithm I can follow while converting from PEG to BNF? And if not, what are the approaches that might help me converting? Or is converting the new grammar even possible? If not, then I will go back to 3.8.x grammar.
Hoping to get some good suggestion. Thanks in advanced.
&
!
etc to BNF. For example, the following rule is changed to BNF by doing some workaround-Original:
slices:
| slice !','
| ','.slice+ [',']
BNF:
%token COMMA
`
slices:
slice
| slices_seperated_by_comma
| slices_seperated_by_comma COMMA
;
slices_seperated_by_comma:
slice COMMA slice
| slice COMMA slice COMMA slice
| slices_seperated_by_comma slices_seperated_by_comma
;
This was done by keeping in mind that single
slice
will not have comma at the end. But multiple comma-separated slices might have trailing comma. And more than one comma-separated slice
can be either two slices or three slices or a combination of them.However, this becomes far complicated when there are more than one
!
in a rule. And when it's ~
, I cannot even think of a way to convert it to BNF.Is there any algorithm I can follow while converting from PEG to BNF? And if not, what are the approaches that might help me converting? Or is converting the new grammar even possible? If not, then I will go back to 3.8.x grammar.
Hoping to get some good suggestion. Thanks in advanced.