thp/src/syntax/grammar.md

46 lines
455 B
Markdown
Raw Normal View History

2023-01-05 23:20:58 +00:00
# Grammar
2023-09-17 22:58:56 +00:00
2023-01-05 23:20:58 +00:00
## Module
A module is (commonly) a single source file.
2023-09-17 22:58:56 +00:00
```ebnf
module = top level declaration*
```
2023-01-05 23:20:58 +00:00
2023-09-17 22:58:56 +00:00
## Top level declaration
```ebnf
top level declaration = function declaration
```
2023-01-05 23:20:58 +00:00
2023-09-17 22:58:56 +00:00
## Function declaration
2023-01-05 23:20:58 +00:00
```ebnf
2023-09-17 22:58:56 +00:00
function declaration = "fun", identifier, params list, return type?, block
```
2023-09-17 22:58:56 +00:00
### Params list
2023-01-05 23:20:58 +00:00
2023-09-17 22:58:56 +00:00
```ebnf
params list = "(", ")"
```
2023-01-05 23:20:58 +00:00
2023-09-17 22:58:56 +00:00
### Return type
```ebnf
2023-09-17 22:58:56 +00:00
return type = ;
```
2023-09-17 22:58:56 +00:00
### Block
2023-01-05 23:20:58 +00:00
```ebnf
2023-09-17 22:58:56 +00:00
block = "{", "}"
```
2023-01-05 23:20:58 +00:00
2023-09-17 22:58:56 +00:00