Pascal to Forth

L. Morgenstern
{"title":"Pascal to Forth","authors":"L. Morgenstern","doi":"10.1145/259965.259991","DOIUrl":null,"url":null,"abstract":"In translating Pascal to Forth, certain obvious dissimilarities turn out, paraabxically, to be mere inconveniences, yielding to mechanical translation rules. Differences in viewpoint can be more far-reaching, and a programmer who is unaware of them will write clumsy Forth. Some differences between Forth and Pascal are obvious, but yield to mechanical translation rules. Others, more profound, stem from differences in viewpoint, and may be untranslatable. TRANSLATABLE DIFFERENCES The following are examples of differences between Pascal and Forth for which there are straightforward rules for conversion. Array limits: Forth conventionally starts numbering at O, whereas Pascal usually uses 1. Translation is straightforward, although it may not always immediately apparent whether a” 1” is the index of the f~st element of an array and can be changed to O; or whether it is the quantity “l” that must not be altered. Use of the stack: In Pascal, every quantity has a name and reserved memoW, thus, a := b+c needs three names. In Forth, one can employ the data stack, saving memory ind improving speed. Beginners to Forth do not use this approach enough, and overuse named variables; but experienced programmers may go the other way. Superfluous ROT, SWAP, R> and >R commands are a signal that this has happened, Permission to copy without fee all or part of thie material is granted, provided that the copies are not made or distributed for direet commercial advantage, the ACM copyright notice and the title of the publication and ita date appear, and notice k given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to repubtish, requires a fee andlor Specflc permission. 01991 ACM 0.89791-462.7/90/0200.0035 $1.50 DO ... LOOP limits: Forth’s rule for DO loop limits may look capricious, but can be justified in two ways: 1) It facilitates factoring, that is, breaking a definition into fragments, and 2) it follows the Forth convention of starting things with zero. In this familiar example, : SPACES ( n --) O DO SPACE LOOP ; factoring has detached the starting value and the loop limit from each other, a freedom not available in Pascal, Clean syntax is the result, but the effect is like splitting an infinitive: frowned upon by purists, but useful, nevertheless. Pascal-style loops can be converted to Forth-style by a simple transformation. : BASIC-STYLE ( nl n2 -nl’ n2’) 2DUP < IF SWAP THEN 1+ SWAP ; The usage is: 35 BASIC-STYLE DO .. . . .. .. . . .. .. . . LOOP MORE PROFOUND DIFFERENCES There are deep differences in viewpoint between Pascal and Forth. A programmer who is unaware of these may write clumsy Forth, and will fail to take advantage of Forth’s power. 1) Lack of levels: Traditional languages have three levels: micro-processor, language, and application. These distinctions disappear in Forth. A new word becomes part of Forth, the equal of all other words, and the user may ignore its supposcxi levd","PeriodicalId":391657,"journal":{"name":"FORTH '90 and '91","volume":"1 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"1991-03-07","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"FORTH '90 and '91","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/259965.259991","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0

Abstract

In translating Pascal to Forth, certain obvious dissimilarities turn out, paraabxically, to be mere inconveniences, yielding to mechanical translation rules. Differences in viewpoint can be more far-reaching, and a programmer who is unaware of them will write clumsy Forth. Some differences between Forth and Pascal are obvious, but yield to mechanical translation rules. Others, more profound, stem from differences in viewpoint, and may be untranslatable. TRANSLATABLE DIFFERENCES The following are examples of differences between Pascal and Forth for which there are straightforward rules for conversion. Array limits: Forth conventionally starts numbering at O, whereas Pascal usually uses 1. Translation is straightforward, although it may not always immediately apparent whether a” 1” is the index of the f~st element of an array and can be changed to O; or whether it is the quantity “l” that must not be altered. Use of the stack: In Pascal, every quantity has a name and reserved memoW, thus, a := b+c needs three names. In Forth, one can employ the data stack, saving memory ind improving speed. Beginners to Forth do not use this approach enough, and overuse named variables; but experienced programmers may go the other way. Superfluous ROT, SWAP, R> and >R commands are a signal that this has happened, Permission to copy without fee all or part of thie material is granted, provided that the copies are not made or distributed for direet commercial advantage, the ACM copyright notice and the title of the publication and ita date appear, and notice k given that copying is by permission of the Association for Computing Machinery. To copy otherwise, or to repubtish, requires a fee andlor Specflc permission. 01991 ACM 0.89791-462.7/90/0200.0035 $1.50 DO ... LOOP limits: Forth’s rule for DO loop limits may look capricious, but can be justified in two ways: 1) It facilitates factoring, that is, breaking a definition into fragments, and 2) it follows the Forth convention of starting things with zero. In this familiar example, : SPACES ( n --) O DO SPACE LOOP ; factoring has detached the starting value and the loop limit from each other, a freedom not available in Pascal, Clean syntax is the result, but the effect is like splitting an infinitive: frowned upon by purists, but useful, nevertheless. Pascal-style loops can be converted to Forth-style by a simple transformation. : BASIC-STYLE ( nl n2 -nl’ n2’) 2DUP < IF SWAP THEN 1+ SWAP ; The usage is: 35 BASIC-STYLE DO .. . . .. .. . . .. .. . . LOOP MORE PROFOUND DIFFERENCES There are deep differences in viewpoint between Pascal and Forth. A programmer who is unaware of these may write clumsy Forth, and will fail to take advantage of Forth’s power. 1) Lack of levels: Traditional languages have three levels: micro-processor, language, and application. These distinctions disappear in Forth. A new word becomes part of Forth, the equal of all other words, and the user may ignore its supposcxi levd
帕斯卡尔致福斯
在把帕斯卡尔翻译成福斯的过程中,某些明显的不同之处反而变成了不方便,服从于机械的翻译规则。视点的差异可能影响更深远,不了解它们的程序员将编写出笨拙的Forth。福斯和帕斯卡之间的一些差异是显而易见的,但都服从于机械的翻译规则。其他的,更深刻的,源于观点的不同,可能是不可翻译的。可翻译的差异以下是Pascal和Forth之间的差异的例子,它们有简单的转换规则。数组限制:Forth通常从0开始编号,而Pascal通常使用1。转换是直接的,尽管“1”是否为数组第f~st元素的索引可能并不总是立即明显,并且可以更改为O;还是数量" l "不能被改变。栈的使用:在Pascal中,每个量都有一个名称和保留的内存,因此,a:= b+c需要三个名称。第四,可以使用数据堆栈,节省内存并提高速度。Forth的初学者没有充分使用这种方法,并且过度使用命名变量;但是有经验的程序员可能会走另一条路。多余的ROT, SWAP, R>和>R命令是已经发生这种情况的信号,授予免费复制全部或部分材料的许可,前提是复制不是为了直接商业利益而制作或分发,ACM版权声明,出版物标题和出版日期出现,并且通知k给出了复制是由计算机械协会许可的。以其他方式复制或复制,需要付费和特别许可。01991 acm 0.89791-462.7/90/0200.0035 $1.50 do…循环限制:Forth关于DO循环限制的规则可能看起来很反复无常,但可以从两个方面加以证明:1)它促进了分解,即将定义分解为片段;2)它遵循了Forth从零开始的惯例。在这个熟悉的例子中,:SPACES (n——)O DO SPACE LOOP;因式分解使起始值和循环限制相互分离,这是Pascal中所没有的自由,结果是语法整洁,但效果就像拆分不定式:纯粹主义者不赞成,但仍然有用。pascal样式的循环可以通过简单的转换转换为forth样式。:基本style (nl ' n2 ' -nl ' n2 ') 2DUP < IF SWAP THEN 1+ SWAP;用法是:35基本风貌 .. . . .. .. . . .. .. . .更深刻的差异帕斯卡和福斯在观点上有深刻的差异。没有意识到这一点的程序员可能会写出笨拙的Forth,并且无法利用Forth的强大功能。1)层次不足:传统语言有微处理器、语言和应用三个层次。这些区别在Forth中消失了。一个新单词成为Forth的一部分,与所有其他单词相等,用户可以忽略它的假定状态
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信