A nice parsing library is pyparsing:
http://pyparsing.wikispaces.com/
It contains a parser for mathematical expressions.
There are examples in the source distribution.
HTH,
Eike.
___
Tutor maillist - Tutor@python.org
http://mail.python.org/mailman/li
Dj Gilcrease wrote:
> How would I go about writing a fast token parser to parse a string like
> "[4d6.takeHighest(3)+(2d6*3)-5.5]"
>
> and get a list like
> ['+',
> ['takeHighest',
> ['d',
> 4,
> 6
> ],
> 3
> ],
> ['-',
> ['*',
>
How would I go about writing a fast token parser to parse a string like
"[4d6.takeHighest(3)+(2d6*3)-5.5]"
and get a list like
['+',
['takeHighest',
['d',
4,
6
],
3
],
['-',
['*',
['d',
2,