Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.72 KB | None | 0 0
  1. def hero():
  2. thisstring=''
  3. quote= False
  4. skip=False
  5. special =False
  6. for i in range(0, len(lexemmas)):
  7. if(skip):
  8. skip=False
  9. continue
  10. if(lexemmas[i]=='\n'):
  11. continue
  12. if(lexemmas[i]=='#'):
  13. printOutput(lexemmas[i], 'TOK_UNKNOWN')
  14. printError(lexemmas[i])
  15. thisstring=''
  16. continue
  17.  
  18. if(not quote):
  19. switched = switcher.get(lexemmas[i], 'false')
  20.  
  21. if(switched=='false'):
  22. thisstring = thisstring + lexemmas[i]
  23. special=False
  24. naya=True
  25. while naya:
  26. naya=False
  27. if(lexemmas[i]=='"'):
  28. if(quote):
  29. printOutput(thisstring.strip(), 'TOK_STRINGLIT')
  30. thisstring = ''
  31. quote= not quote
  32. elif(thisstring.strip() == 'for' and checkEnd(i)):
  33. printOutput(thisstring.strip(), 'TOK_FOR')
  34. thisstring=''
  35. elif (thisstring.strip() == 'if' and checkEnd(i)):
  36. printOutput(thisstring.strip(), 'TOK_IF')
  37. thisstring=''
  38. elif (thisstring.strip() == 'else' and checkEnd(i)):
  39. printOutput(thisstring.strip(), 'TOK_ELSE')
  40. thisstring=''
  41. elif (thisstring.strip() == 'while' and checkEnd(i)):
  42. printOutput(thisstring.strip(), 'TOK_WHILE')
  43. thisstring=''
  44. elif (thisstring.strip() == 'print' and checkEnd(i)):
  45. printOutput(thisstring.strip(), 'TOK_PRINT')
  46. thisstring=''
  47. elif (thisstring.strip() == 'return' and checkEnd(i)):
  48. printOutput(thisstring.strip(), 'TOK_RETURN')
  49. thisstring=''
  50. elif (thisstring.strip() == 'continue' and checkEnd(i)):
  51. printOutput(thisstring.strip(), 'TOK_CONTINUE')
  52. thisstring=''
  53. elif (thisstring.strip() == 'break' and checkEnd(i)):
  54. printOutput(thisstring.strip(), 'TOK_BREAK')
  55. thisstring=''
  56. elif (thisstring.strip() == 'debug' and checkEnd(i)):
  57. printOutput(thisstring.strip(), 'TOK_DEBUG')
  58. thisstring=''
  59. elif (thisstring.strip() == 'read' and checkEnd(i)):
  60. printOutput(thisstring.strip(), 'TOK_READ')
  61. thisstring=''
  62. elif (thisstring.strip() == 'let' and checkEnd(i)):
  63. printOutput(thisstring.strip(), 'TOK_LET')
  64. thisstring=''
  65. elif (thisstring.strip() == 'int' and checkEnd(i)):
  66. printOutput(thisstring.strip(), 'TOK_INT')
  67. thisstring=''
  68. elif (thisstring.strip() == 'float' and checkEnd(i)):
  69. printOutput(thisstring.strip(), 'TOK_FLOAT')
  70. thisstring=''
  71. elif (thisstring.strip() == 'string' and checkEnd(i)):
  72. printOutput(thisstring.strip(), 'TOK_STRING')
  73. thisstring=''
  74. elif (thisstring.strip() == '<' and checkEnd(i)):
  75. if(lexemmas[i+1]=='>'):
  76. printOutput(thisstring.strip()+ '>', 'TOK_NOTEQUALTO')
  77. skip=True
  78. else:
  79. printOutput(thisstring.strip(), 'TOK_LESSTHAN')
  80. thisstring=''
  81. elif (thisstring.strip() == '<>' and checkEnd(i)):
  82. printOutput(thisstring.strip(), 'TOK_NOTEQUALTO')
  83. thisstring=''
  84. elif (thisstring.strip() == ':'):
  85. if(lexemmas[i+1]=='='):
  86. printOutput(thisstring.strip()+ '=', 'TOK_ASSIGN')
  87. skip=True
  88. thisstring=''
  89. elif (thisstring.strip() == '=' and checkEnd(i)):
  90. if(lexemmas[i+1]=='='):
  91. printOutput(thisstring.strip()+ '=', 'TOK_EQUALTO')
  92. skip=True
  93. thisstring=''
  94. elif (thisstring.strip() == '>' and checkEnd(i)):
  95. printOutput(thisstring.strip(), 'TOK_GREATERTHAN')
  96. thisstring=''
  97. elif (thisstring.strip() == 'and' and checkEnd(i)):
  98. printOutput(thisstring.strip(), 'TOK_AND')
  99. thisstring=''
  100. elif (thisstring.strip() == 'or' and checkEnd(i)):
  101. printOutput(thisstring.strip(), 'TOK_OR')
  102. thisstring=''
  103. elif (thisstring.strip() == 'not' and checkEnd(i)):
  104. printOutput(thisstring.strip(), 'TOK_NOT')
  105. thisstring=''
  106. elif (thisstring.strip() == 'length' and checkEnd(i)):
  107. printOutput(thisstring.strip(), 'TOK_LENGTH')
  108. thisstring=''
  109. else:
  110. yo = thisstring.strip()
  111. num=''
  112. text=''
  113. if(not quote and (checkEnd(i) or special) and len(thisstring.strip())>0):
  114.  
  115. if(yo[0].isalpha()):
  116. printOutput(yo, 'TOK_IDENTIFIER')
  117. elif(yo[0].isdigit()):
  118. for i in range(len(yo)):
  119. if(yo[i].isdigit() or yo[i]=='.'):
  120. num=num+yo[i]
  121. else:
  122. break
  123. if(num != ''):
  124. # print(num +str(checkEnd(i))
  125. text=yo[len(num):]
  126. if(float(num)==round(float(num))):
  127. printOutput(num, 'TOK_INTLIT')
  128. num=''
  129. else:
  130. printOutput(num, 'TOK_FLOATLIT')
  131. num=''
  132. if(len(text)>0):
  133. thisstring=text
  134. naya=True
  135. special=True
  136. text=''
  137. else:
  138. thisstring=''
  139. elif(thisstring==''):
  140. printOutput('lexemma: Unkown Token', 'TOK_UNKNOWN')
  141. else:
  142. printOutput(lexemmas[i], switched)
  143.  
  144. if(quote):
  145. printOutput('EOF', 'TOK_EOF')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement