Awesome! Coincidently I have begun a similar personal project - a CYK parser - just five days ago. It can currently parse nondeterministic context free languages which includes most programming languages but I have encountered the exact same problem of operator precedence and operator associativity, which is one point I'm currently trying to resolve.
My plan is to solve these issues by performing rebalancing and sift down operations directly on the AST.
As I have done some research on operator precedence parsing, I have found another way which is absolutely trivial to implement:
Just put a (( at the beginning of the equation, a )) at the end and replace every + with a ))+(( and every * with a )*(. By doing this your expression is correctly parenthesized without any complicated algorithms. (Found it on Wikipedia)
Awesome! Coincidently I have begun a similar personal project - a CYK parser - just five days ago. It can currently parse nondeterministic context free languages which includes most programming languages but I have encountered the exact same problem of operator precedence and operator associativity, which is one point I'm currently trying to resolve.
My plan is to solve these issues by performing rebalancing and sift down operations directly on the AST.
I have also made the project available on GitHub if you're interested.
Awesome. CYK parsing is a term I have run across, but I am not familiar with how they work. You should write an article on it!
As I have done some research on operator precedence parsing, I have found another way which is absolutely trivial to implement:
Just put a (( at the beginning of the equation, a )) at the end and replace every + with a ))+(( and every * with a )*(. By doing this your expression is correctly parenthesized without any complicated algorithms. (Found it on Wikipedia)
I have exams at the moment but if I have some time, I will do that.