Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to create your own programming language in python

run = True
while 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.
Comment

create programming language in python

from sly import Parser

class BasicParser(Parser):
	#tokens are passed from lexer to parser
	tokens = BasicLexer.tokens

	precedence = (
		('left', '+', '-'),
		('left', '*', '/'),
		('right', 'UMINUS'),
	)

	def __init__(self):
		self.env = { }

	@_('')
	def statement(self, p):
		pass

	@_('var_assign')
	def statement(self, p):
		return p.var_assign

	@_('NAME "=" expr')
	def var_assign(self, p):
		return ('var_assign', p.NAME, p.expr)

	@_('NAME "=" STRING')
	def var_assign(self, p):
		return ('var_assign', p.NAME, p.STRING)

	@_('expr')
	def statement(self, p):
		return (p.expr)

	@_('expr "+" expr')
	def expr(self, p):
		return ('add', p.expr0, p.expr1)

	@_('expr "-" expr')
	def expr(self, p):
		return ('sub', p.expr0, p.expr1)

	@_('expr "*" expr')
	def expr(self, p):
		return ('mul', p.expr0, p.expr1)

	@_('expr "/" expr')
	def expr(self, p):
		return ('div', p.expr0, p.expr1)

	@_('"-" expr %prec UMINUS')
	def expr(self, p):
		return p.expr

	@_('NAME')
	def expr(self, p):
		return ('var', p.NAME)

	@_('NUMBER')
	def expr(self, p):
		return ('num', p.NUMBER)


class BasicExecute:
	
	def __init__(self, tree, env):
		self.env = env
		result = self.walkTree(tree)
		if result is not None and isinstance(result, int):
			print(result)
		if isinstance(result, str) and result[0] == '"':
			print(result)

	def walkTree(self, node):

		if isinstance(node, int):
			return node
		if isinstance(node, str):
			return node

		if node is None:
			return None

		if node[0] == 'program':
			if node[1] == None:
				self.walkTree(node[2])
			else:
				self.walkTree(node[1])
				self.walkTree(node[2])

		if node[0] == 'num':
			return node[1]

		if node[0] == 'str':
			return node[1]

		if node[0] == 'add':
			return self.walkTree(node[1]) + self.walkTree(node[2])
		elif node[0] == 'sub':
			return self.walkTree(node[1]) - self.walkTree(node[2])
		elif node[0] == 'mul':
			return self.walkTree(node[1]) * self.walkTree(node[2])
		elif node[0] == 'div':
			return self.walkTree(node[1]) / self.walkTree(node[2])

		if node[0] == 'var_assign':
			self.env[node[1]] = self.walkTree(node[2])
			return node[1]

		if node[0] == 'var':
			try:
				return self.env[node[1]]
			except LookupError:
				print("Undefined variable '"+node[1]+"' found!")
				return 0

              
if __name__ == '__main__':
	lexer = BasicLexer()
	parser = BasicParser()
	print('GFG Language')
	env = {}
	
	while True:
		
		try:
			text = input('GFG Language > ')
		
		except EOFError:
			break
		
		if text:
			tree = parser.parse(lexer.tokenize(text))
			BasicExecute(tree, env)
Comment

is python a programming language

Python is an interpreted, object-oriented, 
 high-level programming language with dynamic semantics.
Comment

python coding language

if you are a beginner do python instread of being like me and starting with c#
Comment

python language

#for python comments
Comment

python programming language

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
Comment

how to make a programming language in python

# 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 using

def Bin(Integer):  
    return bin(Integer).replace("0b", "")  
class Symbol:
    def __init__(self, name=''):
        self.name = f"Symbol({name})"
    def __repr__(self):
        return self.name
lines = text
def mySplit(string):
    text = string
    string = string
    string = string.replace("(", "œ", 1)
    string = string[::-1].replace(")"[::-1], "œ"[::-1], 1)[::-1]
    text = string.split("œ")
    return text

def mySplit2(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 lines

for i in lines:
    # next write the instructions
    
    count+=1
    code = mySplit(i.strip().replace("
", ""))
    code2 = mySplit2(i.strip().replace("
", ""))
    x = 0
    
    while True:
        x+=2
        try:
            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))
            elif list(i.strip().replace("
", ""))[0:2] == list("//"):
                pass
            elif i.strip().replace("
", "") != "":
               print("invalid syntax at line " + str(count))

        except IndexError:
            pass
        try:
            code[x + 2]
        except Exception:
            break
    
Comment

how to make a programming language in python

while True:
    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
Comment

how to create your own programming language in python

run = True
while 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
Comment

PREVIOUS NEXT
Code Example
Python :: get category discord.py 
Python :: python3 password generator script 
Python :: python sort case insensitive 
Python :: python launch prompt 
Python :: csv reader url 
Python :: python rabbitmq 
Python :: convert uppercase to lowercase and vice versa in python 
Python :: Python NumPy asfarray Function Example List to float type array 
Python :: how to move an item from one list to another python 
Python :: how to add two strings in python 
Python :: list of single item repeated python 
Python :: python builtwith 
Python :: pythom Lambda 
Python :: functional conflict definition 
Python :: python sched 
Python :: division operators in python 
Python :: Display vowels in a string using for loop 
Python :: how to open link in new tab selenium python 
Python :: lowering the time.countdown python 
Python :: python web server oneliner 
Python :: pysolr - connect to solr via vpn 
Python :: renpy quickstart 
Python :: python force realod 
Shell :: copy ssh key mac 
Shell :: docker delete all images 
Shell :: ubuntu extract rar 
Shell :: git config username and password global 
Shell :: uninstall material ui react 
Shell :: install redis on mac pro 
Shell :: reload zshrc 
ADD CONTENT
Topic
Content
Source link
Name
8+7 =