~kf5jwc/imp-parser

ref: 9a694fa0d8b73f01beb051b54cdab8a2b000be09 imp-parser/imp_parser/ast/integer.py -rw-r--r-- 329 bytes View raw
9a694fa0 — Kyle Jones I've done more type annotating, which.... helped? 1 year, 6 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from dataclasses import dataclass
from .types import Aexp


@dataclass
class IntAexp(Aexp):
    i: int

    def eval(self, _: dict) -> int:
        return self.i


@dataclass
class VarAexp(Aexp):
    name: str

    def eval(self, env: dict) -> int:
        if self.name in env:
            return env[self.name]
        return 0