My first Python program -- a lexer

Arnaud Delobelle arnodel at googlemail.com
Sun Nov 9 02:36:45 EST 2008


Thomas Mlynarczyk <thomas at mlynarczyk-webdesign.de> writes:

> Hello,
>
> I started to write a lexer in Python -- my first attempt to do
> something useful with Python (rather than trying out snippets from
> tutorials). It is not complete yet, but I would like some feedback --
> I'm a Python newbie and it seems that, with Python, there is always a
> simpler and better way to do it than you think.
>

Hi,

Adding to John's comments, I wouldn't have source as a member of the
Lexer object but as an argument of the tokenise() method (which I would
make public).  The tokenise method would return what you currently call
self.result.  So it would be used like this.

>>> mylexer = Lexer(tokens)
>>> mylexer.tokenise(source)

# Later:

>>> mylexer.tokenise(another_source)

-- 
Arnaud



More information about the Python-list mailing list