如何将整数创建为字符代码常量? [英] How is a integer created as a character code constant?
问题描述
我正在为 integer/1 使用 SWI-Prolog.
I am building some test cases for integer/1 using SWI-Prolog.
ISO/IEC 13211-1 给出了 integer
的 BNF 定义,整数的替代方法之一是 字符代码常量
.
ISO/IEC 13211-1 gives a BNF definition for integer
and one of the alternatives for integer is for a character code constant
.
我能够使用 integer/1
创建和测试所有其他替代方案的示例,但是对于 character code constant
我无法创建有效示例.(见下文)
I am able to create and test examples of all the other alternatives using integer/1
but for character code constant
I cannot create a valid example. (see below)
如何使用 整数/1?
How is an integer as a character code constant
created that will return true using integer/1?
回答
感谢@false.
integer(0'0).
true.
integer(0'9).
true.
integer(0'a).
true.
integer(0'\n).
true.
<小时>
实用性
X is 0'\n.
X = 10.
X is 0b010101.
X = 21.
X is 0xFFF1.
X = 65521.
X is 0o7423.
X = 3859.
感谢 j4n bur53通过@false 的链接
and thanks to j4n bur53 via link from @false
对于 SWI-Prolog,除了 2,8 或 16 之外,还可以使用其他基数.
with SWI-Prolog other radix can be used besides 2,8, or 16.
X is 5'1234012340.
X = 3032220.
X is 32'123456789ABCDEFGHIJKLMNOPQRSTU.
X = 47525417447024678661670292427038339608998846.
<小时>
我尝试了什么
What I tried
integer("0").
false.
integer('0').
false.
integer(`0`).
false.
integer("1").
false.
integer('1').
false.
integer(`1`).
false.
<小时>
ISO
国际标准 ISO/IEC 13211-1 第一版 1995-06-01
信息技术 - 编程语言 - Prolog
第 1 部分:通用核心
INTERNATIONAL STANDARD ISO/IEC 13211-1 First edition 1995-06-01
Information technology - Programming languages - Prolog
Part 1: General Core
国际标准 ISO/IEC 13211-1:1995
技术勘误1
发表于 2007-11-15
INTERNATIONAL STANDARD ISO/IEC 13211-1:1995
TECHNICAL CORRIGENDUM 1
Published 2007-11-15
国际标准 ISO/IEC 13211-1:1995
技术勘误2
发表于 2012-02-15
INTERNATIONAL STANDARD ISO/IEC 13211-1:1995
TECHNICAL CORRIGENDUM 2
Published 2012-02-15
integer
的 BNF
integer token (* 6.4.4 *) =
integer constant (* 6.4.4 *)
| character code constant (* 6.4.4 *)
| binary constant (* 6.4.4 *)
| octal constant (* 6.4.4 *)
| hexadecimal constant (* 6.4.4 *) ;
字符代码常量
character code constant (* 6.4.4 *) =
"0" , single quote char (* 6.5.5 *), single quoted character (* 6.4.2.1 *)
我怀疑 ISO/IEC 13211-1 中的 BNF 是错误的,但检查 CORRIGENDUM 显示没有更正.
I suspect the BNF is wrong in ISO/IEC 13211-1 but checking the CORRIGENDUM shows no corrections.
整数测试用例
% <integer constant> examples
number(1).
% true.
number(0).
% true.
number(01).
% true.
number(12345678901234567890123456789012345678901234567890).
% true.
% <character code constant> examples
% ???
% <binary constant> examples
number(0b0).
% true.
number(0b10101010101010101010101010101010101010101010101010).
% true.
integer(0b2).
% ERROR: Syntax error: Illegal number
% ERROR: integer
% ERROR: ** here **
% ERROR: (0b2) .
% <octal constant> examples
integer(0o7).
% true.
integer(0o1234567012345670123456701234567012345670123456701234567).
% true.
integer(0o8).
% ERROR: Syntax error: Illegal number
% ERROR: integer
% ERROR: ** here **
% ERROR: (0o8) .
% <hexadecimal constant>
integer(0x0).
% true.
integer(0xF).
% true.
integer(0xf).
% true.
integer(0x123456789ABCDEF012345670123456789ABCDEF012345670123456789ABCDEF).
% true.
integer(0xG).
% ERROR: Syntax error: Illegal number
% ERROR: integer
% ERROR: ** here **
% ERROR: (0xG) .
推荐答案
这是在评论中被 false 回答的.
在此处重新发布,以便其他人可以看到存在的答案.
This was answered by false in a comment.
Reposting here so that others can see an answer exist.
integer(0'0).
true.
integer(0'9).
true.
integer(0'a).
true.
integer(0'\n).
true.
这篇关于如何将整数创建为字符代码常量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!