I was planning to get together with my friends because of a certain virus, and it was canceled and I was depressed. Forgive a certain virus.
I think this time it is highly complete. Personally, this is the best result of the year. The hard part was putting together a series of processes with functions. Anyway, I was worried. ~~ But it took about a week ~~ Oh, by the way, I started to follow. Please feel free to comment on the mistakes in the article, "I shouldn't do this more", or "I think this process should be done". I think the URL is on My Page. Click here for the code-> https://github.com/pythonmaster1027/Omega-version0.2.3/tree/main
You don't care about it, do you? (For my convenience, it is assumed that I will develop with python. However, if your main language is not python, if you are motivated to "may be able to do it" or "do it", I will definitely try it. I think it should be.)
0, schedule decision. : Never pull it out. I try to schedule anything, not just language development. That's because it's just a waste of time to ask, "What? What should I do?" Also, I think that development will continue if you make it quickly while you have motivation.
Create a virtual machine. : Readers may be wondering what happened from the very beginning. But you can. Well, even though it's a virtual machine, in my case it's just four arithmetic operations. Other than that, I will post it as it is with the expansion of the language function. For more information, see main.py [Vm class] on Github.
Grammar decision. : It's the most important. The important thing is "whether it's fun to write". Readability will be managed later.
Make a lexical analyzer. : Create a lexical analyzer according to your desired grammar. It runs slower, but it seems better to use regular expressions. However, I survived with "replace". Processed with Token class.
4, make a parser. : It seems that a large number of frustrated people will occur from around here. But as you can see from my code (I wonder if you can find it on the Github link), it's not like "I'll parse the syntax!" I just rearranged it. All you have to do is understand your virtual machine. That's why I created a virtual machine first. Actually processed by Token class.
5, transpile. : Transpile the four arithmetic languages of virtual machines and the parsed language with the "intermediate language" after parsed. This forced me to use replace, which made the completed language extremely slow. Is it made of python? ~~ Children look like parents. ~~ This slowness is an issue for readers. (← Hey) This is also processed by the Token class.
For example, this process can be performed in the Omega language (the name of your own language) (finally the main subject). This process is commonly referred to as a "number guessing game".
main.om
def :main():
input">"inp;
if inp == dango = {test()};
println_Sorry!;
end;
def :test():
println_Correct answer!!;
println_Enter y to continue the game and n to stop the game.;
input">"ans;
if ans == y = {start()};
exit;
def :start():
while_True = {main()};
end;
start();
--I haven't implemented the return value or the argument area yet. It's an issue for the next time. --The equivalent of print in python is "println". Output with "_" (hyphen) after println. --Basically, the contents of if / while are function calls. This is because I wanted to make it a "strict functional language" as a hobby. This area is an application, so if you don't like it, please remodel it. ――The rest is the input part. Use input-> Characters at the time of input-> Variables to store --Also, use "let" to initialize variables. --For character strings, use "str". --As an example, if you want to define a string type variable "word", set "str word = dangomushi;".
This time, I explained "How to make your own language". As for my impression, it's fun to make my own language (laughs). Everyone, please try to make your own language! !! Also, as mentioned above, not only "I can't think of a way to increase followers", but also "I can't interact with people who have the same hobbies in the first place", so if you have any doubts, "This is better" If you have any opinions, please come to the rice section or DM! !! (Promotion) See you in the next article! goodbye! !!
Recommended Posts