xo-reader: feat: parse infix exprs for +,-,*,/ operators

This commit is contained in:
Roland Conybeare 2024-08-14 23:44:17 -04:00
commit 29596a7c1d
5 changed files with 141 additions and 8 deletions

View file

@ -121,6 +121,10 @@ namespace xo {
virtual void on_rightparen_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr);
/** handle incoming operator token **/
virtual void on_operator_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr);
/** handle incoming floating-point-literal token **/
virtual void on_f64_token(const token_type & tk,
exprstatestack * p_stack,

View file

@ -10,6 +10,18 @@
namespace xo {
namespace scm {
/* represent an infix operator */
enum class optype {
invalid = -1,
op_add,
op_subtract,
op_multiply,
op_divide,
n_optype
};
/** @class progress_xs
* @brief state machine for parsing a schematica runtime-value-expression
**/
@ -49,6 +61,12 @@ namespace xo {
virtual void on_rightparen_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * /*p_emit_expr*/) override;
/* entry point for an infix operator token */
virtual void on_operator_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * p_emit_expr) override;
virtual void on_f64_token(const token_type & tk,
exprstatestack * p_stack,
rp<Expression> * /*p_emit_expr*/) override;
@ -58,6 +76,9 @@ namespace xo {
private:
/** populate an expression here **/
rp<Expression> gen_expr_;
/** infix operator, if supplied **/
optype op_type_ = optype::invalid;
};
} /*namespace scm*/
} /*namespace xo*/