Let's make a number guessing game in your own language!

It's time for your own language!

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 made it again.

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

A series of development flow

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.

  1. 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.

  2. Grammar decision. : It's the most important. The important thing is "whether it's fun to write". Readability will be managed later.

  3. 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.

grammar

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;".

Summary

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

Let's make a number guessing game in your own language!
Let's make a rock-paper-scissors game
Study, number guessing game in Python
Let's make a shiritori game with Python
Let's make a simple language with PLY 1
Let's make a combination calculation in Python
Argument implementation (with code) in your own language
Make a cocos2d game in a pixel double window
Make a rock-paper-scissors game in one line (python)
Make a squash game
Make a Tetris-style game!
Try to make a Python module in C language
Let's make a simple game with Python 3 and iPhone
Let's make a cron program in Java! !! (Task Scheduler)
Let's make a Discord Bot.
Let's make a spot sale service 4 (in Python mini Hack-a-thon)
Make a bookmarklet in Python
Try to make a blackjack strategy by reinforcement learning (③ Reinforcement learning in your own OpenAI Gym environment)
Try HeloWorld in your own language (with How to & code)
Make your own VPC with a Single Public Subnet Only with boto
Let's make a remote rumba [Hardware]
[Python] Make your own LINE bot
Let's make a remote rumba [Software]
[Python] logging in your own module
Let's make a GUI with python.
Let's make a spot sale service 2
Let's make a breakout with wxPython
Let's make a graph with python! !!
Let's make a supercomputer with xCAT
Make a curtain generator in Blender
Let's make a spot sale service 3
Use a scripting language for a comfortable C ++ life 4-Use your own C ++ library from a scripting language-
Make your own NOAA / GOES familiar X-ray flux 3days plot in Python
Let's make an image recognition model with your own data and play!
How to make a request to bitFlyer Lightning's Private API in Go language
Create your own Linux commands in Python
[LLDB] Create your own command in Python
Make your own PC for deep learning
[GO language] Let's read a YAML file
Let's make a voice slowly with Python
Let's make a multilingual site using flask-babel
Let's make a web framework with Python! (1)
Let's make a tic-tac-toe AI with Pylearn 2
Let's analyze a Chinese retro game machine
Let's run a Bash script in Java
Let's make a Twitter Bot with Python!
Let's make a web framework with Python! (2)
Let's make a Backend plugin for Errbot
Get your own IP address in Python