eight_bit_computer.token_utils module

Functionality for working with string tokens on assembly lines

eight_bit_computer.token_utils.is_label(test_string)[source]

Test if a string is a valid label.

Parameters:test_string (str) – The string to test
Returns:True if the string is a valid label, false otherwise.
Return type:bool
eight_bit_computer.token_utils.is_variable(test_string)[source]

Test if a string is a valid variable.

Parameters:test_string (str) – The string to test
Returns:True if the string is a valid variable, false otherwise.
Return type:bool
eight_bit_computer.token_utils.is_constant(test_string)[source]
eight_bit_computer.token_utils.is_number(test_string)[source]

Test if a string is a valid number.

Parameters:test_string (str) – The string to test
Returns:True if the string is a valid number, false otherwise.
Return type:bool
eight_bit_computer.token_utils.number_constant_value(number_constant)[source]

Get the value that a number constant represents.

Parameters:number_constant (str) – The constant to extract the value from.
Returns:The value of the constant.
Return type:int
eight_bit_computer.token_utils.is_memory_index(argument)[source]

Determine whether this argument is a memory index.

Memory indexes can be module names or constants with a [ at the start and a ] at the end. e.g.:

  • [A]
  • [#42]
  • [$variable]
Parameters:argument (str) – The argument being used for the assembly operation.
Returns:True if the argument is a memory index, false if not.
Return type:bool
eight_bit_computer.token_utils.represent_as_memory_index(argument)[source]

Format the argument so it appears as a memory index.

See is_memory_index() for details on what a memory index is.

Parameters:argument (str) – The argument to represent as a memory index.
Returns:The formatted argument.
Return type:str
eight_bit_computer.token_utils.extract_memory_position(argument)[source]

Extract a memory position from a memory index argument.

See is_memory_index() for details of what a memory index is.

Parameters:argument (str) – The argument to extract a memory position from.
Returns:The location in memory being referenced.
Return type:str
eight_bit_computer.token_utils.get_tokens_from_line(line)[source]

Given a line split it into tokens and return them.

Tokens are runs of characters separated by spaces. If there are no tokens return an empty list.

Parameters:line (str) – line to convert to tokens
Returns:The tokens
Return type:list(str)