-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoya.cf
82 lines (75 loc) · 2.62 KB
/
soya.cf
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
--- programs ---
entrypoints Program ;
Prog. Program ::= [Stmt] ;
--- statements ---
Blk. Block ::= "{" [Stmt] "}" ;
separator Stmt "" ;
Empty. Stmt ::= ";" ;
BStmt. Stmt ::= Block ;
AssStmt. Stmt ::= Target "=" Source;
TargetId. Target ::= Ident;
TargetList. Target ::= Ident "[" Expr "]";
DummyTarget. Target ::= "_";
separator Target "," ;
SourceExpr. Source ::= Expr;
SourceType. Source ::= Type;
VoidCall. Stmt ::= Ident "(" [Expr] ")" ;
Ret. Stmt ::= "return" Expr ";" ;
VRet. Stmt ::= "return" ";" ;
Cond. Stmt ::= "if" "(" Expr ")" Block ;
CondElse. Stmt ::= "if" "(" Expr ")" Block "else" Block ;
While. Stmt ::= "while" "(" Expr ")" Block ;
Break. Stmt ::= "break" ";" ;
Cont. Stmt ::= "continue" ";" ;
For. Stmt ::= "for" "(" Ident "=" Expr "to" Expr ")" Block ;
Grow. Stmt ::= "grow" "(" Ident "," Expr ")" ";" ; -- adds element to the beggining of the list
Cut. Stmt ::= "cut" "(" Ident ")" ";" ; -- removes element from the beggining of the list
DeclFunc. Stmt ::= FnDef;
FuncStmt. FnDef ::= "def" Ident "(" [Arg] ")" "->" Type Block ;
VoidFuncStmt. FnDef ::= "def" Ident "(" [Arg] ")" Block ;
Print. Stmt ::= "print" "(" Expr ")" ";" ;
ArType. Arg ::= Ident "=" Type ;
ArValue. Arg ::= Ident "=" Expr ;
ArRef. Arg ::= "ref" Ident "=" Type ;
separator Arg "," ;
--- types ---
Int. Type ::= "int" ;
Str. Type ::= "str" ;
Bool. Type ::= "bool" ;
List. Type ::= "[" Type "]";
separator Type ",";
--- expressions ---
EVar. Expr6 ::= Ident ;
ELitInt. Expr6 ::= Integer ;
ELitTrue. Expr6 ::= "True" ;
ELitFalse. Expr6 ::= "False" ;
ELitNone. Expr6 ::= "None" ;
EApp. Expr6 ::= Ident "(" [Expr] ")" ;
EString. Expr6 ::= String ;
EGetElem. Expr6 ::= Ident "[" Expr "]" ; -- gets value from list
ENewList. Expr6 ::= "[" [Expr] "]" ; -- creates a list out of expressions: [1, 2+2, 5]
Len. Expr6 ::= "len" "(" Ident ")" ; -- returns length of the list
EIsNone. Expr6 ::= "isna" "(" Expr ")";
Neg. Expr5 ::= "-" Expr6 ;
Not. Expr5 ::= "not" Expr6 ;
EMul. Expr4 ::= Expr4 MulOp Expr5 ;
EAdd. Expr3 ::= Expr3 AddOp Expr4 ;
ERel. Expr2 ::= Expr2 RelOp Expr3 ;
EAnd. Expr1 ::= Expr2 "and" Expr1 ;
EOr. Expr ::= Expr1 "or" Expr ;
separator Expr "," ;
coercions Expr 6 ;
--- operators ---
Plus. AddOp ::= "+" ;
Minus. AddOp ::= "-" ;
Times. MulOp ::= "*" ;
Div. MulOp ::= "/" ;
Mod. MulOp ::= "mod" ;
LTH. RelOp ::= "<" ;
LE. RelOp ::= "<=" ;
GTH. RelOp ::= ">" ;
GE. RelOp ::= ">=" ;
EQU. RelOp ::= "==" ;
NE. RelOp ::= "!=" ;
--- comments ---
comment "#" ;