# Integer expression parse

`integer-expression-parse` · version 1.0.0 · Numbers & math · free, no key needed

Parse an integer expression and return its tokens, required variables, precedence tree, and precedence table.

**Use when you need to: parse integer expression without evaluating · show tokens in a bitwise arithmetic formula · find variables needed by an integer expression.**

## Decide before calling

Read the [versioned contract](/v1/tools/integer-expression-parse/versions/1.0.0) and the supported scope below. Reuse `integer-expression-parse@1.0.0` when your input, required output and limits match it. Choose another approach for an unsupported operation.

## Explain the choice

"I can use `integer-expression-parse@1.0.0` for parse integer expression without evaluating. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."

## Supported

- parse integer expression without evaluating
- show tokens in a bitwise arithmetic formula
- find variables needed by an integer expression
- show operator precedence tree for shifts and masks
- validate exact integer expression syntax
- parse hexadecimal binary and octal expression
- inspect floor division and modulo expression
- explain integer expression grouping

## Not supported

- evaluate or substitute variable values
- execute function calls or arbitrary code
- parse decimal or floating-point literals

## Behavior

- Literals are decimal or 0x hexadecimal, 0b binary, or 0o octal integers; names match [A-Za-z_][A-Za-z0-9_]{0,31}. Decimal literals consist of 0 or a nonzero first digit followed by digits. A leading zero followed by another digit (including 00, 012, and 08) is invalid_input; octal uses the explicit 0o prefix.
- Precedence from highest to lowest is parentheses; power ** (right associative); unary - and ~; * / // % rem; + -; << >>; &; ^; |. This follows Python 3.12, except the explicit rem spelling and C division mode.
- Parsing validates syntax only and returns tokens, sorted required variable names, a precedence tree, and the precedence table. It never substitutes variables or evaluates operations.
- Exponent and shift operands may be negative or exceed evaluation limits, and division/remainder operands may be zero. These are valid syntax; evaluation restrictions belong exclusively to integer-expression-evaluate.
- Only input bytes, tokens, operators, depth, literal digits, unique variable names, and serialized output bytes are bounded by this parse-only contract.
- max_input_bytes bounds the UTF-8 byte length of JSON.stringify(input), including keys, punctuation, and every field. Field bounds apply together with this whole-input bound.
- max_expression_bytes bounds only the expression string in UTF-8; variable names and values have their separately declared limits.

## Input

- `expression` (string, required): min length 1; max length 1024; ASCII integer expression; UTF-8 input is capped at 1024 bytes.

## Output

- `standard_version` (constant "Python 3.12 §6.5–6.9; ISO/IEC 9899:2018 §6.5.5", required)
- `tokens` (array of object, required): max items 256
- `variables` (array of string, required): max items 64; each min length 1; each max length 32
- `precedence_tree` (string, required): min length 1; max length 4096
- `precedence` (array of string, required): min items 8; max items 9; each min length 1; each max length 80

## Limits

- max input bytes: 16384
- max tokens: 256
- max operators: 128
- max depth: 32
- max literal digits: 128
- max variables: 64
- max output bytes: 2048
- max expression bytes: 1024

## Example

Request input:

```json
{
  "expression": "base + index * 4"
}
```

Response:

```json
{
  "result": {
    "standard_version": "Python 3.12 §6.5–6.9; ISO/IEC 9899:2018 §6.5.5",
    "tokens": [
      {
        "type": "name",
        "text": "base"
      },
      {
        "type": "operator",
        "text": "+"
      },
      {
        "type": "name",
        "text": "index"
      },
      {
        "type": "operator",
        "text": "*"
      },
      {
        "type": "integer",
        "text": "4"
      }
    ],
    "variables": [
      "base",
      "index"
    ],
    "precedence_tree": "(+ base (* index 4))",
    "precedence": [
      "parentheses",
      "** (right associative)",
      "unary - and ~",
      "* / // % rem",
      "+ -",
      "<< >>",
      "&",
      "^",
      "|"
    ]
  }
}
```

## How to call it

### MCP

Connect `https://computefirst.net/mcp` ([setup](/docs#connect)), then call `execute` with:

```json
{
  "id": "integer-expression-parse",
  "version": "1.0.0",
  "input": {
    "expression": "base + index * 4"
  }
}
```

### HTTP (no key)

```sh
curl -X POST https://computefirst.net/v1/tools/integer-expression-parse/versions/1.0.0/execute \
  -H "Content-Type: application/json" \
  -d '{"expression":"base + index * 4"}'
```

The machine-readable contract is at [/v1/tools/integer-expression-parse/versions/1.0.0](/v1/tools/integer-expression-parse/versions/1.0.0).

### CLI

```sh
node cli.mjs run integer-expression-parse 1.0.0 --input input.json --base-url https://computefirst.net
```

Get the client at [/clients/cli/](/clients/cli/).

## Related tools

- [Integer expression evaluate](/tools/integer-expression-evaluate): Evaluate exact integer arithmetic and return decimal, hexadecimal, and binary results.
- [Rational trace check](/tools/rational-trace-check): Check a step-by-step rational calculation trace; reports the first step whose operand, operator or result disagrees.
- [Linear residual check](/tools/linear-residual-check): Check a claimed residual r = b - A x (per component and/or its max norm) exactly for an approximate solution x.
- [Lp optimality certificate check](/tools/lp-optimality-certificate-check): Check an LP optimum claim from a primal x and dual y: feasibility, complementary slackness and zero duality gap.
- [Number engineering format](/tools/number-engineering-format): Format an exact decimal in scientific or engineering notation with explicit precision and rounding.
- [Chi square decomposition check](/tools/chi-square-decomposition-check): Check a claimed Pearson chi-square, its per-cell (O-E)^2/E terms and df exactly; returns the first wrong term.
