Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import re
- import string
- word = " ident assignment ident operator number operator ident"
- def boo(s):
- tokens = s.lstrip() # removes the leading whitespaces
- statement1 = ["assign_stmt", "expression"] # need space in front of all stuff
- assignment_stmt = ["ident assignment expression"]
- expression1 = ["ident", "number", "ident operator expression", "number operator expression"]
- if tokens == statement1:
- tokens = "statement"
- else:
- keep_going = True
- lst = tokens.split(" ") # converts the string into a list
- while keep_going:
- keep_going = False
- for x in range(len(lst)):
- one = (lst[x:]) # this makes it forget the leftmost piece
- two = ' '.join(one) # makes the list into a string.
- print(two)
- if two in statement1:
- lst[x:] = ["statement"]
- # del lst[-1]
- keep_going = True
- elif two in assignment_stmt:
- lst[x:] = ["assign_stmt"]
- # del lst[-1]
- keep_going = True
- elif two in expression1:
- lst[x:] = ["expression"]
- # del lst[-1]
- keep_going = True
- final_lst = ' '.join(lst)
- print("here is final"+ final_lst)
- if final_lst == "statement":
- print ("Valid Statement")
- else:
- print ("Invalid Statement")
- boo(word)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement