Debugging Day
-
fixed unary negative operation on a function like
-sqrtin the tokenizer. -
added support for implicit multiplication in the tokenizer (right now only valid for alphabets after numbers like 3x, 25x, etc. and not for alphabet after alphabet like xsin(x), xlog(x), etc.)
-
fixed the decimal point collection in the tokenizer due to the failed test case: -.5
-
Added support for exponents by adding
parse_pow(). -
initially i had simply copied the structure of
parse_addandparse_muland ran the test case but i found out that the result was wrong. My current parsing algorithm has natural left associativity, which is required for other operators but, is wrong for power. Because, 2^3^2 should result in 2^(3^4) and not (2^3)^4, which means i needed right associativity. -
For getting right associativity, i had to make it such that the right term of the node was recursively calling parse_pow(), so that everything after it would get parsed first which would give us right associativity.
Comments 2
Oh cool, so you’re using recursion or are you saving some tokens into stack/FIFO data structure?
i am using recursion. you can see my earlier devlogs for in depth updates on the tokenizer and parser because this is just something i put together quickly as the updates were pretty small. The final objective is to build a AST so i do not need to save the tokens into a different data structure as These nodes are what forms an AST which in itself is a data structure. It is pretty complex tbh (atleast for me) but surprisingly once i understood it, coding it was not a challenge.
Sign in to join the conversation.