TorchLean API

NN.Verification.PINN.PdeParse

PdeParse #

A compact hand-rolled parser from strings to PDE AST (Expr).

Grammar (informal): expr := term (('+' | '-') term)* term := factor ('' factor) factor := primary ('^' int)? primary:= 'u' | 'ux' | 'uy' | 'uxx' | 'uyy' | number | ident | '(' expr ')'

Numbers are parsed as Floats. Idents look up a value from env : StringOption Float. Unsupported tokens produce an error.

Implementation note: The parser is total by threading a simple fuel : Nat through the recursive descent; fuel is initialized from the remaining bytes in the input and decreases on every recursive descent step.

References:

Parser state for the hand-written PDE expression parser.

Instances For
    @[inline]
    Instances For
      @[inline]
      Instances For
        @[inline]
        Instances For
          @[inline]
          Instances For

            Whitespace predicate used by the PDE expression parser.

            Instances For

              Skip whitespace with an explicit recursion budget.

              Instances For

                Skip whitespace from the current parser state.

                Instances For

                  Consume characters satisfying p, accumulating into acc, with explicit fuel.

                  Instances For

                    Consume characters satisfying p, accumulating into acc.

                    Instances For

                      Parse a signed decimal number without exponent, e.g. -12.34.

                      Instances For

                        Parse a natural number at the current parser state.

                        Instances For

                          Parse an identifier used for environment lookup.

                          Instances For

                            Parse an additive/subtractive expression with an explicit recursion budget.

                            Instances For

                              Parse a multiplicative term with an explicit recursion budget.

                              Instances For

                                Parse a primary expression plus an optional integer power.

                                Instances For

                                  Parse atoms: parenthesized expressions, u/derivative names, numerals, or environment identifiers.

                                  Instances For

                                    Parse a full expression from the current parser state.

                                    Instances For

                                      Entry point: parse a string to Expr using env for identifiers.

                                      Instances For