/** @file ParserStack.hpp * * @author Roland Conybeare, Jan 2026 **/ #pragma once #include "SyntaxStateMachine.hpp" #include #include namespace xo { namespace scm { /** @brief A stack of expression state machines * * Each state machine is dedicated to a particular syntax instance. * The innermost machine is in xsm; machines for surrounding expressions * are in progressively removed frames reached via parent links. **/ class ParserStack { public: using DArena = xo::mm::DArena; public: ParserStack(DArena::Checkpoint ckp, obj ssm, ParserStack * parent); /** create new top of stack for syntax @p ssm, using memory from @p mm. * previous stack given by @p parent **/ static ParserStack * push(ParserStack * stack, DArena & mm, obj ssm); /** unwind effect of last call to @ref push **/ static ParserStack * pop(ParserStack * stack, DArena & mm); DArena::Checkpoint ckp() const noexcept { return ckp_; } obj top() const noexcept { return ssm_; } ParserStack * parent() const noexcept { return parent_; } private: /** stack pointer: top of stack just before this instance created **/ DArena::Checkpoint ckp_; /** top of parsing stack: always non-null **/ obj ssm_; /** remainder of parsing stack excluding top **/ ParserStack * parent_ = nullptr; }; } /*namespace scm*/ } /*namespace xo*/ /* end ParserStack.hpp */