]> gitweb.ps.run Git - toc/blobdiff - src/toc.h
complete grammar
[toc] / src / toc.h
index 642bc37d4c74f8df6f85a4ad41188a6c14585376..67f92dc0753648093a1f3b156c48cca6121b1c93 100644 (file)
--- a/src/toc.h
+++ b/src/toc.h
@@ -18,7 +18,9 @@ std::ostream & operator<< (std::ostream & out, const std::vector<T> & v) {
 std::ostream & operator<< (std::ostream & out, const Type & t);\r
 std::ostream & operator<< (std::ostream & out, const Variable & v);\r
 std::ostream & operator<< (std::ostream & out, const Body & b);\r
 std::ostream & operator<< (std::ostream & out, const Type & t);\r
 std::ostream & operator<< (std::ostream & out, const Variable & v);\r
 std::ostream & operator<< (std::ostream & out, const Body & b);\r
-std::ostream & operator<< (std::ostream & out, const OperatorExpr & o);\r
+std::ostream & operator<< (std::ostream & out, const UnaryOperatorExpr & o);\r
+std::ostream & operator<< (std::ostream & out, const BinaryOperatorExpr & o);\r
+std::ostream & operator<< (std::ostream & out, const TernaryOperatorExpr & o);\r
 std::ostream & operator<< (std::ostream & out, const Expr & e);\r
 std::ostream & operator<< (std::ostream & out, const Stmt & s);\r
 \r
 std::ostream & operator<< (std::ostream & out, const Expr & e);\r
 std::ostream & operator<< (std::ostream & out, const Stmt & s);\r
 \r
@@ -65,21 +67,23 @@ std::ostream & operator<< (std::ostream & out, const Body & b) {
 \r
   return out;\r
 }\r
 \r
   return out;\r
 }\r
-std::ostream & operator<< (std::ostream & out, const OperatorExpr & o) {\r
-  out << *o.lexpr << " ";\r
-\r
-  switch (o.type) {\r
-  case OperatorType::Plus:        out << "+"; break;\r
-  case OperatorType::Minus:       out << "-"; break;\r
-  case OperatorType::Multiply:    out << "*"; break;\r
-  case OperatorType::Divide:      out << "/"; break;\r
-  case OperatorType::Equals:      out << "=="; break;\r
-  case OperatorType::NotEquals:   out << "!="; break;\r
-  case OperatorType::LessThan:    out << "<"; break;\r
-  case OperatorType::GreaterThan: out << ">"; break;\r
+std::ostream & operator<< (std::ostream & out, const UnaryOperatorExpr & o) {\r
+  if (o.type == UnaryOperatorType::IncrementPost || o.type == UnaryOperatorType::DecrementPost) {\r
+    out << UnaryOperatorTypeStrings[(int)o.type] << *o.expr;\r
+  }\r
+  else {\r
+    out << *o.expr << UnaryOperatorTypeStrings[(int)o.type];\r
   }\r
 \r
   }\r
 \r
-  out << " " << *o.rexpr;\r
+  return out;\r
+}\r
+std::ostream & operator<< (std::ostream & out, const BinaryOperatorExpr & o) {\r
+  out << *o.lexpr << " " << BinaryOperatorTypeStrings[(int)o.type] << " " << *o.rexpr;\r
+\r
+  return out;\r
+}\r
+std::ostream & operator<< (std::ostream & out, const TernaryOperatorExpr & o) {\r
+  out << *o.lexpr << " ? " << *o.rexprTrue << " : " << *o.rexprFalse;\r
 \r
   return out;\r
 }\r
 \r
   return out;\r
 }\r