Merge pull request #338 from quantified-uncertainty/grammar-new110-26
grammar document
This commit is contained in:
		
						commit
						501ca2e73d
					
				
							
								
								
									
										56
									
								
								packages/website/docs/Internal/Grammar.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										56
									
								
								packages/website/docs/Internal/Grammar.md
									
									
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,56 @@
 | 
			
		|||
---
 | 
			
		||||
title: Grammar
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
<number> ::= [-]? [0-9]+ (.[0-9]+)? | [-]? [0-9]+ (.[0-9]+)? [e] [-]? [0-9]+
 | 
			
		||||
<symbol> ::= [a-zA-Z]+ [a-zA-Z0-9]?
 | 
			
		||||
<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>
 | 
			
		||||
<term> ::= <power> * <term> | <power> <term> | <power> / <term> | <power> .* <term> | <power ./ <term> | <power>
 | 
			
		||||
<power> ::= <factor> ^ <power> | <factor> .^ <power> | <factor>
 | 
			
		||||
<factor> ::= <number> | <bool> | <symbol> | ( <expr> ) | <array> | <record> | <record>.<symbol> | <symbol> => <expr> | <symbol>(<symbol>) | <symbol>(<symbol>, <symbol>) | ...
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Data structures
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
<array> ::= [] | [<expr>] | [<expr>, <expr>] | ...
 | 
			
		||||
<record> ::= {} | {<symbol>: <expr>} | {<symbol>: <expr>, <symbol>: <expr>} | ...
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## Statements
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
<statement> ::= <assign> | <assignFunction>
 | 
			
		||||
<assign> ::= <symbol> = <expr>
 | 
			
		||||
<assignFunction> ::= <symbol>(<symbol>) = <expr> | <symbol>(<symbol>, <symbol>) = <expr> | ...
 | 
			
		||||
```
 | 
			
		||||
 | 
			
		||||
## A squiggle file
 | 
			
		||||
 | 
			
		||||
To be valid and raise no errors as of current (apr22) interpreter,
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
<delim> ::= ; | \n
 | 
			
		||||
<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.
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user