| Conditions | 5 |
| Total Lines | 24 |
| Code Lines | 11 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 9 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | import { Token, TokenType } from "./Token" |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Evaluate the result. |
||
| 24 | */ |
||
| 25 | evaluate(): bigint { |
||
| 26 | 6 | let n = 0n |
|
| 27 | 6 | for(const x of this.tokens) { |
|
| 28 | 8 | if (x.type === TokenType.identifier) { |
|
| 29 | 3 | if (!(x.s in this.identifiers)) { |
|
| 30 | 2 | throw `"${x.s}" is undefined` |
|
| 31 | } |
||
| 32 | 1 | n += BigInt(this.identifiers[x.s]) |
|
| 33 | } |
||
| 34 | // else if (x.type === TokenType.separator) { |
||
| 35 | // } |
||
| 36 | // else if (x.type === TokenType.operator) { |
||
| 37 | // if (x.s === '=') { |
||
| 38 | // } |
||
| 39 | // } |
||
| 40 | 5 | else if (x.type === TokenType.literal) { |
|
| 41 | 3 | n += BigInt(x.s) |
|
| 42 | } |
||
| 43 | } |
||
| 44 | 4 | return n |
|
| 45 | } |
||
| 57 |