如何将BNF转换为EBNF [英] How to convert BNF to EBNF

查看:415
本文介绍了如何将BNF转换为EBNF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将BNF转换为EBNF?

How can I convert this BNF to EBNF?

<vardec> ::= var <vardeclist>;
<vardeclist> ::= <varandtype> {;<varandtype>}
<varandtype> ::= <ident> {,<ident>} : <typespec>
<ident> ::= <letter> {<idchar>}
<idchar> ::= <letter> | <digit> | _

推荐答案

EBNF或扩展的Backus-Naur格式 ISO 14977:1996 ,并且可从ISO免费获得PDF格式的 * .计算机语言标准并未广泛使用它.还有一个对此进行了描述,并且那张纸包含这张表,总结了EBNF表示法.

EBNF or Extended Backus-Naur Form is ISO 14977:1996, and is available in PDF from ISO for free*. It is not widely used by the computer language standards. There's also a paper that describes it, and that paper contains this table summarizing EBNF notation.

         Table 1: Extended BNF
Extended BNF    Operator  Meaning
-------------------------------------------------------------
unquoted words            Non-terminal symbol
" ... "                   Terminal symbol
' ... '                   Terminal symbol
( ... )                   Brackets
[ ... ]                   Optional symbols
{ ... }                   Symbols repeated zero or more times
{ ... }-                  Symbols repeated one or more times†
=               in        Defining symbol
;               post      Rule terminator
|               in        Alternative
,               in        Concatenation
-               in        Except
*               in        Occurrences of
(* ... *)                 Comment
? ... ?                   Special sequence

*运算符与前面的(无符号)整数一起使用;它似乎不允许重复的数字可变-例如在初始字符后的1-15个字符,以使标识符最长为16个字符. lis

The * operator is used with a preceding (unsigned) integer number; it does not seem to allow for variable numbers of repetitions — such as 1-15 characters after an initial character to make identifiers up to 16 characters long. This lis

在标准中,圆括号(被称为起始组符号,而圆括号)被称为结束组符号;左方括号[开始选项符号,右方括号是结束选项符号;大括号{开始重复符号,而大括号}结束重复符号.单引号'被称为第一引号符号,双引号"被称为第二引号符号.

In the standard, open parenthesis ( is called start group symbol and close parenthesis ) is called end group symbol; open square bracket [ is start option symbol and close square bracket is end option symbol; open brace { is start repeat symbol and close brace } is end repeat symbol. Single quotes ' are called first quote symbol and double quotes " are second quote symbol.

*是的,免费-即使您愿意,也可以支付74瑞士法郎.查看包含收费项目的框下方的注释.

该问题旨在将该"BNF"转换为EBNF:

The question seeks to convert this 'BNF' into EBNF:

<vardec> ::= var <vardeclist>;
<vardeclist> ::= <varandtype> {;<varandtype>}
<varandtype> ::= <ident> {,<ident>} : <typespec>
<ident> ::= <letter> {<idchar>}
<idchar> ::= <letter> | <digit> | _

BNF尚未正式定义,因此我们必须对其含义做出一些(简单的)猜测.翻译是常规的(如果正式定义了BNF,则可能是机械翻译):

The BNF is not formally defined, so we have to make some (easy) guesses as to what it means. The translation is routine (it could be mechanical if the BNF is formally defined):

vardec     = 'var', vardeclist, ';';
vardeclist = varandtype, { ';', varandtype };
varandtype = ident, { ',', ident }, ':', typespec;
ident      = letter, { idchar };
idchar     = letter | digit | '_';

必须在非端子周围除去尖括号;定义符号::=替换为=;诸如;_之类的端子用引号引起来;串联用,显式标记;并且每个规则都以;结尾.原始文件中的分组和替代操作恰好与标准符号一致.请注意,用逗号进行显式连接意味着多词非终结符是明确的.

The angle brackets have to be removed around non-terminals; the definition symbol ::= is replaced by =; the terminals such as ; and _ are enclosed in quotes; concatenation is explicitly marked with ,; and each rule is ended with ;. The grouping and alternative operations in the original happen to coincide with the standard notation. Note that explicit concatenation with the comma means that multi-word non-terminals are unambiguous.

对标准本身的随意研究表明,{...}-符号不是标准的一部分,只是本文的一部分.但是,如 jmmut 中的

Casual study of the standard itself suggests that the {...}- notation is not part of the standard, just of the paper. However, as jmmut notes in a comment, the standard does define the meaning of {…}-:

§5.8语法术语

§5.8 Syntactic term

...

当句法术语是句法因素后跟 除外符号后跟语法例外 表示同时满足以下两个条件的任何符号序列 条件:

When a syntactic-term is a syntactic-factor followed by an except-symbol followed by a syntactic-exception it represents any sequence of symbols that satisfies both of the conditions:

a)它是由句法因子表示的符号序列,

a) it is a sequence of symbols represented by the syntactic-factor,

b)它不是由 句法例外.

b) it is not a sequence of symbols represented by the syntactic-exception.

...

注意-{ "A" } -表示一个或多个A的序列,因为它是一个带有空句法例外的句法项.

NOTE - { "A" } - represents a sequence of one or more A's because it is a syntactic-term with an empty syntactic-exception.

这篇关于如何将BNF转换为EBNF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆