A HYBRID METHOD FOR STREAMING DEFERRED CONSTRUCTION OF A SYNTAX TREE

Authors

DOI:

https://doi.org/10.31673/2412-4338.2026.037403

Abstract

The article addresses the problem of constructing syntax trees in static program code analysis systems, where the classical full materialization of a parse tree may lead to significant memory overhead. A hybrid method for streaming deferred construction of a syntax tree is proposed. The method combines the spatial efficiency of streaming approaches with the ability to navigate materialized fragments of the tree. Unlike the traditional model, in which a syntax tree is fully constructed before further processing begins, the proposed approach provides for node materialization as the consumer algorithm traverses the syntax tree and requires access to its fragments. The method is based on an event-driven parsing model, in which the underlying parser generates an ordered stream of parsing events, while a specialized adapter transforms these events into partially materialized nodes and control markers. To coordinate event generation and the materialization process, a bounded intermediate buffer is used. It provides FIFO semantics, memory usage control, and correct interaction between the producer and the consumer. Special attention is paid to the formalization of deferred computations, the mechanism of forcing promises, correct termination of the streaming process, and handling of failure states. It is shown that the actual space complexity of the proposed model is determined by the depth of the current parsing stack, the size of the intermediate buffer, and the set of materialized nodes that remain reachable through active references held by the consumer algorithm. In the worst case, the space complexity approaches that of the classical approach with full tree materialization. However, in typical practical traversal scenarios, when active references to already processed nodes are lost, the memory allocated for them can be reclaimed by the garbage collector before the analysis of the entire structure is completed.

This reduces peak memory consumption and allows that memory to be reused within the same analysis process.

Keywords: syntax tree, deferred computations, streaming processing, event-driven model, parsing, space complexity

Published

2026-10-01

Issue

Section

Articles