I made my own language (2)

It's time for your own language

It's been too cold lately and I'm about to die ...

I made it again

Yes, I updated it. The main changes are

--I also made my own error function / error. If you don't make your own, you won't be attached to it. --class / What is it, but I finally implemented the class. Object thinking, hurray! --I managed to get rid of the blanks when I printed. --The number of files has decreased dramatically. ――Thanks to that, execution has become lighter!

Click here for Omega-version 0.1.0 (Github) ->https://github.com/pythonmaster1027/Omega-version0.1.0

Torima code

File hierarchy

(Arbitrary directory)
 ├ main.py
 └ Omega.bat

There is very little code.

main.py


import os
import sys

class Start:#I want you to start

    def __init__(self):#Initialize
        try:
            self.f = open(sys.argv[1], "r", encoding="utf_8")
        
        except IndexError:
            print("Please specify the file name")
            sys.exit()
        
        except FileNotFoundError:
            print("File not found")
            print("To solve: Make the file path the full path")
            sys.exit()
        
        self.r = self.f.readlines()
        self.re = self.f.read()
        self.dic1 = {}

    def run(self):#I want you to run

        if "class Main{\n" in self.r:
            for line in self.r:
                line = line.replace("    ", "").replace(" ", "").split("//")[0]#line = self.Program read line by line from f
                
                #print
                if "print" and '"' in line:
                    pr = line.replace("print", "").replace("{", "").replace("}", "").replace('"', "")
                    print(pr)
                
                #Variable definition
                elif line.startswith("int") or line.startswith("str"):
                    self.var = line.replace('\n', "")
                    varname = self.var.split("=")[0]#Variable name
                    if line.startswith("int"):
                        try:
                            self.ele = eval(self.var.split("=")[-1].replace("int", ""))#int type element
                        except NameError:
                            print("Err: NameErr")
                            self.ele = "Not int"
                    elif line.startswith("str"):
                        self.ele = self.var.split("=")[-1].replace("str", "")#int type element
                    self.dic1[varname] = self.ele
                    
                #Print that specifies a variable as an argument
                elif "print" in line:
                    line = line.replace("print", "").replace("{", "").replace("}", "").replace("\n", "")
                    print(self.dic1[line])

                elif line in "\n":
                    pass
        else:
            print("Err:class[Main]Not found")
            sys.exit()

#Execution function definition
def main():
    s = Start()
    s.run()

#Execution department
if __name__ == '__main__':
    main()

Python code, that's it. Only. Next, Omega.bat.

Omega.bat


@echo off
main.py %1

Summary

This language is composed of only 2 files. It's amazing that you can create a language with just two files. Next, I would like to implement the function definition as well.

Recommended Posts

I made my own language. (1)
I made my own language (2)
I made my own AML
I made my goimports
I made my own primitive static site generator
I made my own parallel link robot (software version)
I made my own parallel link robot (mechanical edition)
I made my own OSS because I wanted to contribute to it
[Python] I made my own library that can be imported dynamically
Python> I made a test code for my own external file
I am making my own aws cli
I made my own filter plugin for text parsing of Ansible
I made my own research tool using the legal API [Smart Roppo]
Since I made my own smart lock, I will summarize the difficult points
[C language] My locomotive is too slow ~ I made a sl command ~
I made my dog "Monaka Bot" with LineBot
〇✕ I made a game
I made an Ansible-installer
I tried learning my own dataset using Chainer Trainer
I made my own Django Middleware so that I can access request information from anywhere
Heapsort made in C language
I made blackjack with python!
I published my own Python baseball library to Packaging & PyPI
I made a python text
I made a surveillance camera with my first Raspberry PI.
I tried 100 language processing knock 2020
When I made a Discord Bot, my classmates destroyed my computer
I made a discord bot
I made COVID19_simulator with JupyterLab
I made Word2Vec with Pytorch
I made blackjack with Python.
I made wordcloud with Python.
I made a script to say hello at my Koshien
I made my own 3-layer forward propagation neural network and tried to understand the calculation deeply.
I made a C ++ learning site
I made a Line-bot using Python!
I made a CUI-based translation script (2)
I made a wikipedia gacha bot
I tried 100 language processing knock 2020: Chapter 3
I made a fortune with Python.
I made a CUI-based translation script
vim settings (editing my own notes)
I made an Angular starter kit
I tried 100 language processing knock 2020: Chapter 1
I made a daemon with Python
I tried 100 language processing knock 2020: Chapter 2
I tried 100 language processing knock 2020: Chapter 4
I installed Linux on my Mac
I put Alpine Linux in Larkbox and made it my home server
I tried how to improve the accuracy of my own Neural Network
I made a kind of simple image processing tool in Go language.
I made it thinking "My virtual machine router can't be this fast"
I made go language for api and minimum configuration of react for front