Skip to content

Write down what the grammar accepts, and correct three statements that were not true (#746 items 8, 74) - #1041

Merged
Rafael-SOWNet merged 1 commit into
masterfrom
docs/syntax-corrections-and-gaps
Aug 23, 2026
Merged

Rafael-SOWNet merged 1 commit into
masterfrom
docs/syntax-corrections-and-gaps

Conversation

@Rafael-SOWNet

Copy link
Copy Markdown
Member

Docs/Usage/Syntax.md is the only statement of this language other than the grammar itself, so what it omits is undiscoverable and what it gets wrong is worse than nothing. #746 item 8 asks for the omissions and item 74 for the wrong statements.

How the list was derived

Not taken from the roadmap's count. Every function-open literal in Sources/AngouriMath/Core/Antlr/AngouriMath.g — 102 of them — checked by name against the page, plus the non-function productions of atom, the lexer rules (NUMBER, BOOLEAN, VARIABLE, COMMENT, NEWLINE) and the token insertion in Core/Parser.cs. That left 20 function names and 15 features undocumented.

Added

sum, product the operators that declare a name over a range — the headline of item 8
exp, log10, log2 and log with one argument, which is base 10
inverse hyperbolics the a- spellings of all six, and the five refusals beyond arcsinh
(|x|) absolute-value brackets
True, False which is what Stringize prints
//, /* */, newlines skipped by the lexer
.5, 1., 3i, 1.5e3i number literal forms
ExplicitParsingOnly the setting that turns implicit operators off
Cyrillic a letter in a name, as much as Greek

sum and product get their own section, since getting the argument order wrong is the difference between 55 and something else, and since the declared name shadows what it would otherwise mean: sum(i, i, 1, 10) is 55, sum(sqrt(-1) * i, i, 1, 10) is 55i, product(pi, pi, 1, 4) is 24, and a name that outlives its operator comes back as pi_1.

Corrected

The variable-name rule, which said "a letter or _ followed by letters, digits or _". The grammar is letter+ ('_' (letter|digit)+)? and disagrees four ways:

"_x".ToEntity();     // lexer error -- a name cannot begin with _
"x_".ToEntity();     // lexer error -- nor end with one
"x_1_2".ToEntity();  // lexer error -- at most one _ (#524)
"x1".ToEntity();     // x ^ 1, not a name: a digit is not a letter
"альфа".ToEntity();  // a name -- Cyrillic, which the page did not mention

sinx is s * i * n * x — a third wrong statement, not in the roadmap's count. It is false: the lexer takes the longest match, so sinx is one variable named sinx. Nothing in this language produces a product of one-letter names.

"Juxtaposition is multiplication" is half of it, and the missing half is the surprising one. A number, name or ) followed by a number inserts ^:

"x2".ToEntity();   // x ^ 2
"x(2)".ToEntity(); // x * 2
"x i".ToEntity();  // x ^ i  -- i is a number token
"3 2".ToEntity();  // 3 ^ 2

Already fixed, so left alone: item 74's other statement — everything but ^ groups to the left — was corrected by #1009 when the printer was fixed. The roadmap entry predates that merge.

Recorded rather than fixed

Measured

Sources/Tests/UnitTests/Convenience/SyntaxDocumentedTest.cs runs every example the page prints — the precedence table row by row against explicitly bracketed forms, the four shapes that are not names, both juxtaposition rules, ExplicitParsingOnly, the number and boolean spellings, comments, the inverse hyperbolic table, and sum/product including what the declared name shadows. It compares entities, never printed forms.

7930 passed, 0 failed, 14 skipped   (7825 / 0 / 14 before; the 105 are this file)

No library code is touched, so no answer changes and BREAKING-CHANGES.md is owed nothing. The new test file carries the default 2019-2022 header — Sources/.editorconfig pins it and belongs to other pull requests this cycle, so no 2026 scope was added there.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Bjumi5K7fg8yx6UK1mZTQd

…t say (#746 items 8, 74)

Syntax.md is the only statement of the language other than the grammar itself, so what it
leaves out is undiscoverable and what it gets wrong is worse than nothing.

Derived rather than taken from a list: every function-open literal in AngouriMath.g -- 102
of them -- checked against the page, plus the non-function productions of `atom`, the lexer
rules, and the token insertion in Core/Parser.cs. Twenty function names and fifteen features
were missing.

Added:

  sum and product, the operators that declare a name over a range, with what the declared
    name shadows: `sum(i, i, 1, 10)` is 55 while `sum(sqrt(-1) * i, i, 1, 10)` is 55i, and
    `product(pi, pi, 1, 4)` is 24
  exp, log10, log2, and log with one argument, which is base 10
  the a- spellings of every inverse hyperbolic and the five refusals beyond arcsinh
  (|x|), the absolute-value brackets
  True and False, which is what Stringize prints
  // and /* */ comments, and newlines, which are skipped
  .5, 1., and the imaginary suffix in 3i and 1.5e3i
  MathS.Settings.ExplicitParsingOnly
  Cyrillic letters in names, where only Greek was named

Corrected, each with the probe that settles it:

  The variable-name rule said "a letter or `_` followed by letters, digits or `_`". The
  grammar is `letter+ ('_' (letter|digit)+)?`, which disagrees four ways: `_x` and `x_` are
  lexer errors, `x_1_2` is one too, `x1` is `x ^ 1` rather than a name, and Cyrillic is a
  letter as much as Greek.

  "`sinx` is `s * i * n * x`" is false -- `sinx` is one variable named `sinx`, because the
  lexer takes the longest match. Nothing here produced a product of one-letter names.

  "Juxtaposition is multiplication" is half of it. A number, a name or `)` followed by a
  number inserts `^` and not `*`, so `x2` is `x ^ 2` while `x(2)` is `x * 2`, and `x i` is
  `x ^ i` because `i` is a number token.

The associativity statement item 74 also names -- everything but `^` groups to the left --
was already corrected by #1009 and is left as it stands.

Two things the page now records rather than fixes: Stringize drops a codomain (#1022), and
a // comment that ends the input is a parse error because the lexer rule requires the
newline (#1039, filed from this work). #1028 gained the note that `[]` reaches its
IndexOutOfRangeException through the parser and not only through MathS.Vector.

Sources/Tests/UnitTests/Convenience/SyntaxDocumentedTest.cs runs every example on the page:
the precedence table row by row, the four shapes that are not names, both juxtaposition
rules and ExplicitParsingOnly, the number and boolean spellings, comments, the inverse
hyperbolic table, and sum and product including what their declared name shadows. It
compares entities, never printed forms.

Suite: 7930 passed, 0 failed, 14 skipped, against 7825 / 0 / 14 on this branch before the
change -- the 105 are this file, and nothing else moved.

The new file carries the default 2019-2022 header; Sources/.editorconfig, which pins it,
belongs to other pull requests this cycle and no 2026 scope was added there.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Bjumi5K7fg8yx6UK1mZTQd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant