Auxillary functions

Module name: blackbird.auxiliary

This module contains a variety of auxiliary functions used by the main blackbird.BlackbirdListener.

Note that every auxiliary function in this module accepts a blackbird.blackbirdParser context as an argument.

Summary

_expression(expr)

Evaluate a blackbird expression.

_func(function, arg)

Apply a blackbird function to an Python argument.

_get_arguments(arguments)

Parse blackbird positional and keyword arguments.

_literal(nonnumeric)

Convert a non-numeric blackbird literal to a Python literal.

_number(number)

Convert a blackbird number to a Python number.

_VAR

Mapping from the variable names in the Blackbird script, to their declared values.

Code details

_VAR = {}

Mapping from the variable names in the Blackbird script, to their declared values.

This dictionary is populated when parsing blackbird.blackbirdParser.ExpressionvarContext objects via blackbird.BlackbirdListener.exitExpressionvar, and accessed when required by _expression().

Type

dict[str->[int, float, complex, str, bool, numpy.ndarray]]

_PARAMS = []

list of free parameters in the Blackbird program

Type

list[Symbol]

_literal(nonnumeric)[source]

Convert a non-numeric blackbird literal to a Python literal.

Parameters

nonnumeric (blackbirdParser.NonnumericContext) – nonnumeric context

Returns

str or bool

_number(number)[source]

Convert a blackbird number to a Python number.

Parameters

number (blackbirdParser.NumberContext) – number context

Returns

int or float or complex

_func(function, arg)[source]

Apply a blackbird function to an Python argument.

Parameters
  • function (blackbirdParser.FunctionContext) – function context

  • arg – expression

Returns

int or float or complex

_expression(expr)[source]

Evaluate a blackbird expression.

This is a recursive function, that continually calls itself until the full expression has been evaluated.

Parameters

expr – expression

Returns

int or float or complex or str or bool

_get_arguments(arguments)[source]

Parse blackbird positional and keyword arguments.

In blackbird, all arguments occur between brackets (), and separated by commas. Positional arguments always come first, followed by keyword arguments of the form name=value.

Parameters

arguments (blackbirdParser.ArgumentsContext) – arguments

Returns

tuple containing the list of positional arguments, followed by the dictionary of keyword arguments

Return type

tuple[list, dict]