Operator output queue
Convert infix tokens to postfix without losing precedence or associativity.
Adult planning suggestion: about 9–12 · Language & storytelling
- Players
- 2–3 per group
- Time
- 15–25 minutes
- Materials
- Digit/operator cards, an output row and operator-stack strip.
Prepare
Use single-digit operands, binary +,−,× and balanced parentheses only. Multiplication outranks addition/subtraction; all three operators associate left. Output starts empty; the operator stack is separate from the later value-evaluation stack.
Follow the rule
Read left to right. Send a digit to output. Push an opening parenthesis. Before pushing an operator, pop operators of equal or higher precedence to output until the top is an opening parenthesis or the stack is empty. For a closing parenthesis, pop to output through the matching opening parenthesis, then discard that opening mark.
Check each step
At the end pop remaining operators to output; unmatched parentheses invalidate the input. Parentheses never appear in postfix output. Conversion of 2+3×4 gives 2 3 4 × +, whereas (2+3)×4 gives 2 3 + 4 ×. Preserve each digit's order.
Worked example
For 8−3−1 the equal-precedence pop rule gives 8 3 − 1 −, evaluating to 4. The sequence 8 3 1 − − evaluates to 6 and represents a different grouping. Do not silently treat binary subtraction as right-associative or introduce unary minus into this starter.
Finish and adapt
Ten trios rotate reader, operator keeper and output auditor. After conversion, use the related postfix-value activity to check the result as a separate stage. Finish with the token log and a matching value, not a claimed general parser for variables, exponents or arbitrary malformed input.
Purpose, observation and provenance
Within this activity: Convert infix tokens to postfix without losing precedence or associativity.
Ask why an equal-precedence subtraction is popped before the next one is pushed.
Our rules, examples and printable diagrams are separately prepared. The earliest inventor of the broader mechanism is not established here.
CP Algorithms — Expression parsing — Operator precedence and left-associative stack handling are background; our card protocol outputs postfix rather than evaluating during conversion.
Secondary practice: Cooperation and explaining a check.
For a class of 30, use ten groups of three. Prepare one player-material set per group and keep the host key with the adult. Rotate operator, recorder and checker after each worked example; a reader or scribe may help without choosing answers. Avoid public ranking or diagnostic labels.
Age bands are planning suggestions. Background references may address older learners and do not validate suitability for this age band. Goals describe observable actions, not measured long-term gains or institutional endorsement.
Free alternative: Copy the supplied grids, labels and cards onto reused paper. No specialist product is needed. Adults may prepare pieces or act as a scribe.
Printable materials
Preview at 100% scale, with browser headers and footers off. Cut with suitable help. Keep host keys separate. This is a manual tabletop kit, not an online opponent, automatic judge or solver.
Operator output queue · Player materials
Before you start
Use single-digit operands, binary +,−,× and balanced parentheses only. Multiplication outranks addition/subtraction; all three operators associate left. Output starts empty; the operator stack is separate from the later value-evaluation stack.
Read left to right. Send a digit to output. Push an opening parenthesis. Before pushing an operator, pop operators of equal or higher precedence to output until the top is an opening parenthesis or the stack is empty. For a closing parenthesis, pop to output through the matching opening parenthesis, then discard that opening mark.
After the final input token, pop all remaining operators to output. Unmatched parentheses invalidate the input. Parentheses themselves are never output. Audit conversion first, then evaluate the postfix as a separate task.
| Infix | Postfix |
|---|---|
| 2+3×4 | |
| (2+3)×4 | |
| 8−3−1 |
| Token | Operator stack | Output so far |
|---|---|---|
| ________ | ________ | ________ |
| ________ | ________ | ________ |
| ________ | ________ | ________ |
| ________ | ________ | ________ |
| ________ | ________ | ________ |
| ________ | ________ | ________ |
Operator output queue · Host key — keep separate
2+3×4→2 3 4 × + =14; (2+3)×4→2 3 + 4 × =20; 8−3−1→8 3 − 1 − =4.
Run and audit
Use single-digit operands, binary +,−,× and balanced parentheses only. Multiplication outranks addition/subtraction; all three operators associate left. Output starts empty; the operator stack is separate from the later value-evaluation stack.
Read left to right. Send a digit to output. Push an opening parenthesis. Before pushing an operator, pop operators of equal or higher precedence to output until the top is an opening parenthesis or the stack is empty. For a closing parenthesis, pop to output through the matching opening parenthesis, then discard that opening mark.
At the end pop remaining operators to output; unmatched parentheses invalidate the input. Parentheses never appear in postfix output. Conversion of 2+3×4 gives 2 3 4 × +, whereas (2+3)×4 gives 2 3 + 4 ×. Preserve each digit's order.
For 8−3−1 the equal-precedence pop rule gives 8 3 − 1 −, evaluating to 4. The sequence 8 3 1 − − evaluates to 6 and represents a different grouping. Do not silently treat binary subtraction as right-associative or introduce unary minus into this starter.
Ten trios rotate reader, operator keeper and output auditor. After conversion, use the related postfix-value activity to check the result as a separate stage. Finish with the token log and a matching value, not a claimed general parser for variables, exponents or arbitrary malformed input.
Observe and support
Ask why an equal-precedence subtraction is popped before the next one is pushed.
Use large paper marks or a scribe when needed. A valid example is not a uniqueness or long-term learning claim.