Can the shunting-yard algorithm handle logic processing?

AI Thread 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".
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
What percentage of programmers have learned to touch type? Have you? Do you think it's important, not just for programming, but for more-than-casual computer users generally? ChatGPT didn't have much on it ("Research indicates that less than 20% of people can touch type fluently, with many relying on the hunt-and-peck method for typing ."). 'Hunt-and-peck method' made me smile. It added, "For programmers, touch typing is a valuable skill that can enhance speed, accuracy, and focus. While...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...
Back
Top