Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Code Snippets / [DBPro] - Maths Parser

Author
Message
Zotoaster
19
Years of Service
User Offline
Joined: 20th Dec 2004
Location: Scotland
Posted: 27th Jan 2007 11:31 Edited at: 27th Jan 2007 12:41
This is a maths parser I've been making for the development of my revolutionary "programming language" . Anyhow, I made a similar one before (which I didn't post), but this one is just a test really so it can work with some built in functions. These are:
-Sin
-Cos
-Tan
-ASin
-ACos
-ATan
-Sqrt

All you do is call cmSolveExp(exp$), and it will return the expression as a string, the reason for that is because this programming language doesn't have any data types.



There are still a bug or two. I need to work on the cmSolveExpS() function (which solves simple things without brackets). Unfortunatelly, it wont solve "-30*2" properly, it will return 60. The reason for that is because it doesn't treat the first number as -30, but instead it loops through, finds a minus, then a 30. Also, "1--1" will return 0. Not 1. I have to fix that function up, but it's a small function, so fixing it shouldn't affect the rest.


-Here's the basics of how it works for those who want to know:
If the expression is "sin(45*(20/10))", then how would you solve it?
Well, basically, it finds the inner-most nest, in this case, "(20/10)", and it solves that on it's own, then substitutes it into the function and returns it, so then you end up with: "sin(45*2)", it then repeats that process again. So then, you get the innermost nest, being "(45*2)" and solves it, you then end up with "sin(90)". Everytime it checks the innet nest, it checks the token just before it. If it's a function, in this case, sin, all it does it replace the old answer, with the sin of it, so now, you end up with "1"!

Enjoy

Login to post a reply

Server time is: 2024-11-23 00:05:09
Your offset time is: 2024-11-23 00:05:09