Beispiel #1
0
def t_error(t):
    print("Illegal character '%s'" % t.value[0])
    t.lexer.skip(1)


class Ex351Lexer:
    data = None
    lexer = None

    def __init__(self):
        self.lexer = lex.lex()

    def setData(self, data):
        self.data = data
        self.lexer.input(data)

    def tokenize(self):
        tokens = []
        while True:
            tok = self.lexer.token()
            if not tok:
                break  # No more input
            tokens.append(tok)
        return tokens


if __name__ == '__main__':
    lex = Ex351Lexer()
    lex.setData("17:54:14.473455 -0300	kernel	[IGFB][INFO   ] frameBuffer 0 : (colorMode=0x1)\n")
    print(lex.tokenize())
def t_error(t):
    print("Illegal character '%s'" % t.value[0])
    t.lexer.skip(1)


class Ex351Lexer:
    data = None
    lexer = None

    def __init__(self):
        self.lexer = lex.lex()

    def setData(self, data):
        self.data = data
        self.lexer.input(data)

    def tokenize(self):
        tokens = []
        while True:
            tok = self.lexer.token()
            if not tok:
                break  # No more input
            tokens.append(tok)
        return tokens


if __name__ == '__main__':
    lex = Ex351Lexer()
    lex.setData("if x then 3 <= 4 else 20 >= 1")
    print(lex.tokenize())
Beispiel #3
0
# Error handling rule
def t_error(t):
    print("Illegal character '%s'" % t.value[0])
    t.lexer.skip(1)

class Ex351Lexer:
    data = None
    lexer = None

    def __init__(self):
        self.lexer = lex.lex()

    def setData(self, data):
        self.data = data
        self.lexer.input(data)
        
    def tokenize(self):
        tokens = []
        while True:
            tok = self.lexer.token()
            if not tok:
                break      # No more input
            tokens.append(tok)
        return tokens

if __name__ == '__main__':
    lex = Ex351Lexer()
    lex.setData('while if _x then 3 < 4 else 20 == "ola"')
    print(lex.tokenize())