-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCompIR0.ts
55 lines (48 loc) · 1.04 KB
/
CompIR0.ts
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
export type Statement<Expr> =
| {
if: { cond: Expr; then: Statement<Expr> }[];
else?: Statement<Expr>;
}
| { while: Expr; do: Statement<Expr> }
| Statement<Expr>[]
| { iterator: string; from: Expr; to: Expr; step?: Expr; do: Statement<Expr> }
| { do: Statement<Expr>; until: Expr }
| "break"
| "continue"
| { declare: string; value: Expr }
| { set: string; value: Expr }
| { call: string; args: Expr[] }
| { return: Expr }
type Binops =
| "+"
| "-"
| "*"
| "/"
| "^"
| "%"
| "&"
| "|"
| ">>"
| "<<"
| "<"
| "<="
| ">"
| ">="
| "=="
| "~="
| "and"
| "or";
export type Expression =
| { unop: "-" | "!" | "~"; arg: Expression }
| { binop: Binops; argl: Expression; argr: Expression }
| string
| { call: string; args: Expression[] }
| number;
export type DeclarationStatement<Stmt>={
function: string;
args: string[];
block: Stmt;
};
export type TopStatement<Expr> = Statement<Expr> | DeclarationStatement<Statement<Expr>>
export type JsonLang = TopStatement<Expression>[];
export type CompIR0 = JsonLang