EBNF语法,用于以空格分隔的单词列表 [英] EBNF Grammar for list of words separated by a space

查看:88
本文介绍了EBNF语法,用于以空格分隔的单词列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图了解如何使用EBNF定义形式语法,尤其是用空格分隔的单词序列,例如

I am trying to understand how to use EBNF to define a formal grammar, in particular a sequence of words separated by a space, something like

<non-terminal> [<word>[ <word>[ <word>[ ...]]] <non-terminal>

  1. 定义单词终端的正确方法是什么?
  2. 表示所需空白的正确方法是什么?
  3. 如何显示可选的重复列表?
  4. 在任何地方都有关于EBNF的示例演示教程吗?

非常感谢!

推荐答案

您必须确定词法分析器是否要为空格返回标记(终端).您还必须确定它(词法分析器)将如何定义单词,或者您的语法是否要这样做(在这种情况下,词法分析器将作为终端返回什么?).

You have to decide whether your lexical analyzer is going to return a token (terminal) for the spaces. You also have to decide how it (the lexical analyzer) is going to define words, or whether your grammar is going to do that (in which case, what is the lexical analyzer going to return as terminals?).

对于其余部分,主要是了解EBNF表示法(ISO 14977:1996的精妙之处)的问题,可以从 ISO ),但这实际上是一个被忽略的标准.(我处理的语言-C,C ++,SQL-在定义文档中使用BNF表示法,但在任何文档中都不是EBNF.)

For the rest, it is mostly a question of understanding the niceties of EBNF notation, which is an ISO standard (ISO 14977:1996 — and it is available as a free download from Freely Available Standards, which you can also get to from ISO), but it is a standard that is largely ignored in practice. (The languages I deal with — C, C++, SQL — use a BNF notation in the defining documents, but it is not EBNF in any of them.)

  1. 无论您想对单词进行正确的定义.您需要考虑如何对待名称 P.例如,奥尼尔(J. O'Neill).词法分析器将为此返回什么令牌?
  2. 这与上一期密切相关;词法分析器将返回哪些终端.
  3. 可选的重复列表包含在 {} 大括号中,或者您可以使用Kleene Star表示法.
  4. 有一篇论文扩展的BNF-通用基本标准由RS Scowen解释了EBNF.在 EBNF 上也有Wikipedia条目.
  1. Whatever you want to make the correct definition of a word. You need to think about how you'd want to treat the name P. J. O'Neill, for example. What tokens will the lexical analyzer return for that?
  2. This is closely related to the previous issue; what are the terminals that lexical analyzer is going to return.
  3. Optional repetitive lists are enclosed in { and } braces, or you can use the Kleene Star notation.
  4. There is a paper Extended BNF — A generic base standard by R. S. Scowen that explains EBNF. There's also the Wikipedia entry on EBNF.

我认为可以使用以下命令定义一个非空的,用空格分隔的单词列表:

I think that a non-empty, space-separated word list might be defined using:

non_empty_word_list = word { space word }

其中所有名称都是非终结符.您需要根据系统的相关终端进行定义.

where all the names there are non-terminals. You'd need to define those in terms of the relevant terminals of your system.

这篇关于EBNF语法,用于以空格分隔的单词列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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