Parser: add missing prefix operators (+ and \) to complete the prefix table #28

Closed
opened 2026-06-02 20:03:39 +00:00 by navicore · 1 comment
Owner

Summary

The prefix-operator table is incomplete. - (fy 200) and \+ (fy 900) read
as prefix operators, but the other standard symbolic prefix operators do not:

functor(- a,  N, A).   % OK  -> N = (-),  A = 1
functor(\+ a, N, A).   % OK  -> N = (\+), A = 1
functor(+ a,  N, A).   % Parse error: unexpected `+`
functor(\ a,  N, A).   % Parse error: Unexpected character '\'

Standard prefix operators missing

  • + (fy, 200) — unary plus
  • \ (fy, 200) — bitwise complement

(The ISO declaration-class prefixes — dynamic, discontiguous,
initialization, multifile, … at fx 1150 — are a separate, lower-priority
concern; this issue is about the arithmetic/symbolic prefixes.)

Notes for implementation

  • Prefix handling lives in parse_primary (crates/patch-prolog-core/src/parser.rs).
  • \ is not tokenized as a standalone token today (it only appears inside
    \+, \=, \==, =\=), so unary \ needs a tokenizer change as well.
  • Watch the numeric-literal interaction: -3 already folds to a negative
    number rather than the compound -(3). + 3 should evaluate to 3; keep
    the folding behavior consistent and documented.

Context

Found while building the loglings operator lessons (prefix-vs-infix notation).
Related: the infix table is also incomplete (** ^ >> << xor div :) — tracked
separately.


Reported against prlg 0.4.1.

## Summary The prefix-operator table is incomplete. `-` (fy 200) and `\+` (fy 900) read as prefix operators, but the other standard symbolic prefix operators do not: ```prolog functor(- a, N, A). % OK -> N = (-), A = 1 functor(\+ a, N, A). % OK -> N = (\+), A = 1 functor(+ a, N, A). % Parse error: unexpected `+` functor(\ a, N, A). % Parse error: Unexpected character '\' ``` ## Standard prefix operators missing - `+` (fy, 200) — unary plus - `\` (fy, 200) — bitwise complement (The ISO declaration-class prefixes — `dynamic`, `discontiguous`, `initialization`, `multifile`, … at fx 1150 — are a separate, lower-priority concern; this issue is about the arithmetic/symbolic prefixes.) ## Notes for implementation - Prefix handling lives in `parse_primary` (`crates/patch-prolog-core/src/parser.rs`). - `\` is not tokenized as a standalone token today (it only appears inside `\+`, `\=`, `\==`, `=\=`), so unary `\` needs a tokenizer change as well. - Watch the numeric-literal interaction: `-3` already folds to a negative number rather than the compound `-(3)`. `+ 3` should evaluate to `3`; keep the folding behavior consistent and documented. ## Context Found while building the `loglings` operator lessons (prefix-vs-infix notation). Related: the infix table is also incomplete (`** ^ >> << xor div :`) — tracked separately. --- Reported against `prlg` 0.4.1.
Author
Owner

#32

https://git.navicore.tech/navicore/patch-prolog/pulls/32
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
navicore/patch-prolog#28
No description provided.