2
I’m creating a programming language in C++. I’ve made a simple lexer, which works perfectly for now.
out 5 + 7 * 3
My lexer turns it into:
kw: out
num: 5
op: +
num: 7
op: *
num: 3
nl
Now I need to create an AST (abstract syntax tree), which turns the example into this:
kw out
|
op +
/ \
num 5 op *
/ \
num 7 num 2
But how to make a tree algorithm?
Note Please don’t post a code, it takes all the fun out of it. Instead, tell me the logic of the algorithm.
Although her question is not an exact duplicate of the one she wrote, she is an approximate duplicate. I explain: Your question is different, but the answers you need are all in this other question there (both in the question itself and in the answers).
– Victor Stafusa