User Tools

Site Tools


tutorials:forth

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorials:forth [2022/01/06 11:39]
papa
tutorials:forth [2022/06/07 02:10] (current)
rcs correct lack of space after dot commands in examples
Line 1: Line 1:
-**FORTH-10** is a Forth language interpreter included in the Panda TOPS-20 distributionThe anonymous programmer describes the implementation as "NOT totally standard"The interpreter can be started with the following command on TWENEX:+[[http://forth.org/whatis.html|Forth]] is a stack-based, RPN-format programming language created by [[https://colorforth.github.io/|Charles H. Moore]] and first released in 1970
  
-  @FORTH+There are two Forth implementation available.
  
-MIDAS assembly language source is available in file ''TOPS20:<UTILITIES>FORTH.MID''.+**FORTH-10** is a Forth language interpreter included in the Panda TOPS-20 distribution. The anonymous programmer describes the implementation as "NOT totally standard"MIDAS assembly language source is available in file ''TOPS20:<UTILITIES>FORTH.MID''.
  
-====== Primitive Dictionary ======+**FORTH** is another interpreter originally written on the MIT AI lab DEC-20 called OZ, by John Wilson.
  
-The following Forth words are hard-coded in the FORTH-10 dictionary.+====== FORTH-10 Survival Guide ======
  
-|[[#store|!]]|[[#minus|-]]|[[#ge|>=]]|[[#BINARY|BINARY]]|[[#DROP|DROP]]|[[#F-dot|F.]]|[[#KEY|KEY]]|[[#NUMBER|[NUMBER]]]|[[#SPACE|SPACE]]| +Start the interpreter on TWENEX with the command ''FORTH-10''If you have not created an [[#start-up_file|auto-load file]], FORTH-10 will respond with the default greeting and prompt.
-|[[#digit|#]]|[[#storem|-!]]|[[#fetch|@]]|[[#BUILDS|<BUILDS]]|[[#DUP|DUP]]|[[#F-slash|F/]]|[[#LEAVE|LEAVE]]|[[#OCTAL|OCTAL]]|[[#SPACES|SPACES]]| +
-|[[#eoutf|#>]]|[[#dot|.]]|[[#ticome|]]]|[[#Cstore|C!]]|[[#nDUP|-DUP]]|[[#FILL|FILL]]|[[#LEVEL|LEVEL]]|[[#OR|OR]]|[[#shalfs|SW,,AP]]| +
-|[[#'|']]|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S]]|[[#DECIMAL|DECIMAL]]|[[#[EXPECT]|[EXPECT]]]|[[#IF|IF]]|[[#MOD|MOD]]|[[#RUNT|RUNT]]|[[#VLIST|VLIST]]| +
-|[[#,|,]]|[[#=|=]]|[[#ALLOT|ALLOT]]|[[#DEPTH|DEPTH]]|[[#F-star|F*]]|[[#IJ..N|IJ..N]]|[[#slash-MOD|/MOD]]|[[##S|#S]]|[[#WHILE|WHILE]]| +
-|[[#,,->|,,->]]|[[#=_|=_]]|[[#AND|AND]]|[[#DO|DO]]|[[#F-plus|F+]]|[[#J|J]]|[[##N|#N]]|[[#SIGN|SIGN]]|[[#XOR|XOR]]| +
-|[[#<-,,|<-,,]]|[[#>|>]]|[[#BEGIN|BEGIN]]|[[#DOES>|DOES>]]|[[#F-minus|F-]]|[[#JSYS|JSYS]]|[[#NOT|NOT]]|[[#SINE|SINE]]| |+
  
-===== Arithmetic =====+  @FORTH-10 
 +  FORTH-10   Type QUIT to exit. 
 +   Ok 
 +   
 +Exit FORTH-10 with the command ''QUIT''.
  
-== plus == +At the ''Ok'' prompt, enter data and executable words separated by whitespace. The interpreter pushes each data item onto the top of the stack. Executable words are executed by the interpreter, removing required arguments from the top of the stack and replacing them with output results.
-+ ( n1 n2 -- n1+n2 )+
  
-== one-plus == +  7 3 Ok  ( Push 7 then 3 on stack. ) 
-1+ ( -- n+1 ) +  Ok    Remove two items from stack (3 and 7), push the sum on stack, so 10 is only item. )  
 +  . 10 Ok  ( Word . pops top stack item and prints it. Stack is now empty. ) 
 +   
 +Words ''.'', ''+'', ''-'', ''*'', and ''/'' interpret stack items as integer values. For floating-point values, use ''f.'', ''f+'', ''f-'', ''f*'', and ''f/''.  
  
-== minus == +  3.14159 Ok 
-n1 n2 -- n1-n2 )+  f. 3.14159 Ok      f. pops stack and displays as floating-point. ) 
 +   
 +Add new words to the dictionary with the defining words '':'' and '';''.
  
-== one-minus == +'':'' name word1 word2 ... '';''  create word //name// that executes //word1 word2 ...//
-1- ( n -- n-1 )+
  
-== star == +For example,
-* ( n1 n2 -- n1*n2 )+
  
-== negate == +  : TIMES5 5 * ; Ok  ( Define word TIMES5: Push 5 on stack (previous top value pushed lower), pop 5 and ) 
-MINUS n -- -n )+                     previous top value, multiply and push product on stack.  ) 
 +  7 TIMES5 Ok        ( Execute the word. ) 
 +  . 35  Ok            ( Pop and display result. ) 
 +   
 +List words currently defined in the dictionary with ''VLIST''.
  
-== abs == +In general, Forth programs keep intermediate results on the stack instead of using variables like other languages. Words are provided to manipulate values on the stack so that they can be used in multiple procedures in the correct order.
-ABS ( n -- |n| )+
  
-== max == +|DROP|Pop stack without printing (discards top value).| 
-MAX n1 n2 -- n //n// is the greater of //n1// or //n2//+|DUP|Copy top value and push it to stack.| 
 +|SWAP|Exchange the top two stack values.| 
 +|ROT|Rotate top three values on stack: [1 2 3] -> [2 3 1]| 
 +|OVER|Copy second item on stack and push it to top: [1 2] -> [1 2 1]|
  
-== min == +Forth source files can be prepared with any editor. Load and interpret source files in FORTH-10 with the command ''LOAD "//file//"''.
-MIN ( n1 n2 -- n ) //n// is the lesser of //n1// or //n2//+
  
-== slash == +====== Hello, World! ======
-/ ( n1 n2 -- n1/n2 ) integer division+
  
-== mod == +  : HELLO CR ." "HELLO, WORLD!" CR ; Ok 
-MOD ( n1 n2 -- n ) //n// is the modulus of //n1/n2//+  HELLO 
 +  HELLO, WORLD! 
 +   Ok
  
-== slash-mod == +Insert comments in Forth source code with the word ''(''. The comment continues until the next '')''.
-/MOD n1 n2 -- n3 n4 ) //n3// is the modulus of //n1/n2//, //n4// is the integer quotient (//n1// = //n2//*//n4//+//n3//)+
  
-== f-plus == +====== Primitive Dictionary ======
-F+ ( r1 r2 -- r1+r2 ) floating point addition+
  
-== f-minus == +The following Forth words are hard-coded in the FORTH-10 dictionary.
-F( r1 r2 -- r1-r2 ) floating point subtraction+
  
-== f-star == +  DUP  SWAP  ROLL  PICK  DROP  OVER  ROT  -DUP  ?DUP  LEVEL  DEPTH  FLOAT  +  - 
-Fr1 r2 -- r1*r2 ) floating point multiplication+  *  /  ^  F+  F-  F*  F/  FIX  MOD  /MOD  0 0=_  0<  0< 0>  0> EXCHANGE 
 +  JSYS  =  =_  <  <=  >  >=  FLUSH  TRACE  @  !  +!  -!  FILL  '  '#  ]  QUIT 
 +  <#  #  HOLD  #N  SIGN  #S  #>  HOME  CR  CLEAR  SPACE  SPACES  EMIT  TYPE 
 +  [TYPE]  KEY  ?TERMINAL  EXPECT  [EXPECT]  C@  C!  C>  C<  .  .R  F.  ."  :" 
 +  (" [" VLIST  (  ABS  MINUS  + 1+  1 MAX  MIN  SINE  COSINE  ROOT  LN 
 +  <-,,  SW,,AP  ,,->  AND  OR  NOT  XOR  EXECUTE  FORGET  :  ;  <BUILDS  DOES> 
 +  ,  ALLOT  LOAD  [LOAD]  UNLOAD  DECIMAL  OCTAL  BINARY  IF  ELSE  THEN  DO 
 +  LOOP  +LOOP  I  J  IJ..N  RUNT  REPEAT  UNTIL  CMOVE  [CMOVE]  HERE  LEAVE 
 +  ERROR  [NUMBER]  WHILE  BEGIN  END
  
-== f-slash == 
-F/ ( r1 r2 -- r1/r2 ) floating point division 
  
-===== Stack manipulation =====+====== Start-Up File ======
  
-== drop == +At start-up, FORTH-10 searches the user's log-in directory for a file named ''AUTO-LOAD.4TH''. If such a file exists, it is loaded automatically. If the file does not exist, FORTH-10 displays a standard greeting message.
-DROP ( n -- )+
  
-== dup == +====== FORTH ======
-DUP ( n -- n n )+
  
-== over == +Start the John Wilson's interpreter on TWENEX with the command ''FORTH''. It will respond with this greeting and prompt.
-OVER ( n1 n2 -- n1 n2 n1 )+
  
-== pick == +  @FORTH 
-PICK n1 -- n2 //n2// is the //n1//th item from the top of the stack+  FORTH/Oz v1 (JohnW) 
 +  ok 
 +   
 +Exit FORTH with the command ''BYE''.
  
-== swap == 
-SWAP ( n1 n2 -- n2 n1 ) 
  
-====== Start-Up File ======+====== Reference ====== 
 + 
 +//Starting FORTH// is the standard introductory text for the Forth language. 
 + 
 +* Leo Brody, //Starting FORTH//. Forth, Inc. https://www.forth.com/starting-forth/. [Accessed January 8, 2022.]
  
-At start-up, FORTH-10 searches the user's log-in directory for a file named ''AUTO-LOAD.4TH''. If such a file exists, it is loaded automatically. If the file does not exist, FORTH-10 displays a standard greeting message. 
tutorials/forth.1641469181.txt.gz · Last modified: 2022/01/06 11:39 by papa