Certainly, here's a simple implementation in Python:
def evaluate_postfix(expression):
stack = []
for token in expression.split():
if token.isdigit():
stack.append(int(token))
else:
operand2 = stack.pop()
operand1 = stack.pop()
if token == '+':
stack.append(operand1 + operand2)
elif token == '-':
stack.append(operand1 - operand2)
elif token == '*':
stack.append(operand1 * operand2)
elif token == '/':
stack.append(operand1 / operand2)
return stack.pop()
# Example usage:
expression = "5 3 4 * + 2 /"
result = evaluate_postfix(expression)
print("Result:", result)
This code evaluates the postfix expression using a stack and supports basic arithmetic operations (+, -, *, /).