4Th, the Friendly Forth Compiler

4Th, the Friendly Forth Compiler

4tH, the friendly Forth compiler J.L. Bezemer July 14, 2021 Contents 1 What’s new 19 I Getting Started 24 2 Overview 25 2.1 Introduction . 25 2.2 History . 25 2.3 Applications . 26 2.4 Architecture . 26 2.4.1 The 4tH language . 28 2.4.2 H-code . 28 2.4.3 H-code compiler . 29 2.4.4 Error handling . 30 2.4.5 Interfacing with C . 30 3 Installation Guide 32 3.1 About this package . 32 3.1.1 Example code . 32 3.1.2 Main program . 32 3.1.3 Unix package . 33 3.1.4 Linux package . 34 3.1.5 Android package . 38 3.1.6 MS-DOS package . 40 3.1.7 MS-Windows package . 41 3.2 Setting up your working directory . 43 3.3 Now what? . 43 3.4 Pedigree . 43 3.5 Contributors . 44 1 CONTENTS 2 3.6 Questions . 44 3.6.1 4tH website . 44 3.6.2 4tH Google group . 45 3.6.3 Newsgroup . 45 4 A guided tour 46 4.1 4tH interactive . 46 4.2 Starting up 4tH . 46 4.3 Running a program . 47 4.4 Starting an editing session . 47 4.5 Writing your first 4tH program . 48 4.6 A more complex program . 52 4.7 Advanced features . 56 4.8 Suspending a program . 63 4.9 Calculator mode . 65 4.10 Epilogue . 65 5 Frequently asked questions 66 II Primer 69 6 Introduction 70 7 4tH fundamentals 71 7.1 Making calculations without parentheses . 71 7.2 Manipulating the stack . 72 7.3 Deep stack manipulators . 73 7.4 Passing arguments to functions . 73 7.5 Making your own words . 74 7.6 Adding comment . 75 7.7 Text-format of 4tH source . 75 7.8 Displaying string literals . 75 7.9 Creating variables . 76 7.10 Using variables . 76 7.11 Built-in variables . 76 7.12 What is a cell? . 77 7.13 What is a literal expression? . 77 7.14 Declaring arrays of numbers . 77 CONTENTS 3 7.15 Using arrays of numbers . 78 7.16 Copying arrays of numbers . 78 7.17 Declaring and using constants . 78 7.18 Built-in constants . 79 7.19 Using booleans . 80 7.20 IF-ELSE constructs . 80 7.21 FOR-NEXT constructs . 80 7.22 WHILE-DO constructs . 81 7.23 REPEAT-UNTIL constructs . 82 7.24 Infinite loops . 82 7.25 Including source files . 82 7.26 Getting a number from the keyboard . 83 8 4tH arrays 84 8.1 Aligning numbers . 84 8.2 Creating arrays of constants . 84 8.3 Using arrays of constants . 84 8.4 Using values . 85 8.5 Creating string variables . 86 8.6 What is an address? . 86 8.7 String literals . 87 8.8 String constants . 87 8.9 Initializing string variables . 88 8.10 Initializing a NULL string variable . 88 8.11 Getting the length of a string variable . 88 8.12 Printing a string variable . 89 8.13 Copying a string variable . 89 8.14 The string terminator . 89 8.15 Slicing strings . 90 8.16 Appending strings . 91 8.17 Comparing strings . 91 8.18 Finding a substring . 92 8.19 Replacing substrings . 93 8.20 Deleting substrings . 93 8.21 Removing trailing spaces . 94 8.22 Removing leading spaces . 94 8.23 Upper and lower case . 95 CONTENTS 4 8.24 String literals and string variables . 95 8.25 Printing individual characters . 96 8.26 Distinguishing characters . 96 8.27 Getting ASCII values . 97 8.28 Printing spaces . 97 8.29 Fetching individual characters . 98 8.30 Storing individual characters . 98 8.31 Getting a string from the keyboard . 100 9 Character Segment 101 9.1 The Character Segment . 101 9.2 What is the TIB? . 101 9.3 What is the PAD? . 102 9.4 How do I use TIB and PAD? . 102 9.5 Simple parsing . 102 9.6 Converting a string to a number . 104 9.7 Controlling the radix . 104 9.8 Pictured numeric output . 107 9.9 printf() like formatting . 110 9.10 Converting a number to a string . 111 9.11 Aborting a program . 112 9.12 Opening a file . 113 9.13 Reading and writing from/to a file . 114 9.14 Closing a file . ..

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    648 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us