Basic tokenizer

Andrea Griffini agriff at tin.it
Sat Sep 4 16:54:01 EDT 2004


On Thu, 02 Sep 2004 13:02:09 GMT, "Paul McGuire"
<ptmcg at austin.rr._bogus_.com> wrote:

>I'd be interested in your feedback on this pyparsing example:
>http://www.geocities.com/ptmcg/python/fourFn.py.txt

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

http://www.gripho.it/barecalc.py.txt

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 fourFn.py.

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.

Andrea



More information about the Python-list mailing list