Grammar
This document describes Psil’s grammar in a somewhat formal way, which roughly follows EBNF.
The actual parser may do something slightly different (but equivalent) than this, based on convenience.
The Grammar
- program ::= expr_list? end
- expr_list ::= expr+
-
-
atom ::= number |
boolean |
string |
symbol |
lambda |
identifier |
special_form |
-
invocation ::= ( (identifier |
special_form) expr_list? ) |
- lambda ::= { params? expr }
-
params ::= ** |
** identifier+ ** |
** |
-
special_form ::= if |
cond |
define |
do |
and |
or |
Tokens
Above, all words/characters in bold are token literals, while all words in italics are “specially defined tokens”:
- end is the end of the input stream.
- number is any “word” that can be parsed as a Rust
f64
.
-
- string ::= “ c* “, where c is any character except
"
. There are also the escape sequences \\
, \n
, \r
, \t
, \"
. Strings such as "\"
and “\z” are considered invalid tokens.
- symbol ::= #c+, where c is any character excluding whitespace.
- identifier is pretty much any word that doesn’t conflict with another token.
Not specified in the formal grammar is Psil’s “comments”. Currently, only single-line comments are supported, which start with ;
, and are terminated with the new line character.
; This is an example of a comment