Python as a parser (newbie)

Skip Montanaro skip at mojam.com
Fri Jul 30 12:51:32 EDT 1999


    Ryan> I am creating a program that needs to have scripting support.
    Ryan> I've looked at the faqs and cannot get the answer.  Can I use
    Ryan> Python's scripting ability to parse the input I need to give it,
    Ryan> and execute c/c++ functions realtime in my code?

Yes.  There are many ways to parse input.  Which way will depend largely
upon your input.  You can often get a long way by simply using string.split
and rummaging around ad hoc in the tokens it returns.  Other more complex
parsing tasks can be handled by regular expressions (the re module).  If the
mustard is still too thick to cut, more powerful parsing systems are
available as well, such as Aaron Watters' kwParsing package
(http://www.chordate.com/kwParsing/) and John Aycock's parser generator
(http://www.foretec.com/python/workshops/1998-11/proceedings/papers/aycock-little/aycock-little.html).

As for calling C/C++ functions realtime, "that's what tiggers do best".  You
can manually or mostly automatically write wrappers for function or class
libraries that make your C/C++ APIs callable from Python code.  For more
information, check out the Python Extending and Embedding documentation
(http://www.python.org/doc/current/ext/ext.html) and the SWIG web site
(http://www.swig.org/).

Skip Montanaro	| http://www.mojam.com/
skip at mojam.com  | http://www.musi-cal.com/~skip/
847-475-3758




More information about the Python-list mailing list