问题标签 [bnf]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
428 浏览

parsing - HL7 (HL7.org) 消息格式是否可表示为具有 LALR(1) 兼容性的 BNF?

将此作为新消息重新发布(最初我要求提供 HL7 的 BNF 语法)。虽然可以将所有 HL7 表示为 BNF,但我需要我的 BNF 是 LALR(1) 投诉(完全确定性)。Devon Cooks Gold Parser 是工具集。

只是想在我自己开始创建 BNF 之前我会问...

0 投票
2 回答
1026 浏览

grammar - spotting an Ambiguous BNF

I have an assignment to correct an ambiguous BNF, but I am completely lost. I know this not a true programming question, and I will gladly delete it if it is not an appropriate question for these boards. Are there any good sites where I could learn more about BNF's? The one I am dealing with seems rather simple, but I can't find any examples or good explanations regarding BNF's. I have had some experience spotting ambiguous parse trees and other sorts of grammars, but I am completely lost on this one.

Since it is a school assignment, I am not sure I should post the BNF in question, but if anyone knows of a good site that I could look over to perhaps gain a better understanding of how to attack my question. I really just don't know where to start.

0 投票
1 回答
33 浏览

parsing - 绘制以外的软件来自动创建分析树

我有一个 BNF 语法,还有很多我想解析的关于语法的表达式。是否存在一些我可以使用 ( ) 进入树来表示树然后软件绘制它们的软件?

0 投票
2 回答
221 浏览

java - Writing an interpreter, need help representing this data

I am writing a small interpreter to show an example of Backus-Naur form and i would like to ask for help representing some data.

As you can see everything is encapsulated in a statement. An then there assignments and expression. An expression encapsulates a term, which encapsulate a number and a variable. An assignment encapsulates a variable and a expression. My question is what data structure do i use to represent all of this? I am thinking it should be a set, but then that raises the question should i have nested sets?

0 投票
2 回答
1184 浏览

bnf - 括号什么时候在 EBNF 中使用?

如果你有这样的语法:

然后句子 A = B + C * A,你得到这个最左边的推导:

但是 A = B + ( C * A ) 呢?

0 投票
1 回答
2800 浏览

parsing - 改进数学表达式的 BNF

学习编程时一个很好的练习是写一个计算器。为此,我在BNF中创建了某种DSL ,并希望寻求您的帮助来改进它。使用这种迷你语言,您应该能够将值和表达式命名为名称(也就是创建变量和函数)。addmultiplyassign

先看看BNF:

如您所见,此 BNF 不处理旁边的空白NewLine。在解析开始之前,我计划NewLine从要解析的字符串中删除所有空格(当然是除了)。无论如何,这对解析器来说不是必需的。

使用现在定义的这种语言时,有 4 件事可能会导致问题,我希望您能帮助我找出合适的解决方案:

  1. 在生成此语法时,我尝试遵循自上而下的方法,但、<Expression>和之间有一个圆圈。<Summand><Factor><Call>
  2. 语法以完全相同的方式处理变量和函数。大多数编程语言都会有所作为。这里有必要区分吗?
  3. 在尝试实现 BNF 时,可能有一些我不知道的关于编程、BNF 等的事情,这会在以后杀死我。但在我开始之前,你可能会发现这一点。
  4. 可能有一些我自己找不到的简单而愚蠢的错误。在那种情况下很抱歉。我希望不再有这些错误。

使用手和脑,我可以成功解析以下测试用例:

请帮助改进 BNF,使其可用于成功编写计算器。

编辑: 这个 BNF 真的没有完成。它不会正确处理“2+-3”(应该失败,但不会)和“2+(-3)”(应该不会失败,但会)的情况。

0 投票
3 回答
997 浏览

sql - 解释 SQL 的 BNF

我正在查看 SQL 的语法,特别是字符串文字

忽略[ <introducer> <character set specification> ]部分,这是否意味着一个或多个<quote> [ <character representation> ... ] <quote>s 由 a 分隔<separator>

如果是这样,这是否意味着'hello' 'world'应该将其解析为 one <character string literal>

对于查询SELECT 'hello' 'world',Microsoft SQL Server 2005 返回:

MySQL 5.0 返回:

我知道每种 SQL 风格都是不同的,而且它们并不都遵循标准。我只是想确定我是否正确解释了 BNF。谢谢。

0 投票
2 回答
1092 浏览

parsing - 编写 BNF 时 { 和 } 之间有什么?

我在使用 BNF 时遇到了一些问题。我不知道什么似乎是标准的做事方式(如果有的话),以及是否有像 char 或 int 这样的类型或任何已经内置的类型。

但是,我的主要问题是不了解大括号中的 BNF 部分是如何工作的。
给定类似的东西:

(这是从某个地方随便偷来的,用于 yacc / C)

花括号中的内容实际上是在说什么?我也为快乐的解析器生成器看过类似的东西,并且同样感到困惑。

0 投票
1 回答
2136 浏览

programming-languages - BNF 语法和运算符关联性

(首先这不是硬件,我有所有的答案)

我有一个简单的 BNF 语法

and运算符是左关联(左手递归) or运算符是右关联(这次是右手递归)

给定表达式c and b or not a and ( not b or c ),为什么最正确的“和”在解析树中更高?
方式,我看到c **and** b or not a and ( not b or c )最左边的应该在解析树中更高。

我们的教授给出了这样的答案:

这是 lispy 符号中的解析树。

0 投票
3 回答
5654 浏览

json - 关于 EBNF 表示法和 JSON 的问题

最近我一直在研究解析器和语法以及它们是如何工作的。我正在阅读http://www.ietf.org/rfc/rfc4627.txt使用 EBNF 的 JSON 的形式语法。我对我对 BNF 和 EBNF 的理解非常有信心,但显然我仍然没有完全理解它。RFC 定义了一个 JSON 对象,如下所示:

我知道这里的意图是表示任何 JSON 对象都可以(可选地)有一个成员,然后是 0 个或多个(值分隔符,成员)对。我不明白为什么星号出现. (value-separator member)星号不是应该模仿正则表达式,以便它出现要重复 0 次或更多次的项目之后吗?JSON对象语法不应该这样写吗: