- Removed original TODO for Wilhelm
- Split grammar into sections
- Added a mostly complete "Literals" section with grammar
- Removed simple definitions for things lime `{`, `(` and so on
- Made a new section called "Statements", added definition for a while loop and variable declarations
- Added expression section
This commit is contained in:
Tristan B. Velloza Kildaire 2023-04-18 09:23:41 +02:00
parent d7a7060578
commit 4c7aa516a6
1 changed files with 58 additions and 14 deletions

View File

@ -1,22 +1,66 @@
## Grammar
* TODO: Need help with this @Wilhelm, some things to look at (must reference!)
* https://karmin.ch/ebnf/examples
The grammar for the language is still a work in progress and may take some time to
become concrete but every now and then I update this page to add more to it or fix
any incongruencies with the parser's actual implementation. The grammar starts from
the simplest building blocks and then progresses to the more complex (heavily composed)
ones and these are placed into sections whereby they are related.
**TODO:** Finish implementing this
### Literals
These make are the basic atoms that define literals.
**TODO:** Finish enumerating all numbers
```
statement := discard | todo
expr := literal | binop
binop := expr operator expr
discard := "discard" expr ;
oparen := "("
cparen := ")"
ocurly := "{"
ccurly := "}"
if := "if" oparen expr cparen ocurly { statement } ccurly {"else" if } | "else" { statement }
letter ::= "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K"
| "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V"
| "W" | "X" | "Y" | "Z" | "a" | "b" | "c" | "d" | "e" | "f" | "g"
| "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r"
| "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
number ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" | "0";
```
### Expressions
Expressions come in many forms and are defined here.
```
expr ::= literal | binop | unaryop;
infix ::= "+" | "-" | "*" | "-";
prefix ::= "*" | "&";
binop ::= expr, operator, expr;
unaryop ::= prefix, operator;
```
### Statements
Statements are inevitably the building blocks of a program and make
use of all the former defined sections of the grammar and more of
themsleves in some cases as well.
```
statement ::= discard | decl;
!!! error
A formal grammar does not yet exist, _however_, it is currently in the works and will be available by year end.
discard ::= "discard", expr ;
ident ::= letter | { letter | number };
decl ::= type, identifier, [assign], ";";
type ::= "int" | "uint" | ident;
assign ::= "=", expr;
if ::= "if", "(", expr, ")", "{", { statement }, "}",
[ { "else", if } | ( "else", "{", { statement }, "}") ];
while ::= "while", "(", expr, ")", "{", { statement }, "}";
```