riscemu.parser module

RiscEmu (c) 2021 Anton Lydike

SPDX-License-Identifier: MIT

riscemu.parser.parse_instruction(token: Token, args: Tuple[str], context: ParseContext)
riscemu.parser.parse_label(token: Token, args: Tuple[str], context: ParseContext)
riscemu.parser.parse_tokens(name: str, tokens_iter: Iterable[Token]) Program

Convert a token stream into a parsed program :param name: the programs name :param tokens_iter: the programs content, tokenized :return: a parsed program

riscemu.parser.composite_tokenizer(tokens_iter: Iterable[Token]) Iterable[Tuple[Token, Tuple[str]]]

Convert an iterator over tokens into an iterator over tuples: (token, list(token))

The first token ist either a pseudo_op, label, or instruction name. The token list are all remaining tokens before a newline is encountered :param tokens_iter: An iterator over tokens :return: An iterator over a slightly more structured representation of the tokens

riscemu.parser.take_arguments(tokens: Peekable[Token]) Iterable[str]

Consumes (argument comma)* and yields argument.value until newline is reached If an argument is not followed by either a newline or a comma, a parse exception is raised The newline at the end is consumed :param tokens: A Peekable iterator over some Tokens

class riscemu.parser.AssemblyFileLoader(source_name: str, source: IOBase, options: Dict[str, Any])

Bases: ProgramLoader

This class loads assembly files written by hand. It understands some assembler directives and supports most pseudo instructions. It does very little verification of source correctness.

It also supports numbered jump targets and properly supports local and global scope (globl assembly directive)

The AssemblyFileLoader loads .asm and .s files by default, and acts as a weak fallback to all other filetypes.

is_binary: ClassVar[bool] = False
source: TextIO
parse() Program
Returns:

classmethod can_parse(source_name: str) float

Parse a string assembly file. It also acts as a weak fallback if no other loaders want to take the file.

classmethod get_options(argv: List[str]) Tuple[List[str], Dict[str, Any]]

parse command line args into an options dictionary

Parameters:

argv – the command line args list

Returns:

all remaining command line args and the parser options object