Это продолжает цикл на втором элифе - PullRequest
0 голосов
/ 29 сентября 2018

Не может пройти второй элиф.Код является частью интерпретатора в Python 3.7 Это результат

def make_tokens(self):
    tokens = []
    while self.current_char is not None:
        if self.current_char.isspace():
            print("debug if")
            self.advance()
            continue
        elif self.current_char == "''":
            print("debug elif 1")
            tokens.append(Token(STRING, self.string()))
        elif self.current_char in LETTERS:
            print("debug elif 2")
            tokens.append(Token(IDENTIFIER, self.identifier))
    return(tokens)
    print("debug make tokens end")

1 Ответ

0 голосов
/ 29 сентября 2018

Возможно, потому что self.current_char находится в LETTER на первой итерации.Тогда вы не меняете его во втором if, поэтому он продолжает оставаться в ПИСЬМАХ.

Вы должны сделать:

def make_tokens(self):
    tokens = []
    while self.current_char is not None:
        if self.current_char.isspace():
            print("debug if")

            # self.advance() remove this

            # continue remove this
        elif self.current_char == "''":
            print("debug elif 1")
            tokens.append(Token(STRING, self.string()))
        elif self.current_char in LETTERS:
            print("debug elif 2")
            tokens.append(Token(IDENTIFIER, self.identifier))

        self.advance() # add this

    return(tokens)
    print("debug make tokens end")
...