diff --git a/src/App.tsx b/src/App.tsx index 9ac24e5..38afdb7 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -23,6 +23,7 @@ export default function App() { onChange={(e: any) => setInput(e.target.value)} value={input} className="program" + spellCheck="false" title={`\ type Op = | number @@ -168,7 +169,6 @@ function Stack({ }): JSX.Element { let ns = [...state.stack]; ns.reverse(); - console.log(just_popped); let children = (just_popped ?? []).map((just_popped, i) => ( state.stack.length) { ns.just_pushed = true; } else if (ns.stack.length < state.stack.length) { - ns.just_popped = state.stack.slice(ns.stack.length - 1).reverse(); - if (state.stack.length - ns.stack.length == 1) { + if (is_binary(op)) { + ns.just_popped = state.stack.slice(-2).reverse(); ns.just_pushed = true; + } else { + ns.just_popped = [state.stack[state.stack.length - 1]]; } } return ns; } +function is_binary(op: Op): op is "add" | "sub" | "div" | "mul" | "cmp" { + return ["add", "sub", "div", "mul", "cmp"].indexOf(`${op}`) >= 0; +} + function cmp(a: number, b: number): number { if (a < b) { return -1;