Author Topic: Prefix Expression Evaluator  (Read 3242 times)

0 Members and 1 Guest are viewing this topic.

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Prefix Expression Evaluator
« on: June 29, 2008, 11:44:48 pm »
Script Name: Prefix Expression Evaluator
Script Description: Evaluates an expression (prefix notation) Example: PEvaluate('+ * 4 3 7') returns '19'. This is for scripters, not server owners. If you wish to use this script in your script, feel free to, but please note my name.
Original Author: DorkeyDear (Curt)
Core Version: 2.6.3
Required Files:
filename (minimal version) link
convert.pas (5) http://curt.soldatrs.com/boosters/convert.pas
math.pas (20) http://curt.soldatrs.com/boosters/math.pas
strops.pas (3) http://curt.soldatrs.com/boosters/strops.pas
pexpreval.pas (1.3) http://curt.soldatrs.com/boosters/pexpreval.pas

What is Prefix Notation?
Prefix notation is a notation of writing out expressions
Just like we do "4 + 3" in infix notation, we would do "+ 4 3" in prefix notation
For something more complex, we have "(x + 1) / (x - 1)" in infix notation, we would do "/ + x 1 - x 1" in prefix notation

Reasons of...
preference
Argument length specifiable
Faster than my Expression Evaluator
Easy to learn
No parenthesis
No order of precedence
Dynamic argument count
avoidance
Not used to the style (majority of people do not know the syntax)
Confusing to look at

Notes:
Case-sensitive
Ignores double spaces, single space required separator
Prompting a boolean, anything non-0 is true
Returning a boolean, 1=true, 0=false
Dynamic argument count functions will require the required arguments first, then the count of dynamic arguments; ex "sum a b ..." length will be -3, and we want to add some numbers, here is how it would work "sum 10 9 2 8 7" and 10, 9, 8, and 7 will be operated on; note that if you want 0 dynamic arguments, you still will require to put the zero, "sum 10 9 0"

Operators and Functions:
pi: float; value of pi
e: float; value of e
phi float; value of Phi
abs float: float; absolute value
sign float: integer; sign (-1 for negatives, 0 for 0, 1 for positives)
int float: integer; integer part of value
float float: float; float part of value
roundto float integer: float; rounds to nearest specified decimal place
round float: integer; rounds to the nearest integer
floor float: integer; floors the number
ceil float: integer; ceilings the number
sqrt float: float; square-root
sin float: float; sine
cos float: float; cosine
tan float: float; tangent
sec float: float; secant
csc float: float; cosecant
cot float: float; cotangent
arcsin float: float; arc-sine
arccos float: float; arc-cosine
arctan float: float; arc-tangent
arcsec float: float; arc-secant
arccsc float: float; arc-cosecant
arccot float: float; arc-cotangent
ln float: float; natural logarithm (slow and inaccurate)
not boolean: boolean; not
bool float: boolean; returns boolean value
fac integer: integer; factorial
ncr integer integer: integer; combination
npr integer p integer: integer; permutation
pow float integer: float; exponents
* float float: float; multiplication
/ float float: float; division
% float float: float; modulus
+ float float: float; addition
- float float: float; subtraction
<< integer integer: integer; bit shift left
>> integer integer: integer; bit shift right
< float float: boolean; less than
<= float float: boolean; less than or equal to
> float float: boolean; greater than
>= float float: boolean; greater than or equal to
== float float: boolean; equal to
!= float float: boolean; not equal to
and boolean boolean: boolean; logical and
xor boolean boolean: boolean; logical xor
or boolean boolean: boolean; logical or
sum integer float..: float; sum
mtp integer float..: float; multiplies
min integer float..: float; smallest value
max integer float..: float; largest value
con string string: string; concatenate
conn integer string..: string; concatenate

Please report any bugs or suggestions
« Last Edit: July 03, 2008, 11:45:43 am by DorkeyDear »

Offline iDante

  • Veteran
  • *****
  • Posts: 1967
Re: Prefix Expression Evaluator
« Reply #1 on: June 30, 2008, 12:02:59 am »
very nice. did you get ln working any better?
« Last Edit: June 30, 2008, 12:51:54 pm by iDante »

Offline ZomgProniss

  • Camper
  • ***
  • Posts: 318
  • Known ingame as Proniss
Re: Prefix Expression Evaluator
« Reply #2 on: June 30, 2008, 01:01:26 am »
sounds sik i know noting about scipting but ya sounds awsome

Offline shantec

  • Soldier
  • **
  • Posts: 140
  • Get ANGREH!!
Re: Prefix Expression Evaluator
« Reply #3 on: June 30, 2008, 06:50:08 am »
Soo... i just wonder how much stuff you can Evaluate / PEvaluate at one time? As much as you want?
Also Known As REIMA


Lol Happles (happy apples)

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Prefix Expression Evaluator
« Reply #4 on: June 30, 2008, 11:37:51 am »
Update:
  • Support for dynamic number of arguments
  • Added sum function
  • Added mtp function
« Last Edit: June 30, 2008, 11:42:15 am by DorkeyDear »

Offline JFK

  • Camper
  • ***
  • Posts: 255
    • My TraxInSpace Account
Re: Prefix Expression Evaluator
« Reply #5 on: June 30, 2008, 05:20:11 pm »
Again, f-ing awesome.. now to think of a script that uses all your operators and functions ;)
Come join: EliteCTF
Listen to: My Music

Offline DorkeyDear

  • Veteran
  • *****
  • Posts: 1507
  • I also go by Curt or menturi
Re: Prefix Expression Evaluator
« Reply #6 on: July 03, 2008, 11:41:14 am »
Update:
  • Added min function
  • Added max function

    Date Posted: July 02, 2008, 07:01:35 pm
    Update:
  • Added con operator
  • Added conn operator
  • Back-slashing (backslash) will be a backslash
  • Back-slashing (space) will be a space

Note that now the function restricts the use of character 1 and 2 (well, actually you can still use the, it'll just think they are backslashes or spaces)

Hopefully more string operators and more overall will come soon..
« Last Edit: July 03, 2008, 11:45:04 am by DorkeyDear »