diff --git a/hisscl/interp.py b/hisscl/interp.py index 2bb4636..ceed11b 100644 --- a/hisscl/interp.py +++ b/hisscl/interp.py @@ -15,10 +15,9 @@ class Block(dict): self.labels = labels super().__init__() -class Interp: - vars: dict[str, typing.Any] = {} - +class Interp: def __init__(self, stream: typing.TextIO, name: str): + self.vars: dict[str, typing.Any] = {} self.parser = parser.Parser(stream, name) def __setitem__(self, key, val): diff --git a/hisscl/lexer.py b/hisscl/lexer.py index e46d851..8d32dea 100644 --- a/hisscl/lexer.py +++ b/hisscl/lexer.py @@ -34,11 +34,10 @@ class ExpectedError(Exception): self.expected = expected class Lexer: - pos = ast.Position() - prev_pos = ast.Position() - unread = '' - def __init__(self, stream: typing.TextIO, name: str): + self.pos = pos = ast.Position() + self.prev_pos = ast.Position() + self.unread = '' self.stream = stream self.pos.name = name diff --git a/hisscl/parser.py b/hisscl/parser.py index bedda17..cd5fa4f 100644 --- a/hisscl/parser.py +++ b/hisscl/parser.py @@ -15,10 +15,9 @@ class ExpectedError(Exception): self.expected = expected class Parser: - _prev: tuple[lexer.Token, ast.Position, str] | None = None - def __init__(self, stream: TextIO, name: str): self.lexer = lexer.Lexer(stream, name) + self._prev: tuple[lexer.Token, ast.Position, str] | None = None def _scan(self) -> tuple[lexer.Token, ast.Position, str]: if self._prev is not None: