Blame exprtok.h

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