parser
Parser for Finch Assembly in Python's multiline strings.
Supports constructing assembly nodes objects from parsed strings.
There is also a dedicated VS Code extension for proper highlighting of tagged strings: https://github.com/finch-tensor/vscode-finch-assembly. The extension is not yet available on VS Code marketplace. You can find installation file here: https://github.com/finch-tensor/vscode-finch-assembly/releases
parse_assembly(code, vars, position_type=np.intp)
Parse Finch Assembly code and convert it to assembly node objects.
Takes a string containing Finch Assembly code and transforms it into a structured representation using assembly nodes. The parser supports assignments, increments, for/while loops, if/if-else statements, buffer and field accesses, and calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
code
|
str
|
The Finch Assembly code to parse. Should start with "finch" or "finch-asm" followed by assembly statements. Comments (C/C++ style) are supported. |
required |
vars
|
dict[str, AssemblyExpression]
|
Dictionary mapping names to Assembly expressions. Used to resolve variable references in the assembly code. |
required |
position_type
|
type
|
NumPy integer type to use for integer literals. Affects the dtype of parsed integer constants. (default: np.intp) |
intp
|
Returns:
| Type | Description |
|---|---|
Block
|
A Finch Assembly Block representing the parsed code. |
Raises:
| Type | Description |
|---|---|
Exception
|
If the parser encounters unrecognized syntax or tree nodes. |
Example
from finch.finch_assembly import nodes as asm vars = {"i": asm.Variable("i", int), "arr": asm.Variable("arr", np.ndarray)} code = '''finch ... arr[i] = 42 ... ''' stmt = parse_assembly(code, vars)
Source code in src/finch/finch_assembly/parser.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |