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!
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.
Use python 3.8.5 Parser etc .: All made by myself (<-praise!)
--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.
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
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
--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