Advertisement
Guest User

Untitled

a guest
Nov 26th, 2015
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. import fileinput, re
  2.  
  3. class Lexer:
  4.     def __init__(self):
  5.         self.tokenPattern = re.compile(r"""FORW|BACK|LEFT|RIGHT|DOWN|UP|COLOR|
  6.                                           REP|\d+|#[\dA-F]{6}|\.|\"|\s+$|%"""
  7.                                            ,re.MULTILINE)
  8.         self.lineNumber = 0
  9.  
  10.     def __iter__(self):
  11.         return self.__next__()
  12.  
  13.     def __next__(self):
  14.         for line in fileinput.input():
  15.             line = re.findall(self.tokenPattern, line)
  16.             self.lineNumber += 1
  17.             for token in line:
  18.                 yield token
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement