Can the shunting-yard algorithm handle logic processing?

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
2 replies · 3K views
synch
Messages
86
Reaction score
12
Looking at logic processing with 1 meaning true and 0 meaning false..an "OR" could be implemented using an addition operation , an "AND" using multiplication, and so on. I am wondering if the shunting yard algorithm would handle the sequences of logic based operations ? The precedence of the operators would have to be set appropriately of course..
 
Physics news on Phys.org
The boolean operators are just like the arithmetic operators.
No distinction need be made between boolean or arithmetic operators.
They can all be processed in a stack based processor, and have been for the last 70 years.
 
Reply
  • Like
Likes   Reactions: QuarkyMeson
synch said:
Looking at logic processing with 1 meaning true and 0 meaning false..an "OR" could be implemented using an addition operation , an "AND" using multiplication, and so on. I am wondering if the shunting yard algorithm would handle the sequences of logic based operations ? The precedence of the operators would have to be set appropriately of course..
In the computer languages C and C++, "binary operators" take two values and return a result. So, they are the kind of operators you are asking about. The binary operators supported by C and C++ include:
Arithmetic operators:
addition(+), subtraction(-), multiplication(*), division(/), modulos(%)
Relational operators (return true of false): <, >, <=, >=, ==, !=
Logical operators: and(&&), or(||)
Bitwise operators: and(&), or(|), exclusive or(^), left shift(<<) and right shift(>>)

Not only that, but in C++ you can create your own operand types and redefine what all of those operators do.

As for the "shunting yard" algorithm, the C++ compiler gets to decide how your infix code is implemented. Since the compiler will be looking for optimization opportunities and to make best use of the computers registers, it may not use "shunting yard".