I have a problem similar to this:
How to print a tree structure into a string fast in Ocaml?
But in an opposite way, that I already have a string and want to parse it back to be a tree.
For example, I have
type expr =
Number of int
|Plus of expr*expr
|Prod of expr*expr
and I have a string like 1+2*3+4 (a little different from the link above, assume *
has higher procedence than +
)
Then I want my result to be a expr type Prod(Plus(1,2), Plus(3, 4))
I found another link that might talk about this, but not sure if it's a way of doing my problem:
Please share some ideas, thank you.