From 2c060ccf6a8d6d97ed00d1889277e12e6dbd81d0 Mon Sep 17 00:00:00 2001 From: Quinn Dougherty Date: Fri, 22 Apr 2022 00:15:30 -0400 Subject: [PATCH] grammar --- packages/website/docs/Internal/Grammar.md | 53 +++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 packages/website/docs/Internal/Grammar.md diff --git a/packages/website/docs/Internal/Grammar.md b/packages/website/docs/Internal/Grammar.md new file mode 100644 index 00000000..954ee95b --- /dev/null +++ b/packages/website/docs/Internal/Grammar.md @@ -0,0 +1,53 @@ +--- +title: Grammar +urlcolor: blue +author: + - Quinn Dougherty +--- + +Formal grammar specification, reference material for parser implementation. + +_In all likelihood the reference will have to be debugged as we see what tests pass and don't pass during implementation_. + +## Lexical descriptions of constants and identifiers + +- `` ::= `[-]? [0-9]+ (.[0-9]+)? | [-]? [0-9]+ (.[0-9]+)? [e] [-]? [0-9]+` +- `` ::= `[a-zA-Z]+ [a-zA-Z0-9]?` +- `` ::= `(normal(, ) | beta(, ) | triangular(, , ) | cauchy(, ) | lognormal(, )) | uniform(, ) | to | exponential()` + +## Expressions + +Think of javascript's list unpacking notation to read our variable-argument function `mixture`. + +``` + ::= + | - | .+ | .- | | sample() | mixture(..., ) | mx(..., ) | exp() | log(, ?) | log10() | dotLog(, ?) | normalize() + ::= * | | / | .* | | + ::= ^ | .^ | + ::= | | | ( ) +``` + +## Data structures + +``` + ::= [] | [] | [, ] | ... + ::= {} | {: } | {: , : } | ... +``` + +## Statements + +``` + ::= | + ::= = + ::= () = +``` + +## A squiggle file + +To be valid and raise no errors as of current (apr22) interpreter, + +``` + ::= ; | \n + ::= | | | ... +``` + +This isn't strictly speaking true; the interpreter allows expressions outside of the final line.