Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def hero():
- thisstring=''
- quote= False
- skip=False
- special =False
- for i in range(0, len(lexemmas)):
- if(skip):
- skip=False
- continue
- if(lexemmas[i]=='\n'):
- continue
- if(lexemmas[i]=='#'):
- printOutput(lexemmas[i], 'TOK_UNKNOWN')
- printError(lexemmas[i])
- thisstring=''
- continue
- if(not quote):
- switched = switcher.get(lexemmas[i], 'false')
- if(switched=='false'):
- thisstring = thisstring + lexemmas[i]
- special=False
- naya=True
- while naya:
- naya=False
- if(lexemmas[i]=='"'):
- if(quote):
- printOutput(thisstring.strip(), 'TOK_STRINGLIT')
- thisstring = ''
- quote= not quote
- elif(thisstring.strip() == 'for' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_FOR')
- thisstring=''
- elif (thisstring.strip() == 'if' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_IF')
- thisstring=''
- elif (thisstring.strip() == 'else' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_ELSE')
- thisstring=''
- elif (thisstring.strip() == 'while' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_WHILE')
- thisstring=''
- elif (thisstring.strip() == 'print' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_PRINT')
- thisstring=''
- elif (thisstring.strip() == 'return' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_RETURN')
- thisstring=''
- elif (thisstring.strip() == 'continue' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_CONTINUE')
- thisstring=''
- elif (thisstring.strip() == 'break' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_BREAK')
- thisstring=''
- elif (thisstring.strip() == 'debug' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_DEBUG')
- thisstring=''
- elif (thisstring.strip() == 'read' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_READ')
- thisstring=''
- elif (thisstring.strip() == 'let' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_LET')
- thisstring=''
- elif (thisstring.strip() == 'int' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_INT')
- thisstring=''
- elif (thisstring.strip() == 'float' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_FLOAT')
- thisstring=''
- elif (thisstring.strip() == 'string' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_STRING')
- thisstring=''
- elif (thisstring.strip() == '<' and checkEnd(i)):
- if(lexemmas[i+1]=='>'):
- printOutput(thisstring.strip()+ '>', 'TOK_NOTEQUALTO')
- skip=True
- else:
- printOutput(thisstring.strip(), 'TOK_LESSTHAN')
- thisstring=''
- elif (thisstring.strip() == '<>' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_NOTEQUALTO')
- thisstring=''
- elif (thisstring.strip() == ':'):
- if(lexemmas[i+1]=='='):
- printOutput(thisstring.strip()+ '=', 'TOK_ASSIGN')
- skip=True
- thisstring=''
- elif (thisstring.strip() == '=' and checkEnd(i)):
- if(lexemmas[i+1]=='='):
- printOutput(thisstring.strip()+ '=', 'TOK_EQUALTO')
- skip=True
- thisstring=''
- elif (thisstring.strip() == '>' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_GREATERTHAN')
- thisstring=''
- elif (thisstring.strip() == 'and' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_AND')
- thisstring=''
- elif (thisstring.strip() == 'or' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_OR')
- thisstring=''
- elif (thisstring.strip() == 'not' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_NOT')
- thisstring=''
- elif (thisstring.strip() == 'length' and checkEnd(i)):
- printOutput(thisstring.strip(), 'TOK_LENGTH')
- thisstring=''
- else:
- yo = thisstring.strip()
- num=''
- text=''
- if(not quote and (checkEnd(i) or special) and len(thisstring.strip())>0):
- if(yo[0].isalpha()):
- printOutput(yo, 'TOK_IDENTIFIER')
- elif(yo[0].isdigit()):
- for i in range(len(yo)):
- if(yo[i].isdigit() or yo[i]=='.'):
- num=num+yo[i]
- else:
- break
- if(num != ''):
- # print(num +str(checkEnd(i))
- text=yo[len(num):]
- if(float(num)==round(float(num))):
- printOutput(num, 'TOK_INTLIT')
- num=''
- else:
- printOutput(num, 'TOK_FLOATLIT')
- num=''
- if(len(text)>0):
- thisstring=text
- naya=True
- special=True
- text=''
- else:
- thisstring=''
- elif(thisstring==''):
- printOutput('lexemma: Unkown Token', 'TOK_UNKNOWN')
- else:
- printOutput(lexemmas[i], switched)
- if(quote):
- printOutput('EOF', 'TOK_EOF')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement