2 added 10 characters in body edited Jul 6 '18 at 21:24 Peeyush Kushwaha 59622 silver badges1111 bronze badges As it stands, the grammar you've specified is an ambiguous grammar. i.e. something like ``````a AND b OR c `````` could have two parse trees, depending on how you parenthesize. The role of Shunting-yard algorithm is to remove this ambiguity. If you specify operator precedence, it gives you a unique parenthesization for your expression. So yes, while it does give you an AST for your expression, it's not really meant for parsing. Why I say this is because if you have a proper parse tree, then every node would have an associated nonterminal (i.e. ``, ``, etc). Whereas Shunting-yard, in essence, treats each expression to be of the same kind. So if you were to use it, it would recognize this grammar: `````` ::= "AND" | "OR" | "NOT" | "==" | "!=" | "<=" | ">=" | "<" | ">" | "(" ")" | | | | | `````` But the thing is, you don't make a distinction between expression that evaluate to a numeric value vs expressions which evaluate to a boolean value in your productions. Yet, you're using different nonterminals for logical expressions and other expressions. That is to say, your grammar – in its current form – accepts `( 1 + 2 ) AND @x`, and `( 1 == 2) >= 3` as valid. So you might as well define your grammar to be the above grammar. And then you can incorporate it into Shunting-yard algorithm as suggested by amon in comments - by assigning precedence to the logical and relational operators. You could use C++ Operator Precedence as a reference when assigning precedence to your logical and relational operators. As it stands, the grammar you've specified is an ambiguous grammar. i.e. something like ``````a AND b OR c `````` could have two parse trees, depending on how you parenthesize. The role of Shunting-yard algorithm is to remove this ambiguity. If you specify operator precedence, it gives you a unique parenthesization for your expression. So yes, while it does give you an AST for your expression, it's not really meant for parsing. Why I say this is because if you have a proper parse tree, then every node would have an associated nonterminal (i.e. ``, ``, etc). Shunting-yard, in essence, treats each expression to be of the same kind. So if you were to use it, it would recognize this grammar: `````` ::= "AND" | "OR" | "NOT" | "==" | "!=" | "<=" | ">=" | "<" | ">" | "(" ")" | | | | | `````` But the thing is, you don't make a distinction between expression that evaluate to a numeric value vs expressions which evaluate to a boolean value in your productions. Yet, you're using different nonterminals for logical expressions and other expressions. That is to say, your grammar – in its current form – accepts `( 1 + 2 ) AND @x`, and `( 1 == 2) >= 3` as valid. So you might as well define your grammar to be the above grammar. And then you can incorporate it into Shunting-yard algorithm as suggested by amon in comments - by assigning precedence to the logical and relational operators. You could use C++ Operator Precedence as a reference when assigning precedence to your logical and relational operators. As it stands, the grammar you've specified is an ambiguous grammar. i.e. something like ``````a AND b OR c `````` could have two parse trees, depending on how you parenthesize. The role of Shunting-yard algorithm is to remove this ambiguity. If you specify operator precedence, it gives you a unique parenthesization for your expression. So yes, while it does give you an AST for your expression, it's not really meant for parsing. Why I say this is because if you have a proper parse tree, then every node would have an associated nonterminal (i.e. ``, ``, etc). Whereas Shunting-yard, in essence, treats each expression to be of the same kind. So if you were to use it, it would recognize this grammar: `````` ::= "AND" | "OR" | "NOT" | "==" | "!=" | "<=" | ">=" | "<" | ">" | "(" ")" | | | | | `````` But the thing is, you don't make a distinction between expression that evaluate to a numeric value vs expressions which evaluate to a boolean value in your productions. Yet, you're using different nonterminals for logical expressions and other expressions. That is to say, your grammar – in its current form – accepts `( 1 + 2 ) AND @x`, and `( 1 == 2) >= 3` as valid. So you might as well define your grammar to be the above grammar. And then you can incorporate it into Shunting-yard algorithm as suggested by amon in comments - by assigning precedence to the logical and relational operators. You could use C++ Operator Precedence as a reference when assigning precedence to your logical and relational operators. 1 answered Jul 6 '18 at 21:10 Peeyush Kushwaha 59622 silver badges1111 bronze badges As it stands, the grammar you've specified is an ambiguous grammar. i.e. something like ``````a AND b OR c `````` could have two parse trees, depending on how you parenthesize. The role of Shunting-yard algorithm is to remove this ambiguity. If you specify operator precedence, it gives you a unique parenthesization for your expression. So yes, while it does give you an AST for your expression, it's not really meant for parsing. Why I say this is because if you have a proper parse tree, then every node would have an associated nonterminal (i.e. ``, ``, etc). Shunting-yard, in essence, treats each expression to be of the same kind. So if you were to use it, it would recognize this grammar: `````` ::= "AND" | "OR" | "NOT" | "==" | "!=" | "<=" | ">=" | "<" | ">" | "(" ")" | | | | | `````` But the thing is, you don't make a distinction between expression that evaluate to a numeric value vs expressions which evaluate to a boolean value in your productions. Yet, you're using different nonterminals for logical expressions and other expressions. That is to say, your grammar – in its current form – accepts `( 1 + 2 ) AND @x`, and `( 1 == 2) >= 3` as valid. So you might as well define your grammar to be the above grammar. And then you can incorporate it into Shunting-yard algorithm as suggested by amon in comments - by assigning precedence to the logical and relational operators. You could use C++ Operator Precedence as a reference when assigning precedence to your logical and relational operators.