BNF 创建具有相同长度的向量

发布于 2024-12-09 02:36:43 字数 344 浏览 0 评论 0原文

是否可以用 BNF 描述一对相同长度的向量?例如,我想使用这样的语法来捕获有效的点积运算,因为这样的运算需要相同长度的向量。

我可以描述一个向量(我认为这是可以的): [1,2,3]

<vector> ::= "[" <vectorItems> "]"
<vectorItems> ::= <wholeNumber>|<wholeNumber>","<vectorItems>

但是我如何描述以下内容(即向量可以是任意长度但两个向量的长度相同;是这甚至可能吗?我对此有点陌生)?:[1,2,3,4],[5,6,7,8]

Is it possible to describe in BNF a pair of vectors of the same length? For instance, I would like to use such a grammar to capture valid dot product operations as such an operation requires vectors of the same length.

I can describe one vector (I think this is okay): [1,2,3]

<vector> ::= "[" <vectorItems> "]"
<vectorItems> ::= <wholeNumber>|<wholeNumber>","<vectorItems>

But how can I describe the following (that is, the vectors can be of any length but the lengths of the two vectors are the same; Is this even possible? I am kind of new at this)?: [1,2,3,4], [5,6,7,8]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

兲鉂ぱ嘚淚 2024-12-16 02:36:43

像这样的东西吗?

  S := [T]
  T := N,T,N | N],[N
  N := (any valid number)

  Nonterminals: S, T, N
  Terminals: [ ] , # (anything required by your definition of N)

该语言中的字符串按从小到大的顺序排列,其中 N 代表任意数字:

L = { [N],[N], [N,N],[ N,N], [N,N,N],[N,N,N], ...}

= {aBcDe | a=[ 和 c=],[ 和 e=] 和 B=(N,)^k N 和 D=(N,)^k N
且k> 0)

(端子符号以粗体显示)

Something like this?

  S := [T]
  T := N,T,N | N],[N
  N := (any valid number)

  Nonterminals: S, T, N
  Terminals: [ ] , # (anything required by your definition of N)

The strings in this language are, in order from smallest to largest, where N stands for an arbitrary number:

L = { [N],[N], [N,N],[N,N], [N,N,N],[N,N,N], ...}

= {aBcDe | a=[ and c=],[ and e=] and B=(N,)^k N and D=(N,)^k N
and k > 0)

(terminal symbols shown in bold)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文