Skip to content

JxD8y/PrattCalc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PrattCalc - (A visulizer for Pratt parsing algorithm)

Pratt parsing is the algorithm used to calculate expressions like: 5*2-4+(20-1), This expressions cannot be calculated in linear way because each operator has its own precedence some higher and some lower; the way to parse it correctly is the Pratt parsing algorithm.

In this algorithm we first tokenize the whole expression then assign each operator its own Binding Power (more like a measure to its precedence higher means it has more precedence) then we use a recursive behaviour to create a binary tree of the expression after that we use a solver function to calculate the generated tree to gain the answer of the expression.

Power of this algorithm unfold when you find out that you can create your own operand precedence (BP) or introduce your own operands to calculate your own custom expressions.

I used this article to implement my own C++ version and then created a nice UI to represent how the final parsed expression looks like with binary tree.

Screenshots

3 3 3

Notes

I configured the ImGui in a single source file to use Dx11 which make the whole software be bound to windows OS. so to build it all you need to do is either clone the repo and used visual studio or use :

cmake .
cmake --build .

Contact

You can send me message in telegram: @KVMSwitch