.. _exs-workflows: Workflows ========= These examples show the native EXS tasks that most applications combine: evaluate an expression, inspect its structure, and replace the operator configuration when the default language is not the right fit. Evaluate and print a result --------------------------- Use the default solver when the expression language is numeric or Boolean: .. code-block:: cpp #include snt::exs::Solver solver; auto result = solver.eval("1 + 2 * 3"); result.print(); The built-in steps give multiplication precedence over addition. See :doc:`Operators and evaluation order ` for the complete default pass list. Inspect expression structure ---------------------------- Pass a ``CompositionGraph`` when the caller also needs the syntax tree: .. code-block:: cpp snt::exs::CompositionGraph graph; auto result = solver.eval("1 + 2 * 3", &graph); const auto& root = graph.nodes.at(graph.root); const auto& right = graph.nodes.at(root.children.at(1)); The example expression reduces to an ``add`` node whose right child is a ``mul`` node. The graph is syntactic: it does not record DIP references, branch decisions, or intermediate values. See :doc:`Solver usage and composition graphs ` for graph invariants and the standalone ``build_composition_graph`` pass. Replace symbols and evaluation order ------------------------------------ Supply an ``OperatorList`` and ``StepList`` when a domain language uses different symbols or precedence: .. code-block:: cpp #include #include snt::exs::OperatorList operators; operators.append(snt::exs::NOT_OPERATOR, std::make_shared("N")); operators.append(snt::exs::AND_OPERATOR, std::make_shared("A")); operators.append(snt::exs::OR_OPERATOR, std::make_shared("O")); snt::exs::StepList steps; steps.append(snt::exs::BINARY_OPERATION, {snt::exs::OR_OPERATOR}); steps.append(snt::exs::BINARY_OPERATION, {snt::exs::AND_OPERATOR}); steps.append(snt::exs::UNARY_OPERATION, {snt::exs::NOT_OPERATOR}); snt::exs::Solver custom(operators, steps); auto result = custom.eval("N false A false O true"); Passing both lists replaces both defaults, so every operator used by the expression must be registered and scheduled. See :doc:`Custom atoms and operations ` when a new operation type is required. Pass application settings ------------------------- Derive a settings type and use it as the solver's second template argument when atom parsing or operators need application data: .. code-block:: cpp struct Settings : snt::exs::BaseSettings { std::string symbol; int value; }; Settings settings{{}, "?", 5}; snt::exs::Solver solver(operators, steps, settings); auto result = solver.eval("2 + ?"); The solver stores a copy of the settings object. See :doc:`Solver settings ` for the `from_string` and operator callback signatures.