[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-core-devel
Subject:    Re: Looking for (KDE) lib/class to perform calculations
From:       Marc Mutz <Marc.Mutz () uni-bielefeld ! de>
Date:       2002-03-25 19:20:03
[Download RAW message or body]

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 25 March 2002 02:59, Rob Kaper wrote:
<snip>
> For my purposes an integer would be precise enough, I'm just multiplying
> (always towards integers) and adding/substracting stuff.
>
> If you need to know why.. most rent values in the Monopoly game are based
> on a baserent and a multiplier and/or addition based on number of
> improvements, dice thrown or properties owned. I could put about 200 static
> values in a config file, but those can actually be replaced with about 10
> generic mathematical ones and 25 exceptions, which are mathematical rules
> applied after the generic one.
<snip>

In this case, writing a parser for a stack language (a la PostScript or the 
bibtex style language) is probably the easiest. Unless you want the user to 
edit the expressions. Stack langages are a bit - um unintuitive:

BibTex: a b + 'c :=
C:      c = a + b;

But it's _very_ easy to implement, since you can just read a token and do what 
it tells you:
a  - push(a)
b  - push(b)
+  - push( pop() + pop() )
'c - push("c")
:= - variable[pop()] = pop();

Marc

- -- 
Marc Mutz <mutz@kde.org>
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQE8n3hj3oWD+L2/6DgRAjhrAJ0VZgG6pL8FXtljoh52fPocI7DDCACg1BAU
zKoxyrXDai9G8wQEjQ70RQ8=
=fzwZ
-----END PGP SIGNATURE-----

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic