Basic tokenizer

Andrea Griffini agriff at
Sat Sep 4 22:54:01 CEST 2004

On Thu, 02 Sep 2004 13:02:09 GMT, "Paul McGuire"
<ptmcg at> wrote:

>I'd be interested in your feedback on this pyparsing example:

Like I said in another post I like pyparsing so far... but
I tried writing a bare-bone calculator and I got this...

It implements support for 5 operations, a few functions
and variables with assignment. Only imported module is "math",
and the line count is not really much higher than

If you wonder if you can be able to write a full programming
language parser this way I can ensure you that it's possible;
I've been there a few times (of course I'm not talking about
languages in which the grammar is a nightmare).

On the plus if you need to do a few little hacks (like
deciding how to parse something depending on the *meaning*
of a symbol) it's really easy. For an example of this kind
of hack in the barecalc calculator if an identifier is a
known function then the parser requires "("+expr+")" and
IMO this is crystal clear in the source.


More information about the Python-list mailing list