Merge branch 'main' of github.com:Rconybea/xo-reader
This commit is contained in:
commit
fda9889207
8 changed files with 356 additions and 21 deletions
|
|
@ -125,6 +125,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,
|
||||
|
|
|
|||
26
include/xo/reader/lambda_xs.hpp
Normal file
26
include/xo/reader/lambda_xs.hpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
/** @file lambda_xs.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "exprstate.hpp"
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class lambda_xs
|
||||
* @brief parsing state-machine for a lambda-expression
|
||||
**/
|
||||
class lambda_xs : public exprstate {
|
||||
public:
|
||||
lambda_xs();
|
||||
|
||||
private:
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/** end lambda_xs.hpp **/
|
||||
|
|
@ -6,23 +6,49 @@
|
|||
#pragma once
|
||||
|
||||
#include "exprstate.hpp"
|
||||
#include <iostream>
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/* represent an infix operator */
|
||||
enum class optype {
|
||||
invalid = -1,
|
||||
|
||||
op_add,
|
||||
op_subtract,
|
||||
op_multiply,
|
||||
op_divide,
|
||||
|
||||
n_optype
|
||||
};
|
||||
|
||||
extern const char *
|
||||
optype_descr(optype x);
|
||||
|
||||
extern int
|
||||
precedence(optype x);
|
||||
|
||||
inline std::ostream &
|
||||
operator<< (std::ostream & os, optype x) {
|
||||
os << optype_descr(x);
|
||||
return os;
|
||||
}
|
||||
|
||||
/** @class progress_xs
|
||||
* @brief state machine for parsing a schematica runtime-value-expression
|
||||
**/
|
||||
class progress_xs : public exprstate {
|
||||
public:
|
||||
progress_xs(rp<Expression> valex);
|
||||
progress_xs(rp<Expression> valex, optype op);
|
||||
virtual ~progress_xs() = default;
|
||||
|
||||
static const progress_xs * from(const exprstate * x) {
|
||||
return dynamic_cast<const progress_xs *>(x);
|
||||
}
|
||||
|
||||
static std::unique_ptr<progress_xs> make(rp<Expression> valex);
|
||||
static std::unique_ptr<progress_xs> make(rp<Expression> valex,
|
||||
optype optype = optype::invalid);
|
||||
|
||||
bool admits_f64() const;
|
||||
|
||||
|
|
@ -51,6 +77,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,8 +90,25 @@ namespace xo {
|
|||
virtual void print(std::ostream & os) const override;
|
||||
|
||||
private:
|
||||
/** populate an expression here **/
|
||||
rp<Expression> gen_expr_;
|
||||
/** assemble expression representing
|
||||
* value of
|
||||
* @code
|
||||
* f(lhs_, rhs_)
|
||||
* @endcode
|
||||
*
|
||||
* where f determined by @ref op_type_
|
||||
**/
|
||||
rp<Expression> assemble_expr();
|
||||
|
||||
private:
|
||||
/** populate an expression here, may be followed by an operator **/
|
||||
rp<Expression> lhs_;
|
||||
|
||||
/** infix operator, if supplied **/
|
||||
optype op_type_ = optype::invalid;
|
||||
|
||||
/** populate an expression here, following infix operator */
|
||||
rp<Expression> rhs_;
|
||||
};
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue