Advertisement
Guest User

Untitled

a guest
Sep 25th, 2018
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.54 KB | None | 0 0
  1. import re
  2. import string
  3.  
  4. word = " ident assignment ident operator number operator ident"
  5.  
  6.  
  7. def boo(s):
  8.     tokens = s.lstrip()  # removes the leading whitespaces
  9.  
  10.     statement1 = ["assign_stmt", "expression"]  # need space in front of all stuff
  11.     assignment_stmt = ["ident assignment expression"]
  12.     expression1 = ["ident", "number", "ident operator expression", "number operator expression"]
  13.  
  14.     if tokens == statement1:
  15.         tokens = "statement"
  16.     else:
  17.         keep_going = True
  18.         lst = tokens.split(" ")  # converts the string into a list
  19.         while keep_going:
  20.             keep_going = False
  21.             for x in range(len(lst)):
  22.                 one = (lst[x:])  # this makes it forget the leftmost piece
  23.                 two = ' '.join(one)  # makes the list into a string.
  24.                 print(two)
  25.  
  26.                 if two in statement1:
  27.                     lst[x:] = ["statement"]
  28.                     # del lst[-1]
  29.                     keep_going = True
  30.                 elif two in assignment_stmt:
  31.                     lst[x:] = ["assign_stmt"]
  32.                     # del lst[-1]
  33.                     keep_going = True
  34.                 elif two in expression1:
  35.                     lst[x:] = ["expression"]
  36.                     # del lst[-1]
  37.                     keep_going = True
  38.  
  39.  
  40.         final_lst = ' '.join(lst)
  41.         print("here is final"+ final_lst)
  42.         if final_lst == "statement":
  43.             print ("Valid Statement")
  44.         else:
  45.             print ("Invalid Statement")
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52. boo(word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement