Hej, kod:
global varab
varab = 0
vars = []
for i in range(0, 10):
vars.append(['',''])
#vars.v.append(['var1', 9])
#print(vars.v)
def error(num, error_type):
print(f'\033[91mGit Error #{num} >> {error_type} \033[0m')
def compiler(t):
if t:
compileLine = t
compileLines = compileLine.split()
#print(compileLines)
cl = compileLines[0]
if cl:
if cl == 'calc':
#print('Calculating')
calce=''
for i in range(0, len(compileLines)-1):
calce+=compileLines[i+1]
print(eval(calce))
elif cl == 'definedvars':
print('Defined vars: ')
vararray = vars
for i in vararray:
print(f'{i[0]} with value ${i[1]}')
elif cl == 'print':
calce=''
if len(compileLines)==2:
print(compileLines[1])
else:
manyBrackets = 0
for j in range(0,len(compileLines)):
if compileLines[j] == "'":
manyBrackets += 1
if manyBrackets == 2 or manyBrackets == 0:
if compileLines[1] == "'":
for i in range(0, len(compileLines)-2):
if compileLines[i+2] != "'":
calce += compileLines[i+2]
calce += " "
else:
print(calce)
else:
error(1, 'Function print can\'t have more than 0 or 2 "\'" ')
elif cl == 'gi':
if(compileLines[1].split('.')[1]=='gi'):
file = compileLines[1]
f = open(file, "r")
content = f.readlines()
for k in content:
if k == '':
print('')
else:
compiler(k)
else:
error('4', f'File with {compileLines[1].split(".")[1]} extension can\'t be readed')
elif cl == 'var':
print(vars)
if len(compileLines) < 3:
for k in vars:
if k[0] == str(compileLines[1]):
error('2', f'Variable named {str(compileLines[1])} exist!')
break
else:
vars[varab] = [str(compileLines[1]), None]
varab += 1
print(vars)
break
else:
if str(compileLines[2]) == '=':
calce = ''
manyD = 0
for i in range(0, len(compileLines)-3):
if str(i+3) == "'":
manyD += 1
continue
else:
calce += str(compileLines[i+3])
if manyD == 0 or manyD == 2:
for k in vars:
if k[0] == compileLines[1]:
error('2', f'Variable named {str(compileLines[1])} exist!')
break
else:
vars[varab] = [str(compileLines[1]), calce]
varab += 1
else:
error('2', 'In Variable, you must use 0 or 2 "\'"')
else:
print("null")
while True:
compiler(input("Git => "))
jest problem bo jak odpalam i pisze np:
var a to wyskakuje:
[['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', ''], ['', '']]
Traceback (most recent call last):
File "shell.py", line 111, in <module>
compiler(input("Git => "))
File "shell.py", line 78, in compiler
vars[varab] = [str(compileLines[1]), None]
UnboundLocalError: local variable 'varab' referenced before assignment
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! git@1.0.1 start: `py shell.py`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the git@1.0.1 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm WARN Local package.json exists, but node_modules missing, did you mean to install?
co jest nie tak