parse C expression?

Chris Rebert clp at rebertia.com
Mon Dec 15 20:19:08 EST 2008


On Mon, Dec 15, 2008 at 3:48 PM, Torsten Mohr <tmohr at s.netic.de> wrote:
> Hi,
>
> i found some examples when googling for the subject but nothing really
> matched.
>
> Is there a standard module available that lets me parse a syntax like "C"
> with numbers, operators, braces, variables and function calls?
>
> I'd like to use this to parse an own kind of configuration language
> and preferred would be just standard modules.  Is there something
> available that is maybe based on shlex?

No, nothing approaching C-syntax as it'd have be much more complicated
than shlex and I can't imagine too many uses for such a module.
If it's a configuration file, you might consider using either JSON
(std lib module `json`) or INI (std lib module `ConfigParser`) as the
format instead. Or if you need something really complex, just use
Python itself.
Custom config file formats are bad anyway.

Should you have no control over the format, you'll need to write a
proper parser grammar with something like pyparsing as was mentioned
by James.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



More information about the Python-list mailing list