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 { ASSOC_LEFT, ASSOC_RIGHT, ASSOC_NONE } assoc;
const enum { OP_INFIX, OP_PREFIX, OP_POSTFIX } fix; const enum { OP_INFIX, OP_PREFIX, OP_POSTFIX } fix;
} ops[] = { } ops[] = {
# define OP(Op, Kind, Prio, Assoc, Fix) \ # define OP(Kind, Prio, Assoc, Fix, /* Operator string */ ...) \
[Kind] = { #Op, Kind, Prio, Assoc, Fix }, [Kind] = { (const char[]){__VA_ARGS__}, Kind, Prio, Assoc, Fix, },
#include "operators.inc" #include "operators.inc"
}; };

View file

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