diff --git a/include/xo/parser/parser.hpp b/include/xo/parser/parser.hpp index 57d4b319..a9dbc198 100644 --- a/include/xo/parser/parser.hpp +++ b/include/xo/parser/parser.hpp @@ -47,30 +47,18 @@ namespace xo { public: exprir() = default; -#ifdef OBSOLETE - exprir(exprirtype xir_type, - const std::string & x) - : xir_type_{xir_type}, symbol_name_{x} {} -#endif - exprir(exprirtype xir_type, - TypeDescr td) - : xir_type_{xir_type}, td_{td} {} + explicit exprir(exprirtype xir_type) + : xir_type_{xir_type} {} exprirtype xir_type() const { return xir_type_; } //const std::string & symbol_name() const { return symbol_name_; } - TypeDescr td() const { return td_; } + //TypeDescr td() const { return td_; } void print(std::ostream & os) const; private: /** IR type code **/ exprirtype xir_type_ = exprirtype::invalid; -#ifdef OBSOLETE - /** xir_type=symbol: a symbol (type or variable) name **/ - std::string symbol_name_; -#endif - /** xir_type=typedescr: object identifying/describing a datatype **/ - TypeDescr td_ = nullptr; }; inline std::ostream & @@ -131,23 +119,13 @@ namespace xo { class expraction { public: expraction() = default; - explicit expraction(expractiontype action_type -#ifdef OBSOLETE - const exprir & expr_ir -#endif - ) + explicit expraction(expractiontype action_type) : action_type_{action_type} -#ifdef OBSOLETE - , expr_ir_{expr_ir} -#endif {} static expraction keep(); expractiontype action_type() const { return action_type_; } -#ifdef OBSOLETE - const exprir & expr_ir() const { return expr_ir_; } -#endif void print(std::ostream & os) const; @@ -160,12 +138,6 @@ namespace xo { * pop: drop exprstate, report exprir to parent **/ expractiontype action_type_ = expractiontype::invalid; -#ifdef OBSOLETE - /** - * intermediate representation (pass to enclosing stack state) - **/ - exprir expr_ir_; -#endif }; inline std::ostream & @@ -228,6 +200,10 @@ namespace xo { void on_symbol(const std::string & symbol, exprstatestack * p_stack, rp * p_emit_expr); + /** update exprstate when expeccting a typedescr **/ + void on_typedescr(TypeDescr td, + exprstatestack * p_stack, + rp * p_emit_expr); /** update exprstate in response to IR (intermediate representation) * from nested parsing task **/ diff --git a/src/parser/parser.cpp b/src/parser/parser.cpp index 600c7191..9eaba07c 100644 --- a/src/parser/parser.cpp +++ b/src/parser/parser.cpp @@ -41,9 +41,6 @@ namespace xo { exprir::print(std::ostream & os) const { os << "short_name()); os << ">"; } @@ -339,9 +336,7 @@ namespace xo { } p_stack->pop_exprstate(); - p_stack->top_exprstate().on_exprir - (exprir(exprirtype::typedescr, td), p_stack, p_emit_expr); - //return expraction::pop(exprir(exprirtype::typedescr, td)); + p_stack->top_exprstate().on_typedescr(td, p_stack, p_emit_expr); return; } @@ -353,6 +348,47 @@ namespace xo { } } + void + exprstate::on_typedescr(TypeDescr td, + exprstatestack * /*p_stack*/, + rp * /*p_emit_expr*/) + { + switch(this->exs_type_) { + case exprstatetype::expect_toplevel_expression_sequence: + case exprstatetype::def_0: + case exprstatetype::def_1: + /* NOT IMPLEMENTED */ + assert(false); + return; + + case exprstatetype::def_2: + this->exs_type_ = exprstatetype::def_3; + this->def_lhs_td_ = td; + + return; + case exprstatetype::def_3: + case exprstatetype::def_4: + /* NOT IMPLEMENTED */ + assert(false); + return; + + case exprstatetype::expect_rhs_expression: + case exprstatetype::expect_type: + case exprstatetype::expect_symbol: + /* unreachable + * (this exprstate issues pop instruction from exprstate::on_input() + */ + assert(false); + return; + + case exprstatetype::invalid: + case exprstatetype::n_exprstatetype: + /* unreachable */ + assert(false); + return; + } + } + void exprstate::on_colon(exprstatestack * p_stack) { constexpr bool c_debug_flag = true; @@ -630,19 +666,10 @@ namespace xo { case exprstatetype::expect_toplevel_expression_sequence: case exprstatetype::def_0: case exprstatetype::def_1: - /* NOT IMPLEMENTED */ - assert(false); - return; case exprstatetype::def_2: - this->exs_type_ = exprstatetype::def_3; - this->def_lhs_td_ = ir.td(); - - return; case exprstatetype::def_3: - /* NOT IMPLEMENTED */ - assert(false); - return; case exprstatetype::def_4: + /* NOT IMPLEMENTED */ assert(false); return;