Discuss Scratch
- Discussion Forums
- » Show and Tell
- » TextScratch - A programming language in Scratch.
- Resince
-
Scratcher
100+ posts
TextScratch - A programming language in Scratch.
Awesome idea, I've always wanted to make a programming language in Scratch that resembled the syntax of Javascript.
What I mean by this is:
What I mean by this is:
var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
- gosoccerboy5
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
Well, I think that it would be harder to implement… Just because it would have to sense if an { is there, and if it isn't, what then?Syntax error. Also, all you have to do is measure how many ‘loops’ you'd be in by counting the number of curly brackets, and subtracting the amount of }'s.
If we don't, what would this be:repeat 20
me = Cat
}
I'm torn between indentation and curly brackets - indentation might be more intuitive for Scratch users (concise syntax), but curly brackets might be easier for the parser(?) and would be easier to type in.
Last edited by gosoccerboy5 (Jan. 9, 2021 23:37:44)
- gosoccerboy5
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
Awesome idea, I've always wanted to make a programming language in Scratch that resembled the syntax of Javascript.That'd be pretty sweet. (Would there be like return functions and stuff, or would it be limited to Scratch abilities?)
What I mean by this is:var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
- Resince
-
Scratcher
100+ posts
TextScratch - A programming language in Scratch.
Awesome idea, I've always wanted to make a programming language in Scratch that resembled the syntax of Javascript.That'd be pretty sweet. (Would there be like return functions and stuff, or would it be limited to Scratch abilities?)
What I mean by this is:var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
I wouldn't want to go off-topic on this discussion. Feel free to message me on my profile.

- Greg8128
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
Well, I think that it would be harder to implement… Just because it would have to sense if an { is there, and if it isn't, what then?if you had syntax like
If we don't, what would this be:repeat 20
me = Cat
}
while i > j +3you would still have to detect the “loop” keyword. Even if you could find a way to not include it, you would still need to find a way to not include it. And honestly detecting the presence or absence of a keyword isn't that hard to begin with. What I did for CRIS is just have a tokenizer split the code into ‘tokens’ (numbers, operators, brackets, etc) at the start and then use a block to cause an error if the next token wasn't a ‘{’ when needed.
loop
# stuff
end
If the ‘{’ is missing, you could throw a compile error as gosoccerboy suggested. Alternatively, you could just take the next statement as the body of the loop, which allows stuff such as:
if (i > 3)
foo();
else
bar();
In fact, you could handle the case with the ‘{’ using this method by implementing the {…} as a ‘compound statement’, or several statements that the compiler treats as one. This approach also has several other cool advantages that I can discuss if you want.
I'm torn between indentation and curly brackets - indentation might be more intuitive for Scratch users (concise syntax), but curly brackets might be easier for the parser(?) and would be easier to type in.indentation-based syntax is problematic. Many people have their tabs set up differently in their text editors; some people have a tab equal 4 spaces, some have it equal 2 spaces, and so forth. So if you try to make your code look pretty, it could end up looking ugly for someone else. If you really want indentation based syntax, a simple implementation would be to insert a ‘{’ for every tab gained relative to the previous line and a ‘}’ for every tab lost relative to the previous line. So something like
repeat 10would be read by the compiler as:
a();
repeat 5
b();
c();
repeat 10 {
a();
repeat 5 {
b();
c();
}
}
Last edited by Greg8128 (Jan. 10, 2021 00:04:18)
- pedrodrocafranco
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
(pixels)(command px:: list)::operators
- pedrodrocafranco
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
would use stack script or cris for a physic pen parttenWell, I think that it would be harder to implement… Just because it would have to sense if an { is there, and if it isn't, what then?if you had syntax like
If we don't, what would this be:repeat 20
me = Cat
}while i > j +3you would still have to detect the “loop” keyword. Even if you could find a way to not include it, you would still need to find a way to not include it.
loop
# stuff
end
If the ‘{’ is missing, you could throw a compile error as gosoccerboy suggested. Alternatively, you could just take the next statement as the body of the loop, which allows stuff such as:if (i > 3)
foo();
else
bar();
In fact, you could handle the case with the ‘{’ using this method by implementing the {…} as a ‘compound statement’, or several statements that the compiler treats as one. This approach also has several other cool advantages that I can discuss if you want.I'm torn between indentation and curly brackets - indentation might be more intuitive for Scratch users (concise syntax), but curly brackets might be easier for the parser(?) and would be easier to type in.indentation-based syntax is problematic. Many people have their tabs set up differently in their text editors; some people have a tab equal 4 spaces, some have it equal 2 spaces, and so forth. So if you try to make your code look pretty, it could end up looking ugly for someone else. If you really want indentation based syntax, a simple implementation would be to insert a ‘{’ for every tab gained relative to the previous line and a ‘}’ for every tab lost relative to the previous line. So something likerepeat 10would be read by the compiler as:
a();
repeat 5
b();
c();repeat 10 {
a();
repeat 5 {
b();
c();
}
}
- pedrodrocafranco
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
more easy for make pen partten is in textscratchwould use stack script or cris for a physic pen parttenWell, I think that it would be harder to implement… Just because it would have to sense if an { is there, and if it isn't, what then?if you had syntax like
If we don't, what would this be:repeat 20
me = Cat
}while i > j +3you would still have to detect the “loop” keyword. Even if you could find a way to not include it, you would still need to find a way to not include it.
loop
# stuff
end
If the ‘{’ is missing, you could throw a compile error as gosoccerboy suggested. Alternatively, you could just take the next statement as the body of the loop, which allows stuff such as:if (i > 3)
foo();
else
bar();
In fact, you could handle the case with the ‘{’ using this method by implementing the {…} as a ‘compound statement’, or several statements that the compiler treats as one. This approach also has several other cool advantages that I can discuss if you want.I'm torn between indentation and curly brackets - indentation might be more intuitive for Scratch users (concise syntax), but curly brackets might be easier for the parser(?) and would be easier to type in.indentation-based syntax is problematic. Many people have their tabs set up differently in their text editors; some people have a tab equal 4 spaces, some have it equal 2 spaces, and so forth. So if you try to make your code look pretty, it could end up looking ugly for someone else. If you really want indentation based syntax, a simple implementation would be to insert a ‘{’ for every tab gained relative to the previous line and a ‘}’ for every tab lost relative to the previous line. So something likerepeat 10would be read by the compiler as:
a();
repeat 5
b();
c();repeat 10 {
a();
repeat 5 {
b();
c();
}
}
- gosoccerboy5
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
Also, instead of (or with curly brackets or whatever) shouldn't it be (again, just assuming the syntax is indentation based)? Because that's how it is in Scratch?
while (5 > n):
n = n + 1
repeat until (not (5 > n)):
n = n + 1
- Greg8128
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
Also, instead ofHonestly it's not a big deal(or with curly brackets or whatever) shouldn't it bewhile (5 > n):
n = n + 1(again, just assuming the syntax is indentation based)? Because that's how it is in Scratch?repeat until (not (5 > n)):
n = n + 1
- gosoccerboy5
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
I feel like this should stick as close to scratch as possible, but I guess it doesn't matter ¯\_(ツ)_/¯
- mybearworld
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
Awesome idea, I've always wanted to make a programming language in Scratch that resembled the syntax of Javascript.Thanks!
What I mean by this is:var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
I suppose I can just program for it to look for the {. How aboutSyntax error. Also, all you have to do is measure how many ‘loops’ you'd be in by counting the number of curly brackets, and subtracting the amount of }'s.repeat 20
me = Cat
}
I'm torn between indentation and curly brackets - indentation might be more intuitive for Scratch users (concise syntax), but curly brackets might be easier for the parser(?) and would be easier to type in.
hello {
world
}If the ‘{’ is missing, you could throw a compile error as gosoccerboy suggested. Alternatively, you could just take the next statement as the body of the loop, which allows stuff such as:I don't really understand what you mean with this part.if (i > 3)
foo();
else
bar();
In fact, you could handle the case with the ‘{’ using this method by implementing the {…} as a ‘compound statement’, or several statements that the compiler treats as one. This approach also has several other cool advantages that I can discuss if you want.
That'd be challenging, but challenging doesn't mean impossible!repeat 10would be read by the compiler as:
a();
repeat 5
b();
c();repeat 10 {
a();
repeat 5 {
b();
c();
}
}
- Greg8128
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
Greg8128 wrote:
If the ‘{’ is missing, you could throw a compile error as gosoccerboy suggested. Alternatively, you could just take the next statement as the body of the loop, which allows stuff such as:
if (i > 3)
foo();
else
bar();
In fact, you could handle the case with the ‘{’ using this method by implementing the {…} as a ‘compound statement’, or several statements that the compiler treats as one. This approach also has several other cool advantages that I can discuss if you want.
I don't really understand what you mean with this part.
say that “x = 5” and “y = 7;” are statements. Then
x = 5;is two statements. However,
y = 7;
{is a “compound statement”, or “block”, which combines those two statements into one. This allows your syntax to call for any statement; see the following example for the syntax of an if-else statement:
x = 5;
y = 7;
}
if (<expression)> <statement> else <statement>
a cool fact about this is, if you treat if-else blocks as a statement, you get else-if statements implemented for free!
if (a)This works because
b();
else
if ( c )
d();
else
e();
if ( c )is treated as one statement.
d();
else
e();
Last edited by Greg8128 (Jan. 10, 2021 06:45:42)
- Greg8128
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
Another syntax that you could consider using is s-expressions, which are used in languages such as lisp.
Here is an example of code in Lisp, a language which uses s-expressions:
And the “equivalent” code in C:
Basically, s-expressions are enclosed in parentheses, and have arguments separated by spaces. The first argument is an operator or function, and the rest are arguments for that operator or function. For example, “(* 3 4 (+ 2 3))” in lisp is equivalent to “3 * 4 * (2+3)” in C.
S-expressions look weird, but they have the advantage of being easier to process with a computer. For example, you don't have to worry about order of operations, which can get rather complicated in other languages.
Here is an example of code in Lisp, a language which uses s-expressions:
(setq x 10)
(setq y (+ (* x 3) 20))
And the “equivalent” code in C:
int x = 10;
int y = x * 3 + 20;
Basically, s-expressions are enclosed in parentheses, and have arguments separated by spaces. The first argument is an operator or function, and the rest are arguments for that operator or function. For example, “(* 3 4 (+ 2 3))” in lisp is equivalent to “3 * 4 * (2+3)” in C.
S-expressions look weird, but they have the advantage of being easier to process with a computer. For example, you don't have to worry about order of operations, which can get rather complicated in other languages.
- mybearworld
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
Another syntax that you could consider using is s-expressions, which are used in languages such as lisp.You mean like
Here is an example of code in Lisp, a language which uses s-expressions:(setq x 10)
(setq y (+ (* x 3) 20))
And the “equivalent” code in C:int x = 10;
int y = x * 3 + 20;
Basically, s-expressions are enclosed in parentheses, and have arguments separated by spaces. The first argument is an operator or function, and the rest are arguments for that operator or function. For example, “(* 3 4 (+ 2 3))” in lisp is equivalent to “3 * 4 * (2+3)” in C.
S-expressions look weird, but they have the advantage of being easier to process with a computer. For example, you don't have to worry about order of operations, which can get rather complicated in other languages.
(* 5 4 6 (+ 7 9))
(5 * 4 * 6 * (7 + 9))
- gosoccerboy5
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
Hence the backronym for Lisp..(setq x 10)
(setq y (+ (* x 3) 20))
That seems like an interesting feature but I don't know if anyone but Lisp programmers would use that

Last edited by gosoccerboy5 (Jan. 11, 2021 14:23:23)
- Greg8128
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
To prove that parsing s-expressions is really easy, I made an s-expression parser in an hour or so:
https
/cdn2.scratch.mit.edu/get_image/project/472621441_100x80.png
The whole thing, including demo driver code, is just 155 blocks. (The link works now btw)
https
/cdn2.scratch.mit.edu/get_image/project/472621441_100x80.pngThe whole thing, including demo driver code, is just 155 blocks. (The link works now btw)
Last edited by Greg8128 (Jan. 12, 2021 19:18:25)
- Greg8128
-
Scratcher
500+ posts
TextScratch - A programming language in Scratch.
This is an English-speaking forum, please speak English so that everyone else can understand what you are saying.
- mybearworld
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
To prove that parsing s-expressions is really easy, I made an s-expression parser in an hour or so:It links to the project image..https
/cdn2.scratch.mit.edu/get_image/project/472621441_100x80.png
The whole thing, including demo driver code, is just 155 blocks.
Just looked at it, nice, but the result is missing

Last edited by mybearworld (Jan. 12, 2021 14:33:45)
- mybearworld
-
Scratcher
1000+ posts
TextScratch - A programming language in Scratch.
I will stop translating TOLORS and begin going on with TextScratch, as I think I should do this.
The way you people “motivated” me and gave me hints really inspired me and I developed my own ideas just while reading yours.
I am so excited for it and I can't wait releasing 0.1.0.
I'll start on optimizing the complier (or interpreter), to support loops and stuff.
This is my project I'm working on now.
(Text)scratch on!
The way you people “motivated” me and gave me hints really inspired me and I developed my own ideas just while reading yours.
I am so excited for it and I can't wait releasing 0.1.0.
I'll start on optimizing the complier (or interpreter), to support loops and stuff.
This is my project I'm working on now.
(Text)scratch on!





