Parse #
Hand-rolled parser for ODE RHS expressions.
Grammar (informal): expr := term (('+' | '-') term)* term := unary (('' | '/') unary) unary := '-' unary | factor factor := primary ('^' nat)? primary:= number | 't' | 'u' | ident '(' expr ')' | ident | '(' expr ')'
Supported unary functions: sin, cos, exp, log. Supported identifiers: pi.
Exponentiation is expanded into repeated multiplication when ^ n is given; x^0 is one.
Exponentiation binds more tightly than unary minus, so -u^2 means -(u^2).
This parser is part of the executable ODE verifier. We keep the grammar direct and hand-written so that the accepted certificate syntax is visible in one file, with predictable errors and no hidden parser-combinator behavior.
The output AST is NN.Verification.ODE.Ast.Expr.
Parser state and low-level helpers #
The cursor itself lives in NN.Verification.Util.TextCursor, shared with the PINN PDE parser, and
so do the scanning primitives. What remains here is a thin layer whose only job is to supply this
grammar's fuel budget to those primitives, so the rest of the file can call skipWs and friends
without repeating fuelOf st at every site. The PDE parser keeps the same four names for the same
reason; the budget behind them is what differs.
A fuel budget derived from the remaining input length, which is what guarantees termination.
Unlike the PDE parser this grammar bottoms out within the remaining bytes, so the raw remaining count is enough and no headroom factor is needed.
Instances For
Skip ASCII whitespace (' ', '\t', '\n').
Instances For
Consume consecutive characters satisfying p, accumulating them into acc.
Returns the consumed text and the updated parser state.
Instances For
Parse a signed decimal number without exponent, e.g. -12.34.
Instances For
Parse a natural number (decimal digits) used for exponents ^ n.
Instances For
Parse an identifier consisting of letters/digits/underscore.
Instances For
Built-in constants and unary functions #
Internal: interpret built-in constants like pi / π.
Instances For
Recursive descent: expression/term/factor/unary/primary #
Internal: parse an expr (addition/subtraction chain), with an explicit fuel budget.
This is a plain def (not private) because the module is in a public section for
export/doc tooling, and public declarations should not depend on private helper definitions.
Instances For
Instances For
Parse a term (multiplication/division chain), with an explicit fuel budget.
Instances For
Instances For
Parse a primary expression with optional natural-number exponentiation.
Instances For
Parse a unary (leading negations), with an explicit fuel budget.
Instances For
Parse a primary atom (number/variable/function-call/parentheses), with an explicit fuel
budget.