diff options
author | elioat <elioat@tilde.institute> | 2025-01-12 12:56:31 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2025-01-12 12:56:31 -0500 |
commit | df1bbf51de157fdffd189a9df36544d0a1e1375f (patch) | |
tree | eca0a8ed7a311c379d4a1dc1cdc44525cff0be8e /awk/forth/test.forth | |
parent | e5ca28ac779b9c4e9e981694853940f199b0e83d (diff) | |
download | tour-df1bbf51de157fdffd189a9df36544d0a1e1375f.tar.gz |
*
Diffstat (limited to 'awk/forth/test.forth')
-rw-r--r-- | awk/forth/test.forth | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/awk/forth/test.forth b/awk/forth/test.forth new file mode 100644 index 0000000..1beedaf --- /dev/null +++ b/awk/forth/test.forth @@ -0,0 +1,34 @@ +\ Test arithmetic operations +10 5 + . \ Should print 15 +10 5 - . \ Should print 5 +10 5 * . \ Should print 50 +10 5 / . \ Should print 2 + +\ Test stack manipulation +1 2 3 .s \ Should show 3 values: 1 2 3 +dup . \ Should print 3 again +drop . \ Should print 2 +swap .s \ Should show 2 1 +over .s \ Should show 2 1 2 +rot .s \ Should show 1 2 3 + +\ Test comparisons +5 5 = . \ Should print -1 (true) +5 3 < . \ Should print 0 (false) +3 5 > . \ Should print 0 (false) + +\ Test conditionals +10 20 if .s then \ Should print 1 2 (since the condition is true) +10 5 if .s else 1 then \ Should print 1 (since the condition is false) + +\ Test user-defined words +: square dup * ; \ Define a word to square a number +4 square . \ Should print 16 + +: add_three 1 2 + + ; \ Define a word to add three numbers +1 2 add_three . \ Should print 6 + +\ List all words +words \ Should list all available words + +bye \ Exit the interpreter \ No newline at end of file |