gforth文档翻译 征询修改意见 3.24 字符和字符串

22 views
Skip to first unread message

胡松涛

unread,
May 26, 2011, 9:11:23 AM5/26/11
to cn...@googlegroups.com
大家好,
我和yoyo在翻译gforth的文档,我把翻译好的部分放出来,希望大家能帮忙找出更多的错误。

-----------------译文---------------------

下一个:对齐教程,上一个:内存教程,上一级:教程
3.24 字符和字符串

在堆栈上,字符占用一个存贮单元,就和数字一样。在内存中他们有自己的大小(在大多数系统中是1个8位字节),因此,它需要用自己的词进行内存访问:
create v4
104 c, 97 c, 108 c, 108 c, 111 c,
v4 4 chars + c@ .
v4 5 chars dump

在堆栈上,字符串的首选表示是addr u-count
,其中addr是第一个字符的地址,同时 u-count是字符串中的字符数。
v4 5 type

你會得到如下的字符串常量
s" hello, world" .s
type

请确保在s" 和字符串之间有一个空格;s"
是一种常规的Forth词而且必须以空格分隔(你可以试试删除空格时会发生什么)。

然而,作为这个s" 的使用解释具有相当的局限性:该字符串只在下一次调用s"
之前存在(有些Forth系统保持多个这类字符串,但通常它们仍有一个有限的生命期)。
s" hello," s" world" .s
type
type

你还可以在一个定义中使用s"
,由此产生的字符串,会永远存在(当然,如果定义消失它也消失):
: foo s" hello," s" world" ;
foo .s
type
type
指定: Emit ( c -- ) 作为字符(而非数字)打印 c 。实做 type ( addr u -- ).

参考: 内存块。


--
Hu Songtao
works as an English Teacher in weekends
Skype: idisblueflash
Beijing, China

田明

unread,
May 26, 2011, 9:20:59 AM5/26/11
to cn...@googlegroups.com
差不多就行了


--
You received this message because you are subscribed to the Google
Groups "Forth中国社区" group.
To post to this group, send email to Cn...@googlegroups.com
To unsubscribe from this group, send email to
CnFig+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/CnFig?hl=zh-CN

胡松涛

unread,
May 26, 2011, 9:37:38 AM5/26/11
to cn...@googlegroups.com
在 Thu, 26 May 2011 21:20:59 +0800,田明 <timi...@gmail.com> 写道:

> 差不多就行了

谢谢兄台体谅。
Reply all
Reply to author
Forward
0 new messages