diff options
author | elioat <elioat@tilde.institute> | 2025-01-12 13:39:57 -0500 |
---|---|---|
committer | elioat <elioat@tilde.institute> | 2025-01-12 13:39:57 -0500 |
commit | 6191c494abc1dbdba850c9ae9cd327197a86bdc9 (patch) | |
tree | 6f3a100be5f4fc4f59249c7bba32ccedb45f5389 /awk/forth/f.awk | |
parent | aa39d586b26ba9632bc2090201a319f01083a3bc (diff) | |
download | tour-master.tar.gz |
Diffstat (limited to 'awk/forth/f.awk')
-rwxr-xr-x | awk/forth/f.awk | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/awk/forth/f.awk b/awk/forth/f.awk index 73fea1e..4894b34 100755 --- a/awk/forth/f.awk +++ b/awk/forth/f.awk @@ -67,6 +67,8 @@ function interpret(line) { word = words[i] if (word == "") continue + # print "Processing word: " word # Debugging output (commented out) + if (word == ":") { compiling = 1 i++ @@ -86,6 +88,12 @@ function interpret(line) { continue } + # Execute the word and skip further processing if it's .s + if (word == ".s") { + execute_word(word) + break # Exit the loop after executing .s + } + execute_word(word) } } @@ -110,7 +118,10 @@ function execute_word(word) { else if (word == "*") math_mul() else if (word == "/") math_div() else if (word == ".") stack_print() - else if (word == ".s") stack_show() + else if (word == ".s") { + # print "Executing .s command" # Debugging output + stack_show() + } else if (word == "dup") stack_dup() else if (word == "drop") stack_drop() else if (word == "swap") stack_swap() @@ -121,6 +132,28 @@ function execute_word(word) { else if (word == ">") compare_gt() else if (word == "bye") exit_program() else if (word == "words") list_words() + else if (word == "if") { + # Handle the if statement + if_condition = pop() + if (if_condition == 0) { + # Skip to the next part until we find 'then' or 'else' + skip_if = 1 + } + } + else if (word == "else") { + # Handle the else statement + if (skip_if) { + skip_if = 0 # Reset the skip flag + } else { + # Skip to the next part until we find 'then' + skip_else = 1 + } + } + else if (word == "then") { + # End of the conditional + skip_if = 0 + skip_else = 0 + } } } else { print "Error: Unknown word '" word "'" @@ -197,6 +230,11 @@ function stack_show() { printf "%s ", stack[i] } print "" + # print "Stack state after .s: " # Debugging output + # for (i = 0; i < stack_ptr; i++) { + # print stack[i] + # } + # print "" # Add a newline for better readability } function stack_dup() { |