CR comments; other things

This commit is contained in:
Quinn Dougherty 2022-04-22 12:42:05 -04:00
parent 2c060ccf6a
commit 8f2d0f06f0

View File

@ -1,6 +1,5 @@
---
title: Grammar
urlcolor: blue
author:
- Quinn Dougherty
---
@ -13,17 +12,20 @@ _In all likelihood the reference will have to be debugged as we see what tests p
- `<number>` ::= `[-]? [0-9]+ (.[0-9]+)? | [-]? [0-9]+ (.[0-9]+)? [e] [-]? [0-9]+`
- `<symbol>` ::= `[a-zA-Z]+ [a-zA-Z0-9]?`
- `<baseDistribution>` ::= `(normal(<number>, <number>) | beta(<number>, <number>) | triangular(<number>, <number>, <number>) | cauchy(<number>, <number>) | lognormal(<number>, <number>)) | uniform(<number>, <number>) | <number> to <number> | exponential(<number>)`
- `<baseDistribution>` ::= `normal(<number>, <number>) | beta(<number>, <number>) | triangular(<number>, <number>, <number>) | cauchy(<number>, <number>) | lognormal(<number>, <number>)) | uniform(<number>, <number>) | <number> to <number> | exponential(<number>)`
- `<bool>` ::= `true | false`
## Expressions
The following gives no typing information. You can obey the grammar and still write nonsensical code.
Think of javascript's list unpacking notation to read our variable-argument function `mixture`.
```
<expr> ::= <term> + <expr> | <term> - <expr> | <expr> .+ <expr> | <expr> .- <expr> | <term> | sample(<baseDistribution>) | mixture(...<array>, <array>) | mx(...<array>, <array>) | exp(<expr>) | log(<expr>, <number>?) | log10(<expr>) | dotLog(<expr>, <number>?) | normalize(<expr>)
<expr> ::= <term> + <expr> | <term> - <expr> | <expr> .+ <expr> | <expr> .- <expr> | <term> | sample(<baseDistribution>) | mixture(...<array>, <array>) | mx(...<array>, <array>) | exp(<expr>) | log(<expr>, <number>?) | log10(<expr>) | dotLog(<expr>, <number>?) | normalize(<expr>) | isNormalized(<expr>) | pdf(<expr>, <expr>) | cdf(<expr>, <expr>) | inv(<expr>, <expr>) | mean(<expr>) | truncate(<expr>, <expr>, <expr>) | truncateLeft(<expr>, <expr>) | truncateRight(<expr>, <expr>)
<term> ::= <power> * <term> | <power> <term> | <power> / <term> | <power> .* <term> | <power ./ <term> | <power>
<power> ::= <factor> ^ <power> | <factor> .^ <power> | <factor>
<factor> ::= <number> | <baseDistribution> | <symbol> | ( <expr> )
<factor> ::= <number> | <baseDistribution> | <bool> | <symbol> | ( <expr> )
```
## Data structures
@ -36,9 +38,9 @@ Think of javascript's list unpacking notation to read our variable-argument func
## Statements
```
<stmnt> ::= <asgn> | <asgnFn>
<asgn> ::= <symbol> = <expr>
<asgnFn> ::= <symbol>(<symbol>) = <expr>
<statement> ::= <assign> | <assignFunction>
<assign> ::= <symbol> = <expr>
<assignFunction> ::= <symbol>(<symbol>) = <expr>
```
## A squiggle file
@ -47,7 +49,7 @@ To be valid and raise no errors as of current (apr22) interpreter,
```
<delim> ::= ; | \n
<code> ::= <expr> | <stmnt> <delim> <expr> | <stmnt> <delim> <stmnt> <delim> <expr> | ...
<code> ::= <expr> | <statement> <delim> <expr> | <statement> <delim> <statement> <delim> <expr> | ...
```
This isn't strictly speaking true; the interpreter allows expressions outside of the final line.