I don't want to include the entirety of my language, but I think the relevant part is:
<expr> ::= <logical> | <comparison> | <constant> | <addition> | <subtraction> | <multiplication> | <division> <logical> ::= <expr> "AND" <expr> | <expr> "OR" <expr> | "NOT" <expr> | "(" <expr> ")" <comparison> ::= <expr> "==" <expr> | <expr> "!=" <expr> | <expr> "<=" <expr> | <expr> ">=" <expr> | <expr> "<" <expr> | <expr> ">" <expr>
What I'm trying to do is turn some code that looks like:
IF @var + 2 == 4 THEN something will happen ELSE something else will happen ENDIF
And turn it into a Syntax tree. The reason I would like a syntax tree is that this is code that's to be run in an interpreter and may need to be run several times throught the program (and @var may be different values each time). The tricksy part for me so far is that this isn't really an interpreter, the code is actually expressing an interactive story, something like Twine.
I've started writing the parser and all is going well until I hit the point of expressions. I've written a shunting yard algorithm before to produce Reverse Polish Notation, and I believe I've managed to have the shunting yard algorithm to output a syntax tree (by popping and pushing nodes onto the output stack instead of just numbers and operators); but I don't really understand how to incorporate the boolean / logical operators.
Is there an algorithm that can handle both purely math expressions like 1+2 as well as my
Do I need to rethink my syntax above?