Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fileinput, re
- class Lexer:
- def __init__(self):
- self.tokenPattern = re.compile(r"""FORW|BACK|LEFT|RIGHT|DOWN|UP|COLOR|
- REP|\d+|#[\dA-F]{6}|\.|\"|\s+$|%"""
- ,re.MULTILINE)
- self.lineNumber = 0
- def __iter__(self):
- return self.__next__()
- def __next__(self):
- for line in fileinput.input():
- line = re.findall(self.tokenPattern, line)
- self.lineNumber += 1
- for token in line:
- yield token
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement