Issue 10 | Phase A: Parallel Development of Computing Engine

⏱ Est. reading time: 4 min Updated on 5/7/2026

app.js (created by logic-dev) β€” Shunting-yard Calculation Engine

// Operator precedence
const PRECEDENCE = {
  '+': 1, '-': 1,
  'Γ—': 2, '*': 2, 'Γ·': 2, '/': 2,
  '%': 3, 'unary-': 4
};

// Lexical analysis
function tokenize(expression) {
  // "1+2*3" β†’ ['1', '+', '2', '*', '3']
}

// Shunting-yard algorithm β†’ RPN
function parseExpression(tokens) {
  // ['1', '+', '2', '*', '3'] β†’ ['1', '2', '3', '*', '+']
}

// RPN evaluation
function evaluate(rpn) {
  // Stack-based evaluation, returns "Error" on division by zero
}

// Real-time preview (incomplete expressions are not calculated)
function previewResult(expression) {
  // Mismatched parentheses β†’ returns ''
  // Ends with an operator β†’ returns ''
}

// Input helpers (pure functions, no DOM dependency)
function appendNumber(current, digit) { /* ... */ }
function appendOperator(current, op) { /* ... */ }
function appendDecimal(current) { /* ... */ }
function toggleSign(current) { /* ... */ }

// DOM binding layer (separated from pure functions)
function initCalculator() {
  initElements();
  loadModePreference();
  bindButtonEvents();
  bindKeyboardEvents();
  bindModeToggle();
  updateDisplay();
}

// Export (Node.js test compatibility)
if (typeof module !== 'undefined' && module.exports) {
  module.exports = { tokenize, parseExpression, evaluate, /* ... */ };
}

Architectural Key: Pure Functions and DOM Separation

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Pure Function Layer (DOM-independent) β”‚
β”‚  tokenize β†’ parseExpression β†’ evaluate  β”‚
β”‚  appendNumber, appendOperator, ...     β”‚
β”‚  βœ… Independently testable (Node.js) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
               β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  DOM Interaction Layer           β”‚
β”‚  initCalculator, handleButtonClick β”‚
β”‚  bindKeyboardEvents, toggleMode    β”‚
β”‚  ⚠️ Requires browser environment for testing β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜