{"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