tiny8.parser module¶
Simple parser shim for tiny8.
This module re-exports the assembler’s parse_asm function and serves as
the future location for a more featureful parser if needed.
- tiny8.parser.parse_asm(text: str) Tuple[List[Tuple[str, Tuple]], Dict[str, int]][source]¶
Parse assembly source text into a program listing and a label table.
The function scans the given assembly text line-by-line and produces two values:
program: a list of instructions, where each instruction is a tuple (MNEMONIC, OPERANDS_TUPLE). MNEMONIC is stored in uppercase for readability (the CPU/runtime looks up handlers using mnemonic.lower()). OPERANDS_TUPLE is an immutable tuple of operand values in the order they appear.
labels: a mapping from label name (str) to program counter (int), where the program counter is the zero-based index of the instruction in the produced program list.
- Args:
- text: Assembly source code as a single string. May contain comments,
blank lines and labels.
- Returns:
A pair (program, labels) as described above.
- Notes:
Comments begin with ‘;’ and extend to the end of the line and are removed before parsing.
Labels may appear on a line by themselves or before an instruction with the form “label: instr …”. A label associates the name with the current instruction index.
Registers are encoded as (“reg”, N) where N is the register number.
Numeric operands are parsed using _parse_number; non-numeric tokens are preserved as strings (symbols) for later resolution.