prolog中如何写方括号?
这可能听起来很奇怪,但它是在解析器中使用的,我希望能够解析以下形式的内容
foo[栏]
因此这将在列表中表示为:
[富,[,酒吧,[] 或许这样一句话用DCG会写成:
x --> id [[] arg []]
问题是方括号是保留字符,那么我如何在序言中表示它?
This may sound strange, but it is used in a parser, I want to be able to parse something of the form
foo[bar]
So this would be represented in a list as:
[foo, [, bar, []
Maybe such a word would be written in DCG as:
x --> id [[] arg []]
The problem is that the square bracket is a reserved character, so how can I represent this in prolog?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能将方括号与其他所有内容一起视为原子(即
'['
和']'
)吗?举个例子:
执行:
Can you not treat your square brackets as atoms (i.e.,
'['
and']'
), along with everything else?How about, for example:
Execution:
"["
(在引号中)可以解决问题吗?Does
"["
(in quotes) do the trick?