AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Calculator (https://forums.alliedmods.net/showthread.php?t=317672)

Natsheh 07-23-2019 17:49

Calculator
 
I'm trying to make a calculator that only support multipling , adding and subtraction with a specified synax

Synax will look alike the following :-

{ 5.0 + { { 5 * 5 } - { 3 * 4 } } }

Regex pattren : "^^.*\{.*\d+(?:.*\..*\d*).*[*+-].*\d+(?:.*\..*\d*).*\}.*$"

Now i'm real confused on how to turn that string (equation) to an answer.

klippy 07-23-2019 19:04

Re: Calculator
 
Look into Shunting-yard algorithm and Postfix/Reverse Polish notation, that should help you.

Natsheh 08-04-2019 17:11

Re: Calculator
 
Solved using regex

Fixed pattren : "^^.*(\{ *(\d+(?: *\. *\d* *| *))([\*\+\-]) *(\d+(?: *\. *\d* *| *))\}).*$"

Seems like I was missing brackets for string parsing.


All times are GMT -4. The time now is 17:29.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.