xo-parser: feat: + assign operator handling [wip, untested]

This commit is contained in:
Roland Conybeare 2024-08-27 16:23:04 -04:00
commit 1145830bb1
2 changed files with 29 additions and 2 deletions

View file

@ -19,8 +19,11 @@ namespace xo {
enum class optype {
invalid = -1,
op_assign,
op_add,
op_subtract,
op_multiply,
op_divide,

View file

@ -4,10 +4,13 @@
#include "exprstatestack.hpp"
#include "expect_expr_xs.hpp"
#include "parserstatemachine.hpp"
#include "xo/expression/AssignExpr.hpp"
#include "xo/expression/Apply.hpp"
namespace xo {
using xo::ast::Expression;
using xo::ast::AssignExpr;
using xo::ast::Variable;
using xo::ast::Apply;
namespace scm {
@ -16,6 +19,8 @@ namespace xo {
switch (x) {
case optype::invalid:
return "?optype";
case optype::op_assign:
return "op:=";
case optype::op_add:
return "op+";
case optype::op_subtract:
@ -37,13 +42,16 @@ namespace xo {
case optype::n_optype:
return 0;
case optype::op_assign:
return 1;
case optype::op_add:
case optype::op_subtract:
return 1;
return 2;
case optype::op_multiply:
case optype::op_divide:
return 2;
return 3;
}
return 0;
@ -108,6 +116,22 @@ namespace xo {
case optype::invalid:
return this->lhs_;
case optype::op_assign:
{
ref::brw<Variable> lhs = Variable::from(this->lhs_);
if (!lhs) {
throw std::runtime_error
(tostr("progress_xs::assemble_expr",
" expect variable on lhs of assignment operator :=",
xtag("lhs", lhs_),
xtag("rhs", rhs_)));
}
return AssignExpr::make(lhs.promote(),
this->rhs_);
}
case optype::op_add:
return Apply::make_add2_f64(this->lhs_,
this->rhs_);