liveBook · Manning

Arithmetic operator

As explained in Building User-Friendly DSLs

An operator that performs a numerical arithmetic calculation such as multiplication, division, addition, or subtraction.

An arithmetic operator performs a numerical calculation such as addition, subtraction, multiplication, or division. Its role becomes precise when expressions are evaluated according to the order of operations. section 12.1

Evaluate arithmetic expressions by applying these rules:

  • Evaluate parenthesized subexpressions first. section 12.1
  • Then evaluate exponentiation, multiplication and division, and addition and subtraction in that order. section 12.1
  • Replace each completed subexpression with its numerical result and continue recursively. section 12.1

Operator precedence in practice

The expression 1 + 2 * 3 evaluates multiplication before addition, producing 7. In 1 + 2 * (3 + 4), the parenthesized expression is evaluated first, producing 15 overall. section 12.1

Figure 12.1 Evaluation of 1 + 2 * 3 according to the PEMDAS rule
figure

Trace how 1 + 2 * 3 is evaluated according to PEMDAS. section 12.1

How Building User-Friendly DSLs covers it

How deep it goes
Explains recursive evaluation, parentheses, precedence, and AST construction, stopping short of broader operator semantics.
Examples
Uses 1 + 2 * 3 and 1 + 2 * (3 + 4) to demonstrate precedence and parentheses.
What you can do after
Evaluate arithmetic expressions recursively and represent their evaluation order with ASTs.
How it connects
Connects arithmetic operators with order of operations, expressions, recursion, and abstract syntax trees.

Also explained in

Compare how 2 books explain arithmetic operator →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Building User-Friendly DSLs. The section links point to the parts of the book it draws on.