return Token(EOF, None)
def advance(self): self.pos += 1 if self.pos > len(self.text) - 1: self.current_char = None else: self.current_char = self.text[self.pos]
Hope this helps!
Here's an outline of an interesting report on compiler design based on the book:
# Token class class Token: def __init__(self, type, value): self.type = type self.value = value
if self.current_char == '+': self.advance() return Token(PLUS, '+')
if self.current_char == '-': self.advance() return Token(MINUS, '-')
return Token(EOF, None)
def advance(self): self.pos += 1 if self.pos > len(self.text) - 1: self.current_char = None else: self.current_char = self.text[self.pos]
Hope this helps!
Here's an outline of an interesting report on compiler design based on the book:
# Token class class Token: def __init__(self, type, value): self.type = type self.value = value
if self.current_char == '+': self.advance() return Token(PLUS, '+')
if self.current_char == '-': self.advance() return Token(MINUS, '-')