It's been too cold lately and I'm about to die ...
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
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
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