In this concluding part of the series, I will build an abstract syntax tree or AST. An AST holds the information present in the arithmetic expression and can be evaluated to yield the result. It is built from grammar rules just like the translator in part 2 and evaluated using …
In this part of the series, I will build the calculator as a translator. The translator will evaluate the arithmetic expression according to a set of rules. It will consist of a lexer that will produce a stream of tokens from the input, and a parser that will check the …
The internet abounds with tutorials on programming projects like building
a calculator, for instance. The focus is often on the GUI aspects, ignoring
the complexities of expression evaluation. Mathematical expressions are usually
evaluated by the eval
function. This is not a safe method if arbitrary input
is allowed. In this …
In this post, I am going to tell you about different heap data structures that are common in Computer Science. I will start with the basic heap structure, i.e. the binary heap, and then discuss binomial and Fibonacci heaps. The code for each data structure is in Python. For …
This post adds to the content of the fine article by Real Python titled Understanding the Python traceback. It expands on the topic of chained exceptions and explains what a traceback object is.
First, to repeat for convenience what has been said in that article: when an exception occurs while …
Suppose we want to find permutations of numbers from 1 to n using Python. Easily
done, right ? Just use the standard library function itertools.permutations
to
find the n! number of permutations. But in this post, I am going to illustrate
how you can list them, starting from scratch. I …