Discuss 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:
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.

mybearworld wrote:

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 we don't, what would this be:
repeat 20
me = Cat
}
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.

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.

Resince wrote:

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:
var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
That'd be pretty sweet. (Would there be like return functions and stuff, or would it be limited to Scratch abilities?)
Resince
Scratcher
100+ posts

TextScratch - A programming language in Scratch.

gosoccerboy5 wrote:

Resince wrote:

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:
var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
That'd be pretty sweet. (Would there be like return functions and stuff, or would it be limited to Scratch abilities?)

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.

mybearworld wrote:

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 we don't, what would this be:
repeat 20
me = Cat
}
if you had syntax like
while i > j +3
loop
# stuff
end
you 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.

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.

gosoccerboy5 wrote:

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 10
a();
repeat 5
b();
c();
would be read by the compiler as:
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.

Greg8128 wrote:

mybearworld wrote:

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 we don't, what would this be:
repeat 20
me = Cat
}
if you had syntax like
while i > j +3
loop
# stuff
end
you 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.

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.

gosoccerboy5 wrote:

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 10
a();
repeat 5
b();
c();
would be read by the compiler as:
repeat 10 {
a();
repeat 5 {
b();
c();
}
}
would use stack script or cris for a physic pen partten
pedrodrocafranco
Scratcher
500+ posts

TextScratch - A programming language in Scratch.

pedrodrocafranco wrote:

Greg8128 wrote:

mybearworld wrote:

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 we don't, what would this be:
repeat 20
me = Cat
}
if you had syntax like
while i > j +3
loop
# stuff
end
you 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.

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.

gosoccerboy5 wrote:

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 10
a();
repeat 5
b();
c();
would be read by the compiler as:
repeat 10 {
a();
repeat 5 {
b();
c();
}
}
would use stack script or cris for a physic pen partten
more easy for make pen partten is in textscratch
gosoccerboy5
Scratcher
1000+ posts

TextScratch - A programming language in Scratch.

Also, instead of
while (5 > n):
n = n + 1
(or with curly brackets or whatever) shouldn't it be
repeat until (not (5 > n)):
n = n + 1
(again, just assuming the syntax is indentation based)? Because that's how it is in Scratch?
Greg8128
Scratcher
500+ posts

TextScratch - A programming language in Scratch.

gosoccerboy5 wrote:

Also, instead of
while (5 > n):
n = n + 1
(or with curly brackets or whatever) shouldn't it be
repeat until (not (5 > n)):
n = n + 1
(again, just assuming the syntax is indentation based)? Because that's how it is in Scratch?
Honestly it's not a big deal
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.

Resince wrote:

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:
var i = 0; // Creates a variable set to zero.
repeat (5) { // Repeat Loop
i++; // Changes i by + 1
say (i); // Prints i
}
Thanks!

gosoccerboy5 wrote:

mybearworld wrote:

repeat 20
me = Cat
}
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.

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.
I suppose I can just program for it to look for the {. How about
hello {
world
}
? I think this would be easier..

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.

Greg8128 wrote:

repeat 10
a();
repeat 5
b();
c();
would be read by the compiler as:
repeat 10 {
a();
repeat 5 {
b();
c();
}
}
That'd be challenging, but challenging doesn't mean impossible!
Greg8128
Scratcher
500+ posts

TextScratch - A programming language in Scratch.

mybearworld wrote:

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;
y = 7;
is two statements. However,
{
x = 5;
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:
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)
b();
else
if ( c )
d();
else
e();
This works because
if ( c )
d();
else
e();
is treated as one statement.

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:
(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.

Greg8128 wrote:

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:
(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.
You mean like
(* 5 4 6 (+ 7 9))
is equal to
(5 * 4 * 6 * (7 + 9))
Seems quite useful!
gosoccerboy5
Scratcher
1000+ posts

TextScratch - A programming language in Scratch.

Greg8128 wrote:

(setq x 10)
(setq y (+ (* x 3) 20))
Hence the backronym for Lisp..
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)

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.

Greg8128 wrote:

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.
It links to the project image..
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!

Powered by DjangoBB