-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgrammar.txt
63 lines (32 loc) · 1.43 KB
/
grammar.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
program: declarations
declarations: lib* variable_declaration* <'<-->'> function* mainFunction
lib: DOLLAR <'libinclude'> DOLLAR ID SEMICOLON
variable_declaration: variable initialization
initialization: INITIALIZE bool SEMICOLON
variable_assignment: variable ASSIGN function_call SEMICOLON
mainFunction: funcDecl mainFunc
mainFunc: name <'='> <'?'> function_call <'?'>
funcDecl: name <'::'> types
function: funcDecl func
func: name params <'='> <'?'> funcBody <'?'>
name: ID
types: type (<'->'> type)*
params: ID*
funcBody: expression* return_statement?
return_statement: RETURN regExpression
expression: (conditional | loop | regExpression | variable_assignment)
conditional: <'if'> boolExpression <'fi'> <'then'> expression <'neht'> <'else'> expression <'esle'>
loop: <'check'> boolExpression <'loop'> expression <'pool'> (<'do'> variable_assignment)?
regExpression: boolExpression SEMICOLON
boolExpression: <'!'>? bool (logicalOperator <'!'>? bool)*
bool: expr (comparator expr)*
expr: term ((PLUS | MINUS) term)*
term: factor ((MUL | DIV | REALDIV | MOD) factor)*
factor: PLUS factor | MINUS factor | NUMBER | LPAREN expr RPAREN | variable | function_call | STRING | LIST
variable: name
comparator: LESS | GREATER | EQUAL | NOT_EQUAL | LESS_EQ | GREATER_EQ
string: CHAR*
type: Char | Bool | Num | String | list | IO
list: <'['> type <']'>
logicalOperator: AND | OR
function_call: <'`'> name <'`'> <'{'> (expr (<','> expr)*)? <'}'>