See the structure behind the answer
An expression calculator is most useful when it reveals what the parser saw. This page turns one basic arithmetic line into a token table and a tree. It is not the running scratchpad: there is no tape, keypad state, memory register, or chained continuation.
Type an expression, choose the trace detail, and decide whether the documented postfix percent token is allowed. The browser tokenizer records each token’s source span. The recursive-descent parser builds explicit nodes, then the rational engine evaluates that tree.
Read the token table
A token has a type, normalized lexeme, start index, and end index. Digits and one decimal point form a Number token. Keyboard * and / normalize to Multiply and Divide while retaining the original source span. Parentheses remain OpenGroup and CloseGroup. A leading or operator-following minus is interpreted by the parser as Negate rather than by the tokenizer as part of a number.
Whitespace is skipped but still counts toward source positions. This means an error highlight points to the characters the user actually typed. Unknown letters, commas, units, currency signs, and extra decimal points stop tokenization at the first unsupported span.
Tokens only is a compact syntax check. Compact tree shows the root and important children. Full tree exposes every node with indentation and source range. The tree is text, not a draggable diagram.
Worked example: multiplication under addition
Enter 3 + 4 × (2 - 0.5) and choose Full tree. The token table contains Number 3, Add, Number 4, Multiply, OpenGroup, Number 2, Subtract, Number 0.5, and CloseGroup.
The root is Add. Its left child is Number 3. Its right child is Multiply, whose left child is Number 4 and whose right child is a Group containing Subtract. Evaluation begins inside the group: 2 - 0.5 = 1.5. Multiplication yields 4 × 1.5 = 6. The root addition yields 3 + 6 = 9.
The result card reports exact 9/1, displayed 9, maximum group depth 1, and the node count. Copy tree summary produces a plain-text outline, not executable code.
Distinguish unary minus from subtraction
In -4 + 2, the first minus begins a Negate node over Number 4. In 7 - 4, the minus becomes the binary Subtract root or child with two operands. In 3 × -2, Negate is allowed after the multiplication operator. This explicit structure prevents a sign from being hidden inside string replacement.
The negative-number calculator is better when the goal is to understand signed movement between two values. This page focuses on syntax roles and tree shape.
Percent as a selectable grammar feature
With percent allowed, 25% becomes a Percent node over Number 25 and evaluates to 1/4. The tree for 80 × 25% makes the multiplication and postfix conversion separate. With percent rejected, the same source returns a highlighted disallowed-token error.
The setting supports instruction and debugging; it does not change the global product convention. Percent never means remainder here, and it never applies a contextual increase automatically.
Locate the first structural error
For 4 + (3 × ), tokenization succeeds, but the parser reaches CloseGroup where it expects a number, unary minus, or opening group. The first error span covers the closing parenthesis and names the expected primary.
For 2(3 + 1), the parser finishes Number 2 and then finds OpenGroup where a binary operator is required. It reports implicit multiplication as unsupported. For (2 + 3, the end-of-input span indicates a missing closing parenthesis.
Only the first error is authoritative. Later characters may create secondary problems, so the page asks the user to fix and parse again rather than flooding the result with guesses.
Evaluation and size limits
The tree evaluator uses reduced BigInt rational values. Division by zero is a calculation-domain error attached to the Divide node, not a token error. Non-terminating decimals retain the exact fraction and use the 12-place display rule.
Character, token, group-depth, node, and integer-size limits keep a malicious or accidental expression from monopolizing the browser. Reaching a limit returns its name and source boundary; the site never truncates the tree silently.
Token and node counts are review aids, not difficulty scores. A longer valid tree can be clearer than a short ambiguous source when explicit groups preserve the intended structure.
Expression questions
Is the parse tree JavaScript code?
No. It is a closed arithmetic node model and is never executed by eval or Function.
Why are spaces included in error positions?
Positions refer to the original source so the highlight matches the user’s text.
Can I edit a tree node directly?
No. Edit the source expression and parse again.
Does Full tree save more history?
No. Trace detail changes current output only; refresh clears everything.
Enter the source and select Parse the expression tree. Compare tokens, spans, root operation, groups, and exact result. Fix the first highlighted error before relying on any later interpretation.
