Can the shunting-yard algorithm handle logic processing?

Click For Summary
Logic processing can utilize binary values, where 1 represents true and 0 represents false, allowing for arithmetic operations to be applied to logical operations. For instance, an "OR" operation can be executed using addition, while an "AND" operation can be performed through multiplication. The shunting yard algorithm is questioned for its ability to manage sequences of logical operations, with an emphasis on the necessity of setting operator precedence correctly. The discussion highlights that boolean and arithmetic operators can be treated similarly, as both can be processed in stack-based systems, a practice established for decades. In programming languages like C and C++, binary operators encompass arithmetic, relational, logical, and bitwise operations, all of which return results based on two input values. Additionally, C++ allows for the creation of custom operand types, enabling the redefinition of operator functions. However, the implementation of infix code in C++ is determined by the compiler, which may prioritize optimization over the use of the shunting yard algorithm.
synch
Messages
84
Reaction score
11
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..
 
Technology 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.
 
  • Like
Likes 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".
 

Similar threads

Replies
19
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
1K
Replies
29
Views
5K
  • · Replies 11 ·
Replies
11
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 31 ·
2
Replies
31
Views
7K
  • · Replies 23 ·
Replies
23
Views
3K
Replies
5
Views
2K
  • · Replies 5 ·
Replies
5
Views
4K