evalexpr: parse: prepare for multi-char operators

This commit is contained in:
Bruno BELANYI 2020-10-31 16:27:42 +01:00
parent 0ac03f94d0
commit 10c7a96deb
2 changed files with 17 additions and 17 deletions

View file

@ -17,8 +17,8 @@ static const struct {
const enum { ASSOC_LEFT, ASSOC_RIGHT, ASSOC_NONE } assoc;
const enum { OP_INFIX, OP_PREFIX, OP_POSTFIX } fix;
} ops[] = {
# define OP(Op, Kind, Prio, Assoc, Fix) \
[Kind] = { #Op, Kind, Prio, Assoc, Fix },
# define OP(Kind, Prio, Assoc, Fix, /* Operator string */ ...) \
[Kind] = { (const char[]){__VA_ARGS__}, Kind, Prio, Assoc, Fix, },
#include "operators.inc"
};

View file

@ -11,29 +11,29 @@
*/
#ifndef OP
# define OP(Op, Kind, Prio, Assoc, Fix)
# define OP(Kind, Prio, Assoc, Fix, /* Operator string */ ...)
#endif
#ifndef BINOP
# define BINOP(Op, Kind, Prio, Assoc) \
OP(Op, Kind, Prio, Assoc, OP_INFIX)
# define BINOP(Kind, Prio, Assoc, ...) \
OP(Kind, Prio, Assoc, OP_INFIX, __VA_ARGS__)
#endif
#ifndef PREOP
# define PREOP(Op, Kind, Prio, Assoc) \
OP(Op, Kind, Prio, Assoc, OP_PREFIX)
# define PREOP(Kind, Prio, Assoc, ...) \
OP(Kind, Prio, Assoc, OP_PREFIX, __VA_ARGS__)
#endif
#ifndef POSTOP
# define POSTOP(Op, Kind, Prio, Assoc) \
OP(Op, Kind, Prio, Assoc, OP_POSTFIX)
# define POSTOP(Kind, Prio, Assoc, ...) \
OP(Kind, Prio, Assoc, OP_POSTFIX, __VA_ARGS__)
#endif
BINOP(+, BINOP_PLUS, 1, ASSOC_LEFT)
BINOP(-, BINOP_MINUS, 1, ASSOC_LEFT)
BINOP(*, BINOP_TIMES, 2, ASSOC_LEFT)
BINOP(/, BINOP_DIVIDES, 2, ASSOC_LEFT)
BINOP(^, BINOP_POW, 4, ASSOC_RIGHT)
PREOP(-, UNOP_NEGATE, 3, ASSOC_RIGHT)
PREOP(+, UNOP_IDENTITY, 3, ASSOC_RIGHT)
POSTOP(!, UNOP_FACT, 5, ASSOC_NONE)
BINOP (BINOP_PLUS, 1, ASSOC_LEFT, '+', 0)
BINOP (BINOP_MINUS, 1, ASSOC_LEFT, '-', 0)
BINOP (BINOP_TIMES, 2, ASSOC_LEFT, '*', 0)
BINOP (BINOP_DIVIDES, 2, ASSOC_LEFT, '/', 0)
BINOP (BINOP_POW, 4, ASSOC_RIGHT, '^', 0)
PREOP (UNOP_NEGATE, 3, ASSOC_RIGHT, '-', 0)
PREOP (UNOP_IDENTITY, 3, ASSOC_RIGHT, '+', 0)
POSTOP(UNOP_FACT, 5, ASSOC_NONE, '!', 0)
#undef BINOP
#undef PREOP