Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Thinking about making a programming language in scratch- I need help with something
- me980872
-
Scratcher
75 posts
Thinking about making a programming language in scratch- I need help with something
I am currently working on- well, actually, I'm thinking about working on- a text-based programming language in Scratch. It is my one goal to complete a working programming language before I “retire” from Scratch. I probably won't retire from Scratch though.
So, anyway, I have a question. (This question floats at the top of my head and shows itself randomly throughout the day. In math class, social studies, at school, at home, when I wake up, when I get home from school, 2 minutes after I get home from school, when I'm watching TV when I get home from school, when I am doing almost anything.)
Imagine in this hypothetical programming language, when defining a variable, the variable is set with the code,
The quotation marks signify the start and the end of the variable's data. So, in this case, the variable will be set to
Now, imagine a user is writing in this programming language. They write the code:
In the users' mind, the variable is going to be set to:
Because remember what I said about the quotation marks at the start and the end of the variable? The user added quotation marks it. This means the controlling system reads the first letter:
So, one of my thoughts was, “Well, why don't we make the signals for the start and end of the variable something that no one would ever put in their variable? Something like a random Unicode character. Because what are the odds of a user writing U+024D?” But still, there is a chance that a user would put a Latin Small Letter R with stroke in their variable.
So what can I do here? How could I fix this?
I'm bad at explaining things, so if this doesn't make sense, I apologize. Just ask if you don't understand something.
So, anyway, I have a question. (This question floats at the top of my head and shows itself randomly throughout the day. In math class, social studies, at school, at home, when I wake up, when I get home from school, 2 minutes after I get home from school, when I'm watching TV when I get home from school, when I am doing almost anything.)
Imagine in this hypothetical programming language, when defining a variable, the variable is set with the code,
var=“*variable goes here*”
The quotation marks signify the start and the end of the variable's data. So, in this case, the variable will be set to
*variable goes here*
Now, imagine a user is writing in this programming language. They write the code:
var=“”Hello there!“”
In the users' mind, the variable is going to be set to:
“Hello there!”But in reality, it will be set to
null
Because remember what I said about the quotation marks at the start and the end of the variable? The user added quotation marks it. This means the controlling system reads the first letter:
"and then it continues to the next letter
". So it never reads the variable the user put in.
So, one of my thoughts was, “Well, why don't we make the signals for the start and end of the variable something that no one would ever put in their variable? Something like a random Unicode character. Because what are the odds of a user writing U+024D?” But still, there is a chance that a user would put a Latin Small Letter R with stroke in their variable.
So what can I do here? How could I fix this?
I'm bad at explaining things, so if this doesn't make sense, I apologize. Just ask if you don't understand something.
- scratch___user12345
-
Scratcher
1000+ posts
Thinking about making a programming language in scratch- I need help with something
There is something called a escape character that is present in many coding languages (javascript, python, and lots more). The escape character is almost always backslash. The way it works is that anything after a backslash will be treated normally and won't be used to do anything special.
For example, you want to make it so that:
var=“ \\ ”
will set the variable to "\“
var=” \“ ”
will set the variable to " " “
var=” hello var=\“hi\” will set the variable to hi“
will set the variable to ”var=“hi” will set the variable to hi"
Hope this helps
For example, you want to make it so that:
var=“ \\ ”
will set the variable to "\“
var=” \“ ”
will set the variable to " " “
var=” hello var=\“hi\” will set the variable to hi“
will set the variable to ”var=“hi” will set the variable to hi"
Hope this helps

Last edited by scratch___user12345 (Nov. 11, 2022 01:22:11)
- me980872
-
Scratcher
75 posts
Thinking about making a programming language in scratch- I need help with something
@scratch___user12345 This helps a lot! Thanks so much 

- Discussion Forums
- » Help with Scripts
-
» Thinking about making a programming language in scratch- I need help with something

