From 5f9668526491332f62c05ad831dbf6d5fdc2b6d0 Mon Sep 17 00:00:00 2001 From: Patrick Schönberger Date: Fri, 30 Jul 2021 18:32:33 +0200 Subject: complete grammar --- src/toc.h | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) (limited to 'src/toc.h') diff --git a/src/toc.h b/src/toc.h index 642bc37..67f92dc 100644 --- a/src/toc.h +++ b/src/toc.h @@ -18,7 +18,9 @@ std::ostream & operator<< (std::ostream & out, const std::vector & v) { std::ostream & operator<< (std::ostream & out, const Type & t); std::ostream & operator<< (std::ostream & out, const Variable & v); std::ostream & operator<< (std::ostream & out, const Body & b); -std::ostream & operator<< (std::ostream & out, const OperatorExpr & o); +std::ostream & operator<< (std::ostream & out, const UnaryOperatorExpr & o); +std::ostream & operator<< (std::ostream & out, const BinaryOperatorExpr & o); +std::ostream & operator<< (std::ostream & out, const TernaryOperatorExpr & o); std::ostream & operator<< (std::ostream & out, const Expr & e); std::ostream & operator<< (std::ostream & out, const Stmt & s); @@ -65,21 +67,23 @@ std::ostream & operator<< (std::ostream & out, const Body & b) { return out; } -std::ostream & operator<< (std::ostream & out, const OperatorExpr & o) { - out << *o.lexpr << " "; - - switch (o.type) { - case OperatorType::Plus: out << "+"; break; - case OperatorType::Minus: out << "-"; break; - case OperatorType::Multiply: out << "*"; break; - case OperatorType::Divide: out << "/"; break; - case OperatorType::Equals: out << "=="; break; - case OperatorType::NotEquals: out << "!="; break; - case OperatorType::LessThan: out << "<"; break; - case OperatorType::GreaterThan: out << ">"; break; +std::ostream & operator<< (std::ostream & out, const UnaryOperatorExpr & o) { + if (o.type == UnaryOperatorType::IncrementPost || o.type == UnaryOperatorType::DecrementPost) { + out << UnaryOperatorTypeStrings[(int)o.type] << *o.expr; + } + else { + out << *o.expr << UnaryOperatorTypeStrings[(int)o.type]; } - out << " " << *o.rexpr; + return out; +} +std::ostream & operator<< (std::ostream & out, const BinaryOperatorExpr & o) { + out << *o.lexpr << " " << BinaryOperatorTypeStrings[(int)o.type] << " " << *o.rexpr; + + return out; +} +std::ostream & operator<< (std::ostream & out, const TernaryOperatorExpr & o) { + out << *o.lexpr << " ? " << *o.rexprTrue << " : " << *o.rexprFalse; return out; } -- cgit v1.2.3