Skip to content

Instantly share code, notes, and snippets.

@kerem3338
Last active July 12, 2023 13:20
Show Gist options
  • Save kerem3338/013eae3fd95ec0b55a7cace64fb38abc to your computer and use it in GitHub Desktop.
Save kerem3338/013eae3fd95ec0b55a7cace64fb38abc to your computer and use it in GitHub Desktop.
Basit bir kod yorumlayıcı
#2021 Kakos kişiselleşirilmiş lisans © Zoda
#Bu kodu kişsel veya özel kullanım için modifiye edebilirsiniz
import os
import sys
tokens = []
def open_file(file_name):
data = open(file_name, "r").read()
return data
def lex(contents):
content = list(contents)
tok = ""
state = 0
string = ""
for char in content:
tok += char
if tok == " ":
tok=""
elif tok =="print":
tokens.append("PRİNT")
tok = ""
elif tok == "\"" or "'":
if state == 0:
state = 1
elif state == 1:
tokens.append("STRİNG:" + string)
string = ""
state = 0
elif state == 1:
string += char
tok = ""
print(tokens)
def run():
data = open_file(fr"{os.getcwd()}\{input('file name:')}") #Thanks Bahadır54
lex(data)
if __name__ == "__main__":
run()
@bahadiraraz
Copy link

def run():
	data = open_file(fr"{os.getcwd()}\{input('file name:')}")
	lex(data)
if __name__ == "__main__":
	run()

I think it would be better.

@kerem3338
Copy link
Author

yes

@troopcat
Copy link

troopcat commented Aug 1, 2021

single quoted strings is not working

@kerem3338
Copy link
Author

tek tırnaklı dizeler çalışmıyor
i handle it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment