Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #78558
| References | <4a7f3e7a-ba4d-405e-a078-937bf861fcd8@googlegroups.com> <542c2f9a$0$12975$c3e8da3$5496439d@news.astraweb.com> |
|---|---|
| Date | 2014-10-02 03:01 +1000 |
| Subject | Re: how to parse standard algebraic notation |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.14524.1412182911.18130.python-list@python.org> (permalink) |
On Thu, Oct 2, 2014 at 2:45 AM, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> wrote:
> Code for evaluating mathematical expressions are very common, if you google
> for "expression parser" I am sure you will find many examples. Don't limit
> yourself to Python code, you can learn from code written in other languages
> too, e.g. I have a Pascal programming book that develops a parser for both
> polynomials and arithmetic expression.
Building expression evaluators is good fun! And then you can add
specialty terms, like dice rolling.
> roll 2d6 + d6 "Electric" + 12 "Strength"
[ROLL] Rosuav rolls 2d6: 3, 6, totalling 9.
[ROLL] Rosuav rolls d6: 1 ("Electric")
[ROLL] Rosuav adds a bonus of 12 ("Strength")
[ROLL] For 2d6 + d6 "Electric" + 12 "Strength", Rosuav totals: 22
The code behind that follows a fairly similar pattern to what you
describe, only it deals with dice rolls (NdM -> roll N dice with M
sides each) instead of powers of x. (And it allows comments/tags.)
ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
how to parse standard algebraic notation math math <mathematisch@gmail.com> - 2014-09-30 13:53 -0700
Re: how to parse standard algebraic notation Gary Herron <gherron@digipen.edu> - 2014-09-30 14:05 -0700
Re: how to parse standard algebraic notation math math <mathematisch@gmail.com> - 2014-10-01 00:01 -0700
Re: how to parse standard algebraic notation Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-10-01 08:35 +0100
Re: how to parse standard algebraic notation Chris Angelico <rosuav@gmail.com> - 2014-10-01 18:38 +1000
Re: how to parse standard algebraic notation math math <mathematisch@gmail.com> - 2014-10-01 05:04 -0700
Re: how to parse standard algebraic notation Marco Buttu <marco.buttu@gmail.com> - 2014-10-01 14:22 +0200
Re: how to parse standard algebraic notation Marco Buttu <marco.buttu@gmail.com> - 2014-10-01 14:26 +0200
Re: how to parse standard algebraic notation Chris Angelico <rosuav@gmail.com> - 2014-10-01 10:20 +1000
Re: how to parse standard algebraic notation wxjmfauth@gmail.com - 2014-10-01 01:08 -0700
Re: how to parse standard algebraic notation Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-10-02 02:45 +1000
Re: how to parse standard algebraic notation Chris Angelico <rosuav@gmail.com> - 2014-10-02 03:01 +1000
csiph-web