# Get formula AST

* Extension version `1.6.0` or later;
* Build with `--enable-reader`;

Parses a formula string into a nested abstract syntax tree (AST) so it can be inspected or rewritten in PHP.

## Methods

```php
getFormulaAst(string $formula): array
```

### **string $formula**

> Formula string. The leading `=` is optional.

## Return value

A nested tree of token nodes. Each node carries a `kind` field (`func`, `ref`, `range`, `number`, `string`, `bool`, `error`, `op`, `array`, ...) and additional fields appropriate to that kind (argument lists, reference text, operator, child nodes).

This method does not depend on workbook state; it can be called without `openFile()`.

## Example

```php
var_export(\Vtiful\Kernel\Excel::getFormulaAst('=SUM(A1:A10) + 1'));
// Output is shaped like:
// array (
//   'kind' => 'op',
//   'op'   => '+',
//   'args' => array (
//     0 => array (
//       'kind' => 'func',
//       'name' => 'SUM',
//       'args' => array ( 0 => array ('kind' => 'range', 'text' => 'A1:A10') ),
//     ),
//     1 => array ('kind' => 'number', 'value' => 1.0),
//   ),
// )
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xlswriter-docs.viest.me/english/reader/get-formula-ast.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
