1/*- 2 * Copyright (c) 2016 3 * mirabilos <m@mirbsd.org> 4 * 5 * Provided that these terms and disclaimer and all copyright notices 6 * are retained or reproduced in an accompanying document, permission 7 * is granted to deal in this work without restriction, including un- 8 * limited rights to use, publicly perform, distribute, sell, modify, 9 * merge, give away, or sublicence. 10 * 11 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to 12 * the utmost extent permitted by applicable law, neither express nor 13 * implied; without malicious intent or gross negligence. In no event 14 * may a licensor, author or contributor be held liable for indirect, 15 * direct, other damage, loss, or other issues arising in any way out 16 * of dealing in the work, even if advised of the possibility of such 17 * damage or existence of a defect, except proven that it results out 18 * of said person's immediate fault when using the work as intended. 19 */ 20 21#if defined(EXPRTOK_DEFNS) 22__RCSID("$MirOS: src/bin/mksh/exprtok.h,v 1.2 2016/08/12 16:48:05 tg Exp $"); 23/* see range comment below */ 24#define IS_ASSIGNOP(op) ((int)(op) >= (int)O_ASN && (int)(op) <= (int)O_BORASN) 25#define FN(name, len, prec, enum) /* nothing */ 26#define F1(enum) /* nothing */ 27#elif defined(EXPRTOK_ENUM) 28#define F0(name, len, prec, enum) enum = 0, 29#define FN(name, len, prec, enum) enum, 30#define F1(enum) enum, 31#define F2(enum) enum, 32#define F9(enum) enum 33#elif defined(EXPRTOK_NAME) 34#define FN(name, len, prec, enum) name, 35#define F1(enum) "" 36#elif defined(EXPRTOK_LEN) 37#define FN(name, len, prec, enum) len, 38#define F1(enum) 0 39#elif defined(EXPRTOK_PREC) 40#define FN(name, len, prec, enum) prec, 41#define F1(enum) P_PRIMARY 42#endif 43 44#ifndef F0 45#define F0 FN 46#endif 47 48#ifndef F2 49#define F2(enum) /* nothing */ 50#define F9(enum) /* nothing */ 51#endif 52 53/* tokens must be ordered so the longest are first (e.g. += before +) */ 54 55/* some (long) unary operators */ 56FN("++", 2, P_PRIMARY, O_PLUSPLUS = 0) /* before + */ 57FN("--", 2, P_PRIMARY, O_MINUSMINUS) /* before - */ 58/* binary operators */ 59FN("==", 2, P_EQUALITY, O_EQ) /* before = */ 60FN("!=", 2, P_EQUALITY, O_NE) /* before ! */ 61/* assignments are assumed to be in range O_ASN .. O_BORASN */ 62FN("=", 1, P_ASSIGN, O_ASN) 63FN("*=", 2, P_ASSIGN, O_TIMESASN) 64FN("/=", 2, P_ASSIGN, O_DIVASN) 65FN("%=", 2, P_ASSIGN, O_MODASN) 66FN("+=", 2, P_ASSIGN, O_PLUSASN) 67FN("-=", 2, P_ASSIGN, O_MINUSASN) 68#ifndef MKSH_LEGACY_MODE 69FN("^<=", 3, P_ASSIGN, O_ROLASN) /* before ^< */ 70FN("^>=", 3, P_ASSIGN, O_RORASN) /* before ^> */ 71#endif 72FN("<<=", 3, P_ASSIGN, O_LSHIFTASN) 73FN(">>=", 3, P_ASSIGN, O_RSHIFTASN) 74FN("&=", 2, P_ASSIGN, O_BANDASN) 75FN("^=", 2, P_ASSIGN, O_BXORASN) 76FN("|=", 2, P_ASSIGN, O_BORASN) 77/* binary non-assignment operators */ 78#ifndef MKSH_LEGACY_MODE 79FN("^<", 2, P_SHIFT, O_ROL) /* before ^ */ 80FN("^>", 2, P_SHIFT, O_ROR) /* before ^ */ 81#endif 82FN("<<", 2, P_SHIFT, O_LSHIFT) 83FN(">>", 2, P_SHIFT, O_RSHIFT) 84FN("<=", 2, P_RELATION, O_LE) 85FN(">=", 2, P_RELATION, O_GE) 86FN("<", 1, P_RELATION, O_LT) 87FN(">", 1, P_RELATION, O_GT) 88FN("&&", 2, P_LAND, O_LAND) 89FN("||", 2, P_LOR, O_LOR) 90FN("*", 1, P_MULT, O_TIMES) 91FN("/", 1, P_MULT, O_DIV) 92FN("%", 1, P_MULT, O_MOD) 93FN("+", 1, P_ADD, O_PLUS) 94FN("-", 1, P_ADD, O_MINUS) 95FN("&", 1, P_BAND, O_BAND) 96FN("^", 1, P_BXOR, O_BXOR) 97FN("|", 1, P_BOR, O_BOR) 98FN("?", 1, P_TERN, O_TERN) 99FN(",", 1, P_COMMA, O_COMMA) 100/* things after this aren't used as binary operators */ 101/* unary that are not also binaries */ 102FN("~", 1, P_PRIMARY, O_BNOT) 103FN("!", 1, P_PRIMARY, O_LNOT) 104/* misc */ 105FN("(", 1, P_PRIMARY, OPEN_PAREN) 106FN(")", 1, P_PRIMARY, CLOSE_PAREN) 107FN(":", 1, P_PRIMARY, CTERN) 108/* things that don't appear in the opinfo[] table */ 109F1(VAR) /*XXX should be F2 */ 110F2(LIT) 111F2(END) 112F9(BAD) 113 114#undef FN 115#undef F0 116#undef F1 117#undef F2 118#undef F9 119#undef EXPRTOK_DEFNS 120#undef EXPRTOK_ENUM 121#undef EXPRTOK_NAME 122#undef EXPRTOK_LEN 123#undef EXPRTOK_PREC 124