如何将高级EBNF结构(使用大括号)转换为BNF(与Bison一起使用)
我正在自学Flex/Bison,我正在用VHDL 93做一些实验。我对一些使用花括号的语法“productions”(在标准中称为productions)有问题 我理解标准中给出的示例的含义和转换方法:如何将高级EBNF结构(使用大括号)转换为BNF(与Bison一起使用),bison,bnf,Bison,Bnf,我正在自学Flex/Bison,我正在用VHDL 93做一些实验。我对一些使用花括号的语法“productions”(在标准中称为productions)有问题 我理解标准中给出的示例的含义和转换方法: term ::= factor { multiplying_operator factor } term ::= factor | term multiplying_operator factor 但是关于: choices ::= choice { | choice } 我不知道如何转换这
term ::= factor { multiplying_operator factor }
term ::= factor | term multiplying_operator factor
但是关于:
choices ::= choice { | choice }
我不知道如何转换这个
block_configuration ::=
for block_specification
{ use_clause }
{ configuration_item }
end for ;
我在stackoverflow中阅读了很多问题,并搜索了一些EBNF教程,但我没有看到任何关于这种构造的内容
最后,我了解到这种结构:
configuration_declarative_part ::=
{ configuration_declarative_item }
翻译为:
configuration_declarative_part ::= |
configuration_declarative_part configuration_declarative_item
可以吗
提前感谢您的帮助。一般情况下,每个
{
..}
将创建两个新规则(称为n1
和n2
),并由第二个规则替换:
n1: ...whatever was in the braces...
n2: /* empty */ | n2 n1 ;
因此,对于选项::=choice{| choice}
,将变为:
n1 ::= /*empty*/ | choice
n2 ::= /*empty*/ | n2 n1
choices ::= choice n2
然后重构它以消除歧义,并根据需要简化它。上述内容减少至等效值:
choices ::= choice | choices choice
一般情况下,每个
{
..}
将创建两个新规则(称为n1
和n2
),并由第二个规则替换:
n1: ...whatever was in the braces...
n2: /* empty */ | n2 n1 ;
因此,对于选项::=choice{| choice}
,将变为:
n1 ::= /*empty*/ | choice
n2 ::= /*empty*/ | n2 n1
choices ::= choice n2
然后重构它以消除歧义,并根据需要简化它。上述内容减少至等效值:
choices ::= choice | choices choice
让我看看我是否理解:
choices ::= choice { | choice }
n1 ::= %empty | choice
n2 ::= %empty | n2 n1
choices ::= choice n2
::= choice ( %empty | n2 n1 )
::= choice | choice n2 n1
::= choice | choices n1
::= choice | choices ( %empty | choice )
::= choice | choices | choices choice
但是choices::=choices
是微不足道的,所以:
choices ::= choice | choices choice
现在怎么办?或者更好的做法是:
block_configuration ::= for block_specification n2 n4 end for ;
与:
这似乎是一条好规则 谢谢
更新:我得出的结论是,添加新规则(基于)比替换和拥有更复杂的规则更好(更清晰)。让我看看我是否理解:
choices ::= choice { | choice }
n1 ::= %empty | choice
n2 ::= %empty | n2 n1
choices ::= choice n2
::= choice ( %empty | n2 n1 )
::= choice | choice n2 n1
::= choice | choices n1
::= choice | choices ( %empty | choice )
::= choice | choices | choices choice
但是choices::=choices
是微不足道的,所以:
choices ::= choice | choices choice
现在怎么办?或者更好的做法是:
block_configuration ::= for block_specification n2 n4 end for ;
与:
这似乎是一条好规则 谢谢
更新:我得出的结论是,添加新规则(基于)比替换规则更好(更清晰),并且具有更复杂的规则。此响应对我理解有用此响应对我理解有用