pkarashchenko commented on a change in pull request #5690:
URL: https://github.com/apache/incubator-nuttx/pull/5690#discussion_r821546914



##########
File path: libs/libc/locale/lib_gettext.c
##########
@@ -195,6 +213,272 @@ static FAR char *molookup(FAR char *p, size_t size, FAR 
const char *s)
   return NULL;
 }
 
+static FAR const char *skipspace(FAR const char *s)
+{
+  while (isspace(*s))
+    {
+      s++;
+    }
+
+  return s;
+}
+
+/* Grammar:
+ *
+ * Start = Expr ';'
+ * Expr  = Or | Or '?' Expr ':' Expr
+ * Or    = And | Or '||' And
+ * And   = Eq | And '&&' Eq
+ * Eq    = Rel | Eq '==' Rel | Eq '!=' Rel
+ * Rel   = Add | Rel '<=' Add | Rel '>=' Add | Rel '<' Add | Rel '>' Add
+ * Add   = Mul | Add '+' Mul | Add '-' Mul
+ * Mul   = Prim | Mul '*' Prim | Mul '/' Prim | Mul '%' Prim
+ * Prim  = '(' Expr ')' | '!' Prim | decimal | 'n'
+ *
+ * Internals:
+ *
+ * Recursive descent expression evaluator with stack depth limit.
+ * for binary operators an operator-precedence parser is used.
+ * eval* functions store the result of the parsed subexpression
+ * and return a pointer to the next non-space character.
+ */
+
+static FAR const char *evalprim(FAR struct eval_s *ev,
+                                FAR const char *s, int d)
+{
+  FAR char *e;
+
+  if (--d < 0)
+    {
+      return "";
+    }
+
+  s = skipspace(s);
+  if (isdigit(*s))
+    {
+      ev->r = strtoul(s, &e, 10);
+      if (e == s || ev->r == -1)
+        {
+          return "";
+        }
+
+      return skipspace(e);
+    }
+
+  if (*s == 'n')
+    {
+      ev->r = ev->n;
+      return skipspace(s + 1);
+    }
+
+  if (*s == '(')
+    {
+      s = evalexpr(ev, s + 1, d);
+      if (*s != ')')
+        {
+          return "";
+        }
+
+      return skipspace(s + 1);
+    }
+
+  if (*s == '!')
+    {
+      s = evalprim(ev, s + 1, d);
+      ev->r = !ev->r;
+      return s;
+    }
+
+  return "";
+}
+
+static bool binop(FAR struct eval_s *ev, int op, unsigned long left)
+{
+  unsigned long a = left;
+  unsigned long b = ev->r;
+
+  switch (op)
+    {
+      case 0:
+        ev->r = a || b;
+        return true;
+
+      case 1:
+        ev->r = a && b;
+        return true;
+
+      case 2:
+        ev->r = a == b;
+        return true;
+
+      case 3:
+        ev->r = a != b;
+        return true;
+
+      case 4:
+        ev->r = a >= b;
+        return true;
+
+      case 5:
+        ev->r = a <= b;
+        return true;
+
+      case 6:
+        ev->r = a > b;
+        return true;
+
+      case 7:
+        ev->r = a < b;
+        return true;
+
+      case 8:
+        ev->r = a + b;
+        return true;
+
+      case 9:
+        ev->r = a - b;
+        return true;
+
+      case 10:
+        ev->r = a * b;
+        return true;
+
+      case 11:
+        if (b)
+          {
+            ev->r = a % b;
+            return true;
+          }
+
+        return false;
+
+      case 12:
+        if (b)
+          {
+            ev->r = a / b;
+            return true;
+          }
+
+        return false;

Review comment:
       should we add a `default:` case? Or there is not compilation warning 
generated?




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to