Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
computers:arduino:breeze [03-Jun-2019 10:32] – Steve Joynt | computers:arduino:breeze [02-Feb-2025 16:14] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 146: | Line 146: | ||
display ( 5 + 7 ) | display ( 5 + 7 ) | ||
</ | </ | ||
+ | |||
+ | This executes the command called " | ||
If we want to add three values together, we will unfortunately need to call the " | If we want to add three values together, we will unfortunately need to call the " | ||
Line 165: | Line 167: | ||
The word " | The word " | ||
- | The command " | + | On line 200 there is a coding error, but not a syntax error. |
- | + | ==== Named Sections of Code ==== | |
- | ==== Named Labels For GoTo ==== | + | |
I think it would be a good compromise to allow the " | I think it would be a good compromise to allow the " | ||
Line 173: | Line 174: | ||
I propose to use the hash character "#" | I propose to use the hash character "#" | ||
- | The first parameter will be the name of the label, and must be unique within the script. More parameters may be supplied, but will be ignored as comments, but beware of using [brackets] or (brackets) within the parameters as they will be executed as usual. It is recommended to enclose any comments in quotes. | + | The first parameter will be the name of the label, and must be unique within the script. |
+ | |||
+ | More parameters may be supplied, but will be ignored as comments, but beware of using [brackets] or (brackets) within the parameters as they will be executed as usual. It is recommended to enclose any comments in quotes. | ||
+ | |||
+ | If the first parameter is "#", | ||
< | < | ||
Line 185: | Line 190: | ||
< | < | ||
- | 100 # CountDown | + | 100 # CountDown |
+ | 105 # # "It counts down from 10 to 1, then signals 'Blast Off'" | ||
110 set count 10 | 110 set count 10 | ||
200 # CountDownLoop | 200 # CountDownLoop | ||
Line 195: | Line 201: | ||
310 display "Blast Off!" | 310 display "Blast Off!" | ||
</ | </ | ||
+ | |||
+ | ==== Calling Subroutines ==== | ||
+ | |||
+ | As one of the primary ideas of this script language is to make the interpreter as compact as possible without compromising too much on readability and usability, it would be good to have a way of re-using sections of script, rather than duplicating code. | ||
+ | |||
+ | Most languages have the concept of a subroutine. Some call it a function or a method or procedure. I have called it a subroutine in this documentation because I plan to implement it like subroutines in the BASIC language. | ||
+ | |||
+ | BASIC has the keywords " | ||
+ | |||
+ | It is not possible to pass parameters to subroutines in BASIC using the " | ||
+ | |||
+ | < | ||
+ | 100 set AskUser.question "Which country do you come from?" | ||
+ | 110 gosub AskUser | ||
+ | 120 set AskUser.question "Why have you come here from "[ get AskUser.answer ]"?" | ||
+ | 130 gosub AskUser | ||
+ | 140 set AskUser.question "Are you a spy?" | ||
+ | 150 gosub AskUser | ||
+ | 160 display "I don't believe you!" | ||
+ | 170 end | ||
+ | 200 # AskUser "Keep asking a question until we get an answer" | ||
+ | 210 display [ get AskUser.question ] | ||
+ | 220 input AskUser.answer | ||
+ | 230 if ( [ get AskUser.answer ] == "" | ||
+ | 240 return | ||
+ | </ | ||
+ | |||
+ | ==== Calling External Subroutines ==== | ||
+ | |||
+ | Many programming languages have a way of calling sections of code that are not part of the current program. This allows greater re-use of code and makes it easier for groups of people to work together on a project. It also makes it easier to test sections of code in isolation, then include them as part of a larger project. | ||
+ | |||
+ | The BASIC language has a command called " | ||
+ | |||
+ | So the variables don't " | ||
+ | |||
+ | Rather than adding a new command like " | ||
+ | |||
+ | Switching between scripts in this way would be slow if the source code needed to be loaded into memory each time, but I will be using an [[AVL Tree]] to store the script (indexed by line number). Switching from one script to another simply requires the old file to be closed and the new one to be opened. There is no need to read large amounts of data into memory, as each line of the program is read only when it is needed. | ||
+ | |||