Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » I want to make a programming language...
- nickeljorn
- Scratcher
1000+ posts
I want to make a programming language...
I want to make a programming language, but I don't know how.
"Just what is the Summer Solstice, besides the day I melt into a puddle of fuzzy puppy fluff?”-Isabelle, Animal Crossing New Leaf
- NitroCipher
- Scratcher
500+ posts
I want to make a programming language...
A programming language of your own? Or an interpreter of an existing one?
I hope my post helped you in some way! Post count: 500+
Current project: [s3Blocks: scratchblocks rewritten for Scratch 3.0] ::#4b4a60 //https://scratch.mit.edu/discuss/topic/290031/ Basically done!This is my signature identifier “aWFtbml0cm9jaXBoZXI=”
- nickeljorn
- Scratcher
1000+ posts
I want to make a programming language...
A programming language of your own? Or an interpreter of an existing one?
A new programming language.
"Just what is the Summer Solstice, besides the day I melt into a puddle of fuzzy puppy fluff?”-Isabelle, Animal Crossing New Leaf
- MegaApuTurkUltra
- Scratcher
1000+ posts
I want to make a programming language...
Racket
$(".box-head")[0].textContent = "committing AT crimes since $whenever"
- TheAspiringHacker
- Scratcher
100+ posts
I want to make a programming language...
Do you want to make a specification (a formal document outlining the definition of the language) or an implementation (software that understands programs written in the language)?
Long live Kyoto Animation!
- ScratchMan544
- Scratcher
100+ posts
I want to make a programming language...
If you're actually looking at the implementation of programming languages:
I'll start with an example from a fake language. The program string is this:
The first step is to convert the program into small lexical units, called tokens. The internal representation for tokens might look something like this:
Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.
Now, at this point you have a few options:
I'll start with an example from a fake language. The program string is this:
let i = 0;
while i < 100 {
print("Number " + i.to_string());
i += 1;
}
The first step is to convert the program into small lexical units, called tokens. The internal representation for tokens might look something like this:
KEYWORD_LET
IDENTIFIER "i"
ASSIGN
NUMERIC_LITERAL 0
SEMICOLON
KEYWORD_WHILE
IDENTIFIER "i"
LESS_THAN
NUMERIC_LITERAL 100
OPEN_BRACE
IDENTIFIER "print"
OPEN_PARENTHESIS
STRING_LITERAL "Number "
PLUS
IDENTIFIER "i"
ATTRIBUTE "to_string"
OPEN_PARENTHESIS
CLOSE_PARENTHESIS
CLOSE_PARENTHESIS
SEMICOLON
IDENTIFIER "i"
PLUS_EQUALS
NUMERIC_LITERAL 1
SEMICOLON
CLOSE_BRACE
Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.
[
(declare "i" (numeric-literal 0)),
(while-loop (less-than (var "i") (numeric-literal 100) [
(call-function (var "print") [
(plus (string-literal "Number ")
(call-function (property "to_string" (var "i")) []))
]),
(plus-assign "i" 1)
]
]
Now, at this point you have a few options:
- You can execute this tree directly, which is oftentimes slower but simpler and more direct (this is an interpeter).
- You can translate it into an even lower-level representation (this is a compiler). This often requires going through at least one more intermediate representation.
Last edited by ScratchMan544 (Dec. 8, 2017 08:09:52)
_=(lambda _:lambda __:_(__))(lambda _:getattr(_,( lambda _:_[:2]+str(print.__call__)[0b10011:(1+1<<1+1+1)+(1<<1+1)+(1<<1)+1]+_[-2:] )(__name__)))(eval) (lambda _:lambda __:_(__))(lambda _:_(_( __import__(dir(__builtins__)[((1<<1+1)<<1+1+1)+(1+1<<1+1+1)+(1+1<<1)+(1<<1)][:3].lower()), print.__doc__[46:52]),open(__file__).write.__str__()[17:22]))(_("getattr"))(( lambda _:lambda __:_(_,__))(lambda _,__:""if __==0else chr(__%128)+_(_,__//128))(963149002634454890336513358634316810781103160855182366005237514)[::-1] )
- scorebat
- New to Scratch
31 posts
I want to make a programming language...
Why would you want to create a new language?
There are already so many of them.
Scorebat
There are already so many of them.
Scorebat
Scorebat
- herohamp
- Scratcher
1000+ posts
I want to make a programming language...
For education. Depending on how you write your language, you may need to write a system which compiles it to either binary, or another language that compiles to binary. Or you would need to write a parser Why would you want to create a new language?
There are already so many of them.
Scorebat
- _nix
- Scratcher
1000+ posts
I want to make a programming language...
It actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!
══ trans autistic lesbian enbydoggirls // 16 17 18 19 20, she/they ════
sparrows one word to the paragraph // <3 // ~(quasar) nebula
- NickyNouse
- Scratcher
1000+ posts
I want to make a programming language...
my order of operations is ltr thank you very muchIt actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!
- MegaApuTurkUltra
- Scratcher
1000+ posts
I want to make a programming language...
muh lispIt actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!
(+ 4 (* 5 2)) (* (+ 4 5) 2)
$(".box-head")[0].textContent = "committing AT crimes since $whenever"
- bobbybee
- Scratcher
1000+ posts
I want to make a programming language...
Hmmmmmph. I like Scheme. Brian broke me :^)muh lispIt actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!infix notation was a mistake and we all know it(+ 4 (* 5 2)) (* (+ 4 5) 2)
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- TheUltimatum
- Scratcher
1000+ posts
I want to make a programming language...
Racket.Hmmmmmph. I like Scheme. Brian broke me :^)muh lispIt actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!infix notation was a mistake and we all know it(+ 4 (* 5 2)) (* (+ 4 5) 2)
- bobbybee
- Scratcher
1000+ posts
I want to make a programming language...
Well sure, that's my preferred Scheme of choice, but heyRacket.Hmmmmmph. I like Scheme. Brian broke me :^)muh lispIt actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!infix notation was a mistake and we all know it(+ 4 (* 5 2)) (* (+ 4 5) 2)
“Ooo, can I call you Señorita Bee?” ~Chibi-Matoran
- MegaApuTurkUltra
- Scratcher
1000+ posts
I want to make a programming language...
me too thanksWell sure, that's my preferred Scheme of choice, but heyRacket.Hmmmmmph. I like Scheme. Brian broke me :^)muh lispIt actually doesn't. Next, you convert this to a tree that represents the structure of the program. This requires knowing about things like operator precedence.If you want your programming language to have automatic order of operations (e.g. knowing that 4 + 5 * 2 is 14 and not 18), you'll have to figure out how to implement that (which is operator precedence), but it's not inherently necessary when you're making a programming language!infix notation was a mistake and we all know it(+ 4 (* 5 2)) (* (+ 4 5) 2)
$(".box-head")[0].textContent = "committing AT crimes since $whenever"
- TheUltimatum
- Scratcher
1000+ posts
I want to make a programming language...
To add to the topic.. I'd recommend this tutorial by Jack Crenshaw. I think it's a really great intro to compiler design. Afterwards if you liked his tutorial I'd reccommend getting Compilers: Principles, Techniques and Tools I own the second edition bought it on amazon for 2$ used not bad at all and the book is great reading material. Though you may have a fun time porting the pre standard C to modern C. A very a good read I'm about a quarter of a way through and already learning all kinds of interesting things.
- Discussion Forums
- » Advanced Topics
- » I want to make a programming language...