in

This site is all about the amazingly cool stuff you can do with VB.NET.

Schizo Developer

Welcome to Schizo Developer!

Mobile Calculator Project

My first project is going to be a calculator for NETCF written in VB.Net.

I hear you saying "It's been done!"....and yer right.

However, not like I want it to work. When I was in college, I had a stack screen calculator ( I suppose most of us did) and I liked it. I like being able to see what terms I used in my calculation. Combined with reverse polish notation, this makes for a powerfully quick calc. I also want it to give me the ability to define reusable global values and perhaps even functions, etc.

So, I have begun first on a generic math parser class. I will make this class compatible with NETCF. Why? Because if I do, it will be very simple to reuse it anywhere I need a math parser.

My first challenge was approach. How does one approach the parsing? For example, if I am looking at an eqn  like:

2+(2*3 +(3+4)) + ((2+5) * 3 + (9*9))

See all those nested parens? Every time I thought about how to approach this, my eyes started crossing....until my eyes cleared and one word appeared before them: recursion!

See, I can process the string one character at a time...I can treat the numbers and operators and when I find an opening parens, I start from the back and find the correct closer...once I do, I sent the entire contents of the parens into a recursive version of the same function, and the process repeats. Once I don't have any more parens, I calculate the values and unwind the stack...

I have the parsing code started, and it does what I want, but I need to get the calculation stuff working....once done, I post an example here.

 

Comments

No Comments
Copyright 2008 - ILoveVB.NET
Powered by Community Server (Commercial Edition), by Telligent Systems