I made my own language. (1)

I made my own language.

Have you ever created your own language? e? is there? ,,,,,Oh yeah.

wait! Don't browser back! Is it interesting? This article! ,,Yes. Thank you very much. Once again, this time, "I tried to make my own language" This is the first time. ~~ Well, I just wrote an article about it. ~~ Then let's go now!

What do you make it?

I write a program (of course). At that time, it suddenly came to my mind. "If you can instruct your PC in a language, can you do the same in your own language?" When I think about it now, it was something I would forget immediately, but since I am a strange person, "If so, let's make it!" I thought that.

Overview

Use python 3.8.5 Parser etc .: All made by myself (<-praise!)

grammar

--I want to specify the type -I want to use {} instead of (). I personally like the shape. --For the time being, the function definition is left. But I want to make it happen. Because it's still the first time.

Code etc.

Oh, I forgot to write it, but I posted it on Github. URL:https://github.com/pythonmaster1027/Omega-version0.0.5 Also, I'm new to Python. I'm not good at writing code. Not bad. There is also an interactive type. URL:https://github.com/pythonmaster1027/Omega-version0.0.1

code

import sys
import os
from main import *

class Fread:
    def __init__(self):
        self.opf = open(str(sys.argv[1]), "r", encoding="utf_8")
    def run(self):
        opf2 = self.opf.readlines()
        for inp in opf2:
            m = Main(inp)
            m.serf()

import sys
from reanp import *
import os
from collections import defaultdict

global d, x, y

class Main:
    def __init__(self, inp):
        self.inp = inp
        self.dict = {}
        self.d = defaultdict(list)
 self.inp = self.inp.split ("//") [0] # // Remove
 self.inp = self.inp.split ("#") [0] Remove # #

    def serf(self):
        if self.inp.startswith("def ") or self.inp.startswith("    "):
            self.inp = self.inp.replace("    ", "")
            self.inp = self.inp.replace(";", "")
            print(self.inp)

            self.run()
        else:
            self.run()
    
 #Processing when printing a character string
    def run(self):
        if self.inp.startswith("print{") and "}" in self.inp and '"' in self.inp:
            self.inp = self.inp.replace("print{", "")
            self.inp = self.inp.replace("}", "")
            self.inp = self.inp.replace('"', "")
            print(self.inp)
        
 #Processing for variable definition
        elif "=" in self.inp:
            if self.inp.startswith("int "):
 self.inp = self.inp.replace ("int", "") # Remove int
                self.inp = self.inp.replace(" ", "")
                self.x = self.inp.split("=")[0]
                self.y = eval(self.inp.split("=")[-1])
                self.dict[self.x] = self.y
                f = open("sys\\var.oms", "a", encoding="utf_8")
                f.write(str(self.dict)+"\n")
                f.close()
            
            if self.inp.startswith("void "):
                self.inp = self.inp.replace("void", "")
                self.inp = self.inp.replace(" ", "")


 #Processing when printing variables
        elif self.inp.startswith("print{") and "}" in self.inp:
            self.inp = self.inp.replace("print{", "")
            self.inp = self.inp.replace("}", "")
            r = Read(self.inp)
            r.run()
        
        elif self.inp == "\n":
            pass
        
        elif self.inp == "exit{}":
            sys.exit(0)

        else:
            print("Err:No funcsion Error")

from ast import literal_eval
from pprint import pprint

class Read:
    def __init__(self, inp):
        self.f = open("sys\\var.oms", "r", encoding="utf_8")
 self.r = self.f.readlines () # list
        self.inp = inp

    def run(self):
        inp = self.inp
        v = Vpri()
        v.run(inp)
        self.f.close()


class Vpri:
 Variable name ordered to #inp = print
    def run(self, inp):
        fil_data = open("sys\\var.oms", encoding="utf_8")
        cov = open("sys\\varconp.oms", "w", encoding="utf_8")
        inp = inp.replace("\n", "")
 for line in fil_data: # Data read line by line
            line = line.replace("{", "").replace("}", "").replace("'", "").replace(" ", "")
            #line = line.rstrip()
 s = line.split (":") [0] #variable name
 i = line.split (":") [-1] # Data assigned to variables
            cov.write(s + "," + inp +"\n")
            if inp == s:
                print(i)
                break
            else:
                pass

        fil_data.close()
        cov.close()
@echo off
read.py %1

Easy to use

  1. Get to the folder with Omega.bat
  2. File name to execute Omega at the command prompt
  3. Run!

Summary

--Since I made it into a file and read it, the code became longer than I expected. --I'm having trouble saving variables. --Execution speed is slow !!!

This is dangomushi. Thank you for watching.

Recommended Posts

I made my own language. (1)
I made my own language (2)
I made my own AML
I made my own Python library
I made my goimports
I made my own primitive static site generator
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
I don't have the skills or strength, but I made my own compiler
[C language] My locomotive is too slow ~ I made a sl command ~
I made my dog "Monaka Bot" with LineBot
[I tried using Pythonista3] Importing my own module
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 an Xubuntu server.
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 an Anpanman painter discriminator
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 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