how to create your own programming language in python
run =Truewhile run:
code =input('>>')if code !="exit":if code =="say:":
say_what =input("....")print(say_what)try:if code =="if:":
statement_true =None
if_what =input('what')if if_what:print("True")else:print("Flase")except:print(f"Error")#credit me i am vivaan please or if i find you i will report.
Python is a high-level, interpreted, general-purpose programming language.
Its design philosophy emphasizes code readability with the use of significant indentation.
Python is dynamically-typed and garbage-collected
# I've tried making a programming language# It wasn't to great, But it was nice# 1st find the file to run and read the lines
text =""
consts =[]import sys
try:file=open(sys.argv[1])
lines =file.readlines()except Exception:print("Error: No file to run")# 2nd I will create all the variables and functions I will be usingdefBin(Integer):returnbin(Integer).replace("0b","")classSymbol:def__init__(self, name=''):
self.name =f"Symbol({name})"def__repr__(self):return self.name
lines = text
defmySplit(string):
text = string
string = string
string = string.replace("(","œ",1)
string = string[::-1].replace(")"[::-1],"œ"[::-1],1)[::-1]
text = string.split("œ")return text
defmySplit2(string):
text = string
string = string
string = string.replace("=","œ=œ")
text = string.split("œ")return text
sep =lambda String,sep: sep.join(list(String))
builtins ={"int":int,"str":str,"float":float,"bool":bool,"unique": Symbol,"hex":hex,"bin": Bin,"list":list,"sep": sep }
count =0# 3rd loop through the linesfor i in lines:# next write the instructions
count+=1
code = mySplit(i.strip().replace("
", ""))
code2 = mySplit2(i.strip().replace("
", ""))
x =0whileTrue:
x+=2try:if code[x -2].strip()=="Console.println":try:print(eval(code[x -1],{"__builtins__": builtins}))except Exception as e:print(str(e))elif code[x -2].strip()=="Console.print":try:print(eval(code[x -1],{"__builtins__": builtins}), end="")except Exception as e:print(str(e))elif code[x -2].strip()=="Console.input":try:input(eval(code[x -1],{"__builtins__": builtins}))except Exception as e:print(str(e))elif code[x -2].strip()=="Console.waite":try:import time
time.sleep(eval(code[x -1],{"__builtins__": builtins}))except Exception as e:print(str(e))eliflist(i.strip().replace("
", ""))[0:2] == list("//"):passelif i.strip().replace("
", "") != "":print("invalid syntax at line "+str(count))except IndexError:passtry:
code[x +2]except Exception:break
whileTrue:
a =input("code>>")exec(a)#this makes a python compiler ide in python if you write print("hello world") in #terminal it can write hello world