Da bin ich wieder . Ich bin gerade dabei einen kleinen Interpreter für eine selbst ausgedachte Sprache in Python zu schreiben. Aber bei der Stringverarbeitung gibt es einen Fehler. Hier erstmal der Code:
Code: Alles auswählen
#!/usr/bin/python
#-*- coding: utf-8 -*-
import sys
i=0
x=[0]*30000
lines=[0]*60000
dat = open(sys.argv[1],"r")
line = dat.readline()
k=0
while line != "":
if line[:1] != "#":
lines[k] = line
k+=1
line = dat.readline()
dat.close()
while 1:
tmp_line = lines[i]
if tmp_line[:1] == ".":
out=""
tok = tmp_line[1:].split(",")
for t in tok:
if t[:1]=="\"" and t[::-1][:1]=="\"" :
out+=t[1:-1]
elif t[:1]=="x":
out+=str(x[int(t[1:])])
else:
print "Error in Line \n%s"%(tmp_line)
exit()
i+=1
Code: Alles auswählen
#start
."Hallo",x3
#ende
Code: Alles auswählen
Traceback (most recent call last):
File "asms.py", line 33, in <module>
if tmp_line[:1] == ".":
TypeError: 'int' object is unsubscriptable
Code: Alles auswählen
Hallo0
Vielen Dank schonmal im Vorraus.
MfG
Dr.ChAoS