My first Python program -- a lexer

Thomas Mlynarczyk thomas at
Mon Nov 10 14:29:02 CET 2008

Paul McGuire schrieb:

> loc = data.index("list")
> print data[:loc].count("\n")-1
> print loc-data[:loc].rindex("\n")-1
> prints 5,14
> I'm sure it's non-optimal, but it *is* an algorithm that does not
> require keeping track of the start of every line...

Yes, I was thinking of something like this. As long as the line/column 
are only needed in case of an error (i.e. at most once per script run), 
I consider this more performant than keeping track of line/column for 
every token.


Ce n'est pas parce qu'ils sont nombreux à avoir tort qu'ils ont raison!

More information about the Python-list mailing list