What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » [?] Pow... err, triggering some function on certain convo events?

[?] Pow... err, triggering some function on certain convo events?
Author: Message:
CookieRevised
Elite Member
*****

Avatar

Posts: 15519
Reputation: 173
– / Male / Flag
Joined: Jul 2003
Status: Away
RE: [?] Powers
It wouldn't be easy.... In fact, it would be hard, especially if you'r not used to regular expressions, parsing (sub)strings and manipulating (sub)strings, and other stuff...

To make what you want you need to make your own eval() function so to speak, from scratch. This means you need to take in account all the possible math operators which are to be used, the operator precedence and what not...

You need to parse each and every operator seperatly (since they can occur in any place in the expression), taking in account parenthesis and brackets and keeping everything in the correct order of precedence, etc etc.

----

To make it a bit easier, you can try to first make a parser which converts the normal math expression (called an infix expression) into a postfix expression (this would be the hardest part).

In that way, you can easly parse/evaluate everything from left to right instead of taking in account parenthesis, order of precedence, etc.

An example of a postfix expression is: "1 2 * 3 +", which will result in 5. Since it is converted from the normal math expression "1*2+3".

There are even already many JavaScript sources for evaluating a postfix expression (as it is actually dead easy). An example, including a very detailed explanation on how it works can be found here:
http://www.qiksearch.com/articles/cs/postfix-evaluation/index.htm

----

Infix notation

What most people understand under a mathematical expression. The operators are written in infix-style.

The major problem with this notation is that it is not that simple to parse. The parentheses surrounding the groups of operands and operators are necessary to indicate the order in which the operations are to be parsed. In the absence of parentheses, certain rules determine the order of operations.

eg1: (5+3)*9
eg2: 9*(5+3)


Postfix notation

Also called Reverse Polish notation (RPN)

This notation is also used in some scientific calculators, mostly in HP calculators. The most noticeable difference is that the operands come before the operator, thus leaving out the need for parentheses.

Unlike infix notation, parsing postfix notations is stack-based: operands are popped from a stack, and results are pushed back into it.

Although this might seem strange at first, postfix has the very big advantage of being extremely easy and fast.

Thus, calculations proceed from left to right.
There are no brackets or parentheses, as they are unnecessary.
Operands precede operator, they are removed as the operation is evaluated.
When an operation is done, the result becomes an operand itself (for later use for other operators).
There are no hidden states, and thus also no need to worry about checking if you have hit an operator or not.

eg1: 5 3 + 9 *
eg2: 9 5 3 + *


Convertion from infix to postfix

This is relativly hard (depends on how much experience you have on the matter). In fact, you better copy existing routines which are trialed and tested before if you don't fully understand the logic behind it.

Here is again a very easy explanation:
http://www.qiksearch.com/articles/cs/infix-postfix/
the source posted there is buggy, see the updated source here:
http://www.qiksearch.com/javascripts/infix-postfix.htm
http://www.codingforums.com/showthread.php?t=5692


Others:
http://www.cs.man.ac.uk/~pjj/cs2121/fix.html
http://www.unf.edu/~rzucker/cot3100dir/parser.html
http://trubetskoy1.narod.ru/english/alg/ppne.html

This post was edited on 09-17-2006 at 10:48 PM by CookieRevised.
.-= A 'frrrrrrrituurrr' for Wacky =-.
09-16-2006 01:27 PM
Profile PM Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
[?] Pow... err, triggering some function on certain convo events? - by Matti on 09-16-2006 at 11:41 AM
RE: [?] Powers - by markee on 09-16-2006 at 11:51 AM
RE: [?] Powers - by Matti on 09-16-2006 at 12:06 PM
RE: [?] Powers - by markee on 09-16-2006 at 12:23 PM
RE: [?] Powers - by CookieRevised on 09-16-2006 at 01:27 PM
RE: [?] Powers - by Matti on 09-16-2006 at 02:02 PM
RE: [?] Powers - by CookieRevised on 09-16-2006 at 02:11 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-16-2006 at 02:25 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by deAd on 09-16-2006 at 08:00 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-17-2006 at 09:19 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-17-2006 at 10:18 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Plik on 09-17-2006 at 12:30 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-17-2006 at 12:38 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by markee on 09-17-2006 at 12:46 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-17-2006 at 01:04 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-17-2006 at 03:30 PM
RE: RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-17-2006 at 11:03 PM
RE: RE: RE: [?] Pow... err, triggering some function on certain convo events? - by deAd on 09-17-2006 at 11:18 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-17-2006 at 11:42 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-18-2006 at 03:54 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-18-2006 at 05:57 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-18-2006 at 08:02 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-18-2006 at 11:09 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-18-2006 at 06:35 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-18-2006 at 08:07 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-18-2006 at 11:15 PM
RE: RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-19-2006 at 06:34 AM
RE: RE: RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-19-2006 at 06:48 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-19-2006 at 05:20 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by CookieRevised on 09-19-2006 at 10:50 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-19-2006 at 12:16 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Matti on 09-19-2006 at 06:33 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-19-2006 at 08:53 PM
RE: [?] Pow... err, triggering some function on certain convo events? - by phalanxii on 09-20-2006 at 12:31 AM
RE: [?] Pow... err, triggering some function on certain convo events? - by Shondoit on 09-20-2006 at 05:06 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On