evalexpr: parse: simplify operators table
This commit is contained in:
parent
793a6c6f6f
commit
d82bf6e77b
|
@ -17,11 +17,7 @@ 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 BINOP(Op, Kind, Prio, Assoc, Fix) \
|
# define OP(Op, Kind, Prio, Assoc, Fix) \
|
||||||
[Kind] = { #Op, Kind, Prio, Assoc, Fix },
|
|
||||||
# define PREOP(Op, Kind, Prio, Assoc, Fix) \
|
|
||||||
[Kind] = { #Op, Kind, Prio, Assoc, Fix },
|
|
||||||
# define POSTOP(Op, Kind, Prio, Assoc, Fix) \
|
|
||||||
[Kind] = { #Op, Kind, Prio, Assoc, Fix },
|
[Kind] = { #Op, Kind, Prio, Assoc, Fix },
|
||||||
#include "operators.inc"
|
#include "operators.inc"
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,25 +10,32 @@
|
||||||
* G, the operand, is parsed by a specific function to start the process.
|
* G, the operand, is parsed by a specific function to start the process.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef OP
|
||||||
|
# define OP(Op, Kind, Prio, Assoc, Fix)
|
||||||
|
#endif
|
||||||
#ifndef BINOP
|
#ifndef BINOP
|
||||||
# define BINOP(_, __, ___, ____, _____)
|
# define BINOP(Op, Kind, Prio, Assoc) \
|
||||||
|
OP(Op, Kind, Prio, Assoc, OP_INFIX)
|
||||||
#endif
|
#endif
|
||||||
#ifndef PREOP
|
#ifndef PREOP
|
||||||
# define PREOP(_, __, ___, ____, _____)
|
# define PREOP(Op, Kind, Prio, Assoc) \
|
||||||
|
OP(Op, Kind, Prio, Assoc, OP_PREFIX)
|
||||||
#endif
|
#endif
|
||||||
#ifndef POSTOP
|
#ifndef POSTOP
|
||||||
# define POSTOP(_, __, ___, ____, _____)
|
# define POSTOP(Op, Kind, Prio, Assoc) \
|
||||||
|
OP(Op, Kind, Prio, Assoc, OP_POSTFIX)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
BINOP(+, BINOP_PLUS, 1, ASSOC_LEFT, OP_INFIX)
|
BINOP(+, BINOP_PLUS, 1, ASSOC_LEFT)
|
||||||
BINOP(-, BINOP_MINUS, 1, ASSOC_LEFT, OP_INFIX)
|
BINOP(-, BINOP_MINUS, 1, ASSOC_LEFT)
|
||||||
BINOP(*, BINOP_TIMES, 2, ASSOC_LEFT, OP_INFIX)
|
BINOP(*, BINOP_TIMES, 2, ASSOC_LEFT)
|
||||||
BINOP(/, BINOP_DIVIDES, 2, ASSOC_LEFT, OP_INFIX)
|
BINOP(/, BINOP_DIVIDES, 2, ASSOC_LEFT)
|
||||||
BINOP(^, BINOP_POW, 4, ASSOC_RIGHT, OP_INFIX)
|
BINOP(^, BINOP_POW, 4, ASSOC_RIGHT)
|
||||||
PREOP(-, UNOP_NEGATE, 3, ASSOC_RIGHT, OP_PREFIX)
|
PREOP(-, UNOP_NEGATE, 3, ASSOC_RIGHT)
|
||||||
PREOP(+, UNOP_IDENTITY, 3, ASSOC_RIGHT, OP_PREFIX)
|
PREOP(+, UNOP_IDENTITY, 3, ASSOC_RIGHT)
|
||||||
POSTOP(!, UNOP_FACT, 5, ASSOC_NONE, OP_POSTFIX)
|
POSTOP(!, UNOP_FACT, 5, ASSOC_NONE)
|
||||||
|
|
||||||
#undef BINOP
|
#undef BINOP
|
||||||
#undef PREOP
|
#undef PREOP
|
||||||
#undef POSTOP
|
#undef POSTOP
|
||||||
|
#undef OP
|
||||||
|
|
Loading…
Reference in a new issue