Blame exprtok.h

Packit Service 95ac19
/*-
Packit Service 95ac19
 * Copyright (c) 2016
Packit Service 95ac19
 *	mirabilos <m@mirbsd.org>
Packit Service 95ac19
 *
Packit Service 95ac19
 * Provided that these terms and disclaimer and all copyright notices
Packit Service 95ac19
 * are retained or reproduced in an accompanying document, permission
Packit Service 95ac19
 * is granted to deal in this work without restriction, including un-
Packit Service 95ac19
 * limited rights to use, publicly perform, distribute, sell, modify,
Packit Service 95ac19
 * merge, give away, or sublicence.
Packit Service 95ac19
 *
Packit Service 95ac19
 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
Packit Service 95ac19
 * the utmost extent permitted by applicable law, neither express nor
Packit Service 95ac19
 * implied; without malicious intent or gross negligence. In no event
Packit Service 95ac19
 * may a licensor, author or contributor be held liable for indirect,
Packit Service 95ac19
 * direct, other damage, loss, or other issues arising in any way out
Packit Service 95ac19
 * of dealing in the work, even if advised of the possibility of such
Packit Service 95ac19
 * damage or existence of a defect, except proven that it results out
Packit Service 95ac19
 * of said person's immediate fault when using the work as intended.
Packit Service 95ac19
 */
Packit Service 95ac19
Packit Service 95ac19
#if defined(EXPRTOK_DEFNS)
Packit Service 95ac19
__RCSID("$MirOS: src/bin/mksh/exprtok.h,v 1.2 2016/08/12 16:48:05 tg Exp $");
Packit Service 95ac19
/* see range comment below */
Packit Service 95ac19
#define IS_ASSIGNOP(op) ((int)(op) >= (int)O_ASN && (int)(op) <= (int)O_BORASN)
Packit Service 95ac19
#define FN(name, len, prec, enum)	/* nothing */
Packit Service 95ac19
#define F1(enum)			/* nothing */
Packit Service 95ac19
#elif defined(EXPRTOK_ENUM)
Packit Service 95ac19
#define F0(name, len, prec, enum)	enum = 0,
Packit Service 95ac19
#define FN(name, len, prec, enum)	enum,
Packit Service 95ac19
#define F1(enum)			enum,
Packit Service 95ac19
#define F2(enum)			enum,
Packit Service 95ac19
#define F9(enum)			enum
Packit Service 95ac19
#elif defined(EXPRTOK_NAME)
Packit Service 95ac19
#define FN(name, len, prec, enum)	name,
Packit Service 95ac19
#define F1(enum)			""
Packit Service 95ac19
#elif defined(EXPRTOK_LEN)
Packit Service 95ac19
#define FN(name, len, prec, enum)	len,
Packit Service 95ac19
#define F1(enum)			0
Packit Service 95ac19
#elif defined(EXPRTOK_PREC)
Packit Service 95ac19
#define FN(name, len, prec, enum)	prec,
Packit Service 95ac19
#define F1(enum)			P_PRIMARY
Packit Service 95ac19
#endif
Packit Service 95ac19
Packit Service 95ac19
#ifndef F0
Packit Service 95ac19
#define F0 FN
Packit Service 95ac19
#endif
Packit Service 95ac19
Packit Service 95ac19
#ifndef F2
Packit Service 95ac19
#define F2(enum)			/* nothing */
Packit Service 95ac19
#define F9(enum)			/* nothing */
Packit Service 95ac19
#endif
Packit Service 95ac19
Packit Service 95ac19
/* tokens must be ordered so the longest are first (e.g. += before +) */
Packit Service 95ac19
Packit Service 95ac19
/* some (long) unary operators */
Packit Service 95ac19
FN("++", 2, P_PRIMARY, O_PLUSPLUS = 0)	/* before + */
Packit Service 95ac19
FN("--", 2, P_PRIMARY, O_MINUSMINUS)	/* before - */
Packit Service 95ac19
/* binary operators */
Packit Service 95ac19
FN("==", 2, P_EQUALITY, O_EQ)		/* before = */
Packit Service 95ac19
FN("!=", 2, P_EQUALITY, O_NE)		/* before ! */
Packit Service 95ac19
/* assignments are assumed to be in range O_ASN .. O_BORASN */
Packit Service 95ac19
FN("=", 1, P_ASSIGN, O_ASN)
Packit Service 95ac19
FN("*=", 2, P_ASSIGN, O_TIMESASN)
Packit Service 95ac19
FN("/=", 2, P_ASSIGN, O_DIVASN)
Packit Service 95ac19
FN("%=", 2, P_ASSIGN, O_MODASN)
Packit Service 95ac19
FN("+=", 2, P_ASSIGN, O_PLUSASN)
Packit Service 95ac19
FN("-=", 2, P_ASSIGN, O_MINUSASN)
Packit Service 95ac19
#ifndef MKSH_LEGACY_MODE
Packit Service 95ac19
FN("^<=", 3, P_ASSIGN, O_ROLASN)	/* before ^< */
Packit Service 95ac19
FN("^>=", 3, P_ASSIGN, O_RORASN)	/* before ^> */
Packit Service 95ac19
#endif
Packit Service 95ac19
FN("<<=", 3, P_ASSIGN, O_LSHIFTASN)
Packit Service 95ac19
FN(">>=", 3, P_ASSIGN, O_RSHIFTASN)
Packit Service 95ac19
FN("&=", 2, P_ASSIGN, O_BANDASN)
Packit Service 95ac19
FN("^=", 2, P_ASSIGN, O_BXORASN)
Packit Service 95ac19
FN("|=", 2, P_ASSIGN, O_BORASN)
Packit Service 95ac19
/* binary non-assignment operators */
Packit Service 95ac19
#ifndef MKSH_LEGACY_MODE
Packit Service 95ac19
FN("^<", 2, P_SHIFT, O_ROL)		/* before ^ */
Packit Service 95ac19
FN("^>", 2, P_SHIFT, O_ROR)		/* before ^ */
Packit Service 95ac19
#endif
Packit Service 95ac19
FN("<<", 2, P_SHIFT, O_LSHIFT)
Packit Service 95ac19
FN(">>", 2, P_SHIFT, O_RSHIFT)
Packit Service 95ac19
FN("<=", 2, P_RELATION, O_LE)
Packit Service 95ac19
FN(">=", 2, P_RELATION, O_GE)
Packit Service 95ac19
FN("<", 1, P_RELATION, O_LT)
Packit Service 95ac19
FN(">", 1, P_RELATION, O_GT)
Packit Service 95ac19
FN("&&", 2, P_LAND, O_LAND)
Packit Service 95ac19
FN("||", 2, P_LOR, O_LOR)
Packit Service 95ac19
FN("*", 1, P_MULT, O_TIMES)
Packit Service 95ac19
FN("/", 1, P_MULT, O_DIV)
Packit Service 95ac19
FN("%", 1, P_MULT, O_MOD)
Packit Service 95ac19
FN("+", 1, P_ADD, O_PLUS)
Packit Service 95ac19
FN("-", 1, P_ADD, O_MINUS)
Packit Service 95ac19
FN("&", 1, P_BAND, O_BAND)
Packit Service 95ac19
FN("^", 1, P_BXOR, O_BXOR)
Packit Service 95ac19
FN("|", 1, P_BOR, O_BOR)
Packit Service 95ac19
FN("?", 1, P_TERN, O_TERN)
Packit Service 95ac19
FN(",", 1, P_COMMA, O_COMMA)
Packit Service 95ac19
/* things after this aren't used as binary operators */
Packit Service 95ac19
/* unary that are not also binaries */
Packit Service 95ac19
FN("~", 1, P_PRIMARY, O_BNOT)
Packit Service 95ac19
FN("!", 1, P_PRIMARY, O_LNOT)
Packit Service 95ac19
/* misc */
Packit Service 95ac19
FN("(", 1, P_PRIMARY, OPEN_PAREN)
Packit Service 95ac19
FN(")", 1, P_PRIMARY, CLOSE_PAREN)
Packit Service 95ac19
FN(":", 1, P_PRIMARY, CTERN)
Packit Service 95ac19
/* things that don't appear in the opinfo[] table */
Packit Service 95ac19
F1(VAR)				/*XXX should be F2 */
Packit Service 95ac19
F2(LIT)
Packit Service 95ac19
F2(END)
Packit Service 95ac19
F9(BAD)
Packit Service 95ac19
Packit Service 95ac19
#undef FN
Packit Service 95ac19
#undef F0
Packit Service 95ac19
#undef F1
Packit Service 95ac19
#undef F2
Packit Service 95ac19
#undef F9
Packit Service 95ac19
#undef EXPRTOK_DEFNS
Packit Service 95ac19
#undef EXPRTOK_ENUM
Packit Service 95ac19
#undef EXPRTOK_NAME
Packit Service 95ac19
#undef EXPRTOK_LEN
Packit Service 95ac19
#undef EXPRTOK_PREC