Can the shunting-yard algorithm handle logic processing?

Click For Summary
SUMMARY

The shunting-yard algorithm can effectively handle logic processing by treating boolean operators similarly to arithmetic operators, where 1 represents true and 0 represents false. In programming languages like C and C++, binary operators such as addition, multiplication, and logical operators can be utilized in conjunction with the shunting-yard algorithm. However, the implementation of this algorithm may vary based on compiler optimizations, which can influence whether the algorithm is employed in processing infix expressions. Proper operator precedence must be established for accurate logic evaluation.

PREREQUISITES
  • Understanding of the shunting-yard algorithm
  • Familiarity with binary operators in C and C++
  • Knowledge of operator precedence and associativity
  • Basic concepts of boolean logic and its representation in programming
NEXT STEPS
  • Research the implementation of the shunting-yard algorithm in C++
  • Explore custom operator overloading in C++
  • Learn about compiler optimizations and their impact on algorithm choice
  • Study boolean algebra and its application in programming logic
USEFUL FOR

Software developers, particularly those working with C and C++, computer science students, and anyone interested in algorithm design and logic processing.

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   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".
 

Similar threads

Replies
19
Views
2K
  • · Replies 13 ·
Replies
13
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
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 6 ·
Replies
6
Views
1K