Dex-TS
PART I - Intro & TOC
| << Previous | Main | Next >> |
Dex-TS
About
Dex-TS is an open-source Tri-Stack Calculator (math expression parser) written in C++ using STL with good OOP design patterns. It is the official successor to C-Flat. Dex-TS has been rewritten from scratch and is now a distributable DLL. I am releasing it in response to UCALC and USPExpress, two excellent pieces of code that have unfortunately gone commercial.
System Requirements
Download
If your system meets the requirements stated above, you may download Dex-TS here (with source).
(note: this program is provided AS IS without warranty of any kind.. etc etc)
Algorithm
This example demonstrates the basics of Tri-Stack. The three stacks (opStack, elemStack, and inStack) are denoted here as [O], [E], and [I]. A sequence of pushes and pops computes the solution.
"1 * 2 + 3"
Step 1 (Format)
Add parenthesis around expression.
- "(1 * 2 + 3)"
Step 2 (Group)
Group tokens into operators and operands.
- [O]: ( * + )
- [E]: 1 2 3
- [I]:
Force top-most opStack operator into inStack (to start chain reaction).
- [O]: ( * +
- [E]: 1 2 3
- [I]: )
Step 3 (Load)
Load inStack with opStack, elemStack elements
(stop when inStack top-most operator ranks higher than opStack top-most operator)
- [O]: (
- [E]: 1
- [I]: ) 3 + 2 *
Step 5 (Bind)
Force inStack top-most operator into opStack.
- [O]: ( *
- [E]: 1
- [I]: ) 3 + 2
Bind elemStack, inStack operands with an opStack operator (push result back into inStack).
1 * 2 = 2
- [O]: ( *
- [E]: 1
- [I]: ) 3 + 2
2 + 3 = 5
- [O]: ( +
- [E]: 2
- [I]: ) 3
Remove extra parenthesis in opStack, inStack.
- [O]: (
- [E]: 5
- [I]: )
Return remaining elemStack operand if inStack empty, goto Step 3 if otherwise.
- [O]:
- [E]: 5
- [I]:
Table of Contents
| << Previous | Main | Next >> |
Next: EOF (aka no more)