shulkerscript-lang/grammar.md

147 lines
1.8 KiB
Markdown
Raw Normal View History

# Grammar of the shulkerscript language
## Table of contents
### Program
```ebnf
Program: Declaration*;
```
### Declaration
```ebnf
Declaration: FunctionDeclaration;
```
### FunctionDeclaration
```ebnf
Function:
2024-04-01 20:42:38 +02:00
Annotation* 'fn' Identifier '(' ParameterList? ')' Block
;
ParameterList:
Identifier (',' Identifier)* ','?
;
```
2024-04-01 20:42:38 +02:00
### Annotation
```ebnf
Annotation: '#[' Identifier ('=' StringLiteral)? ']';
```
### Statement
```ebnf
Statement:
Block
| LiteralCommand
| Conditional
2024-04-05 16:16:12 +02:00
| Grouping
| DocComment
| Semicolon
| Run
;
```
### Block
```ebnf
Block: '{' Statement* '}';
```
### Run
```ebnf
Run:
'run' Expression ';'
;
```
### Conditional
```ebnf
Conditional:
'if' ParenthizedCondition Block ('else' Block)?
;
```
2024-04-06 17:23:20 +02:00
### Condition
```ebnf
2024-04-06 17:23:20 +02:00
Condition:
PrimaryCondition
BinaryCondition
;
```
2024-04-06 17:23:20 +02:00
#### PrimaryCondition
```ebnf
2024-04-06 17:23:20 +02:00
PrimaryCondition:
ConditionalPrefix
| ParenthesizedCondition
| StringLiteral
;
```
#### ConditionalPrefix
```ebnf
ConditionalPrefix:
ConditionalPrefixOperator PrimaryCondition
;
```
#### ConditionalPrefixOperator
``` ebnf
ConditionalPrefixOperator: '!';
```
#### BinaryCondition
``` ebnf
BinaryCondition:
Condition ConditionalBinaryOperator Condition
;
2024-04-05 16:16:12 +02:00
```
2024-04-06 17:23:20 +02:00
#### ConditionalBinaryOperator
``` ebnf
ConditionalBinaryOperator:
'&&'
| '||'
;
```
#### ParenthizedCondition
```ebnf
ParenthizedCondition:
'(' Condition ')'
;
```
2024-04-05 16:16:12 +02:00
### Grouping
``` ebnf
Grouping:
'group' Block
2024-04-06 17:23:20 +02:00
;
2024-04-05 16:16:12 +02:00
```
### Expression
```ebnf
Expression:
Primary
2024-04-06 17:23:20 +02:00
;
2024-04-05 16:16:12 +02:00
```
### Primary
``` ebnf
Primary:
FunctionCall
2024-04-06 17:23:20 +02:00
;
2024-04-05 16:16:12 +02:00
```
### FunctionCall
``` ebnf
FunctionCall:
Identifier '(' (Expression (',' Expression)*)? ')'
;
2024-04-06 17:23:20 +02:00
```
### LuaCode
```ebnf
LuaCode:
'lua' '(' (Expression (',' Expression)*)? ')' '{' (.*?)* '}'
;
```