-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSyntaxExtentions.cs
28 lines (27 loc) · 1018 Bytes
/
SyntaxExtentions.cs
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
namespace YuchikiML {
using System;
public static class SyntaxExtentions {
public static int Size(this Expr e) {
switch (e) {
case Literal lit:
return 1;
case Var variable:
return 1;
case BinOperator binOp:
return binOp.Left.Size() + binOp.Right.Size() + 1;
case Not n:
return n.Body.Size() + 1;
case If ifExpr:
return ifExpr.Condition.Size() + ifExpr.Left.Size() + ifExpr.Right.Size() + 1;
case Bind bind:
return bind.VarBody.Size() + bind.ExprBody.Size() + 1;
case LetRec letRec:
return letRec.VarBody.Size() + letRec.ExprBody.Size() + 1;
case Abs abs:
return abs.Body.Size() + 1;
default:
throw new ArgumentOutOfRangeException();
}
}
}
}