knit_script.knit_script_interpreter.expressions.variables module
Expression for accessing variables.
This module provides the Variable_Expression class, which handles variable access operations in knit script programs. It provides the mechanism for retrieving variable values from the current execution scope, following the scope resolution hierarchy established by the knit script context system.
- class Variable_Expression(parser_node, variable_name)[source]
Bases:
Expression
A structure for accessing variables by name from the current context scope.
The Variable_Expression class implements variable access operations in knit script programs. It stores a variable name and retrieves the corresponding value from the current execution context using the scope resolution system. This includes searching through local scopes, parent scopes, module scopes, and global scopes as defined by the knit script scoping rules.
This expression type is fundamental to knit script programs, enabling access to all types of variables including user-defined variables, function parameters, machine state variables, and built-in constants.
- Parameters:
parser_node (
LRStackNode
)variable_name (
str
)
- __init__(parser_node, variable_name)[source]
Initialize the Variable_Expression.
- Parameters:
parser_node (LRStackNode) – The parser node from the parse tree.
variable_name (str) – Name of the variable to access from the execution context.
- property variable_name: str
Get the name of the variable to access.
- Returns:
The name of the variable that this expression will retrieve from the current scope.
- Return type:
- evaluate(context)[source]
Evaluate the expression to retrieve the variable value.
- Performs variable lookup in the current execution context using the scope resolution system.
This follows the knit script scoping hierarchy, searching through local scopes, parent scopes, module scopes, and global scopes to find the variable.
- Parameters:
context (Knit_Script_Context) – The current context of the knit_script_interpreter.
- Returns:
The value of the variable found in the lowest applicable scope level.
- Return type:
Any
- property line_number: int
Get the line number of the symbol that generated this statement.
- Returns:
The line number where this element appears in the source file.
- Return type:
- property location: Location
Get the location of this symbol in KnitScript file.
- Returns:
The location of this symbol in the source file, including file name, line number, and position information.
- Return type:
Location