|
1. Mathematical Expression Interpreter
|
|
Sun Mar 7, 2004 [7:03 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
Reply
|
* operator priority
* ( ) -1
* * / % 0
* + - 1
* << >> 2
* & 3
* ^ 4
* | 5
* && 6
* || 7
* == <= >= != < > 8
* variable 9
I skipped the "!" operator cause it doesn't follow the normal syntax and isn't necesairy either. Was wondering if I forgot anything else, so far it's sort of c inspired, but I wonder if there might be other common options that'd be cool to add. Also looking into string comparing, the merc mprog engine uses /= and /! for 'contains' and 'does not contain', I was wondering if there are some commonly used operators for strings, and if so, what they are, or a link :)
|
|
|
|
|
2. RE: Mathematical Expression Interpreter
|
|
Sun Mar 7, 2004 [11:06 AM]
|
Spazmatic1
Email not supplied
member since: Aug 14, 2002
|
In Reply To
Reply
|
|
A lot of it comes down to what purpose the interpreter will have. I mean, do you really want to build Matlab style matrix functionality into your system?
|
|
|
|
|
3. RE: Mathematical Expression Interpreter
|
|
Sun Mar 7, 2004 [11:31 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
It's for a mud client which will use 2 commands:
#math {variable} {expression} #if {expression} {doiftrue} [{doiffalse}]
So far I'm thinking about adding ~= which would do a regexp comparison. But if I'm missing operators that could be useful, I'd like to hear about it. Sort of asuming there's some knowledge about useful non c operators here, as well as common syntax.
Would this matlab style matrix functionality be any fun? =]
|
|
|
|
|
4. RE: Mathematical Expression Interpreter
|
|
Mon Mar 15, 2004 [2:51 PM]
|
Blobule
blobule@wocmud.org
member since: Nov 29, 2001
|
In Reply To
Reply
|
|
You should add the D operator. That way you can do xDy with a minimum of effort.
Cheers, Rob.
|
|
|
|
|
5. RE: Mathematical Expression Interpreter
|
|
Mon Mar 15, 2004 [3:28 PM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
|
|
|
|
6. RE: Mathematical Expression Interpreter
|
|
Mon Mar 15, 2004 [6:31 PM]
|
Spazmatic1
Email not supplied
member since: Aug 14, 2002
|
In Reply To
Reply
|
|
Well... Implementation would be fun (at least to a theorist like me... interesting algorithms always are, mathematical algorithms doubly so), at least of the more interesting matrices operations. For the enduser, though... Maybe it they were trying to execute the Simplex method or something, to solve a linear program and maximize their bots' experience gaining effectiveness.
|
|
|
|
|
7. RE: Mathematical Expression Interpreter
|
|
Tue Mar 16, 2004 [2:06 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
Well, I guess I must leave the scope as basic as possible. Over functionality is mostly what kills a program, and I'm sure the geeks can add their own blink blink if they have a decent, basic mathematical toolkit.
So far I added ! ~ + and - (the - is really useful I found out :p)
^= which performs a logical xor comparison.
== and != are capable of holding regular expressions in the right field for string comparison.
<= , >= < and > can be used on strings returning the alphabetic order difference.
I was surprised I couldn't find any free library that interprets mathematical expressions, though this way I can add whatever functionality I desire. I don't believe there's any mud client out there doing anything of this order, so I guess it's a bitch to code as it is =]
|
|
|
|
|
8. RE: Mathematical Expression Interpreter
|
|
Tue Mar 16, 2004 [11:49 AM]
|
Drey
Email not supplied
member since: Mar 19, 2000
|
In Reply To
Reply
|
|
In RPG parlance, xDy is "roll x dice of size y and sum the results".
|
|
|
|
|
9. RE: Mathematical Expression Interpreter
|
|
Tue Mar 16, 2004 [12:22 PM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
doh, somehow didn't make the connection. Thanx for the clarification and a good suggestion Blobule :)
#if {1d10 == 5} would be a lot more natural for the average rpg-er than some odd random number generation operation, which I hadn't added anyways.
*photo of pizza and coke flying toward Scandum as he starts coding*
|
|
|
|
|
10. RE: Mathematical Expression Interpreter
|
|
Tue Mar 16, 2004 [2:52 PM]
|
Tyche
Email not supplied
member since: Apr 4, 2000
|
In Reply To
Reply
|
|
I'd leave out bit operations and the entire notion of bits. They aren't even necessary to end user programming. On an earlier thread, someone, I can't remeber who, pointed out the ** operator which is raise to the power. I thought it was an incredibly convenient shorthand and incorporated it into Aphrodite. I'm not sure how useful it would be to client programming. YMMV. :-)
|
|
|
|
|
11. RE: Mathematical Expression Interpreter
|
|
Tue Mar 16, 2004 [6:44 PM]
|
Spazmatic1
Email not supplied
member since: Aug 14, 2002
|
In Reply To
Reply
|
|
*ponders*
You know, I'm not even sure what the order-of-operations would be if you added a lot of extra operators. I don't think it's even defined by any common standard, if you were to add weird shorthand like Matlab's A\b or something.
|
|
|
|
|
12. RE: Mathematical Expression Interpreter
|
|
Wed Mar 17, 2004 [12:27 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
There's always ( ) and the option to increase the priority range. Will give the dice roll operator it's own priority level higher than * / % because someone will likely end up doing 10 * 1d100 expecting 10 * (1d100) to be executed :)
|
|
|
|
|
13. RE: Mathematical Expression Interpreter
|
|
Wed Mar 17, 2004 [1:02 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
Well, bit operation aren't necessary, but can be quite useful. Just that there aren't many end user applications using them efficiently. But I understand what you mean, 99% of the users will likely never use them, so I'll make sure to leave them out of the internal help file and put it in the documentation :) Their existance shouldn't be an issue though for someone doing 10 + 4 * 5 stuff I hope. And I know a few people who would love to use bit operations for bitvectors and bitrange calculations.
Regarding ** , would 10 ** 3 result in 1000? and I also recall a =* operator being used, which might return true for 1000 =* 10 (1000 being a power of 10) though not entirely sure about the exact usage since that wasn't described, so it could be the other way around?
|
|
|
|
|
14. RE: Mathematical Expression Interpreter
|
|
Wed Mar 17, 2004 [7:50 AM]
|
Blobule
blobule@wocmud.org
member since: Nov 29, 2001
|
In Reply To
Reply
|
|
It's gotta be the shortest way possible to provide dice roll functionality in a clear and concise manner. I think many of my scripts use this operator every 3rd or 4th line. Also some interesting things you can do if you implement support for parenthesis in your expressions. Like:
if( 1d(3d4) == 5 )
Albeit you won't probably need this in particular, but I know I use parenthesis all over the place in my expressions. Especially now that I script spells too.
|
|
|
|
|
15. RE: Mathematical Expression Interpreter
|
|
Wed Mar 17, 2004 [8:17 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
support for parenthesis was already included =]
|
|
|
|
|
16. RE: Mathematical Expression Interpreter
|
|
Wed Mar 17, 2004 [11:45 AM]
|
Spazmatic
Email not supplied
member since: Aug 2, 2002
|
In Reply To
Reply
|
|
Aha! But what if I want (10*1)d100??? Huh? Huh? Punk.
Kidding. However, it does serve my point. You're going to have to create fairly thorough documentation, because combining these operators together is... "new" and "unkempt".
|
|
|
|
|
17. RE: Mathematical Expression Interpreter
|
|
Wed Mar 17, 2004 [12:07 PM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
if you want to do (10*1)d100 you just fill in (10*1)d100, and the interpreter is just fine with that.. and a priority table is all the documentation required =]
|
|
|
|
|
18. RE: Mathematical Expression Interpreter
|
|
Thu Mar 18, 2004 [4:37 AM]
|
Blobule
blobule@wocmud.org
member since: Nov 29, 2001
|
In Reply To
Reply
|
|
I don't know if it's useful to you, but here's how I did my precedence table (highest precedence to lowest):
( ) -> ! ~ + (unary) - (unary) D ^^ % * / - + MIN MAX . (concatenation - implicit and cannot be used explicitly) << >> == != < > <= >= & | ^ && || += -= /= *= %= ^^= &= |= ^= <<= >>= .= :=
Most of this follows standard C precedence. As with the ongoing discussion, I considered D to be of high precedence since it's more likely the case you want 10 * (1d100) than the case of (10 * 1)d100.
Cheers, Blobule.
|
|
|
|
|
19. RE: Mathematical Expression Interpreter
|
|
Thu Mar 18, 2004 [6:42 AM]
|
scandum
Email not supplied
member since: Aug 30, 2002
|
In Reply To
Reply
|
|
00- ! ~ + - 01- d 02- % * / 03- - + 04- << >> 05- < > <= >= 06- == != 07- & 08- ^ 09- | 10- && 11- ^^ (xor) 12- || 13- variable 14- () (semi operator)
I'm exactly following C precedence now I believe, unless I googled up the wrong manual. The priority of the () doesn't matter much I guess, I keep track of parenthesis level and work top down till I reach the 0 level.
the = and ? operators are replaced by 2 commands, which call the math exp routine.
|
|
|
|
|