Advertisement
Guest User

parser.py

a guest
Mar 22nd, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.78 KB | None | 0 0
  1.  
  2.  
  3. def parser(code):
  4.    index = 0
  5.    type = ""
  6.    value = ""
  7.    comment = ""
  8.    
  9.    # setup
  10.    new_variable = ""
  11.    new_say = ""
  12.    new_input = ""
  13.    nothing = ""
  14.    
  15.    while index < len(code):
  16.       type = code[index][0]
  17.       value = code[index][1]
  18.      
  19.       # print(code)
  20.      
  21.       # Statement end
  22.       if type == "STATEMENT_END" and value == ";":
  23.          new_variable = ""
  24.          new_say = ""
  25.          new_input = ""
  26.      
  27.       # Comment
  28.       if type == "COMMENT_START":
  29.          comment = "true"
  30.       elif type == "COMMENT_END":
  31.          comment = ""
  32.       elif comment == "true":
  33.          nothing = ""
  34.          
  35.       # new variable
  36.       elif new_variable != "":
  37.          if type == "STRING" or type == "INTEGER":
  38.             exec("script_" + new_variable + ' = "' +  value + '"')
  39.          else:
  40.             exec("script_" + new_variable + " = " + value)
  41.      
  42.       # new input
  43.       elif new_input != "":
  44.          if type == "STRING" or type == "INTEGER":
  45.             exec("script_" + new_input + ' = input("' +  value + '")')
  46.          else:
  47.             exec("script_" + new_input + ' = input("' + value + '")')
  48.            
  49.       # input
  50.       elif type == "INPUT":
  51.          new_input = value
  52.          
  53.       # say
  54.       elif new_say == "true":
  55.          value = (value)
  56.          if type == "GET_VAR":
  57.             exec('print(script_' + value + ")")
  58.          elif type == "INTEGER":
  59.             exec('print("' + str(value) + '")')
  60.          else:
  61.             exec('print("' + str(value) + '")')
  62.          new_say = ""
  63.          
  64.       # if else elif stuff hard
  65.       # elif type == "IF":
  66.      
  67.      
  68.       # stuff
  69.       elif type == "IDENTIFIER" and value == "say":
  70.          new_say = "true"
  71.      
  72.       elif type == "VAR_DECLEARATION":
  73.          new_variable = value
  74.      
  75.      
  76.       index += 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement