1 /*- 2 * Copyright (c) 2016, 2020 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.4 2020/04/07 11:56:46 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 */ 56 F0("++", 2, P_PRIMARY, O_PLUSPLUS) /* before + */ 57 FN("--", 2, P_PRIMARY, O_MINUSMINUS) /* before - */ 58 /* binary operators */ 59 FN("==", 2, P_EQUALITY, O_EQ) /* before = */ 60 FN("!=", 2, P_EQUALITY, O_NE) /* before ! */ 61 /* assignments are assumed to be in range O_ASN .. O_BORASN */ 62 FN("=", 1, P_ASSIGN, O_ASN) 63 FN("*=", 2, P_ASSIGN, O_TIMESASN) 64 FN("/=", 2, P_ASSIGN, O_DIVASN) 65 FN("%=", 2, P_ASSIGN, O_MODASN) 66 FN("+=", 2, P_ASSIGN, O_PLUSASN) 67 FN("-=", 2, P_ASSIGN, O_MINUSASN) 68 #ifndef MKSH_LEGACY_MODE 69 FN("^<=", 3, P_ASSIGN, O_ROLASN) /* before ^< */ 70 FN("^>=", 3, P_ASSIGN, O_RORASN) /* before ^> */ 71 #endif 72 FN("<<=", 3, P_ASSIGN, O_LSHIFTASN) 73 FN(">>=", 3, P_ASSIGN, O_RSHIFTASN) 74 FN("&=", 2, P_ASSIGN, O_BANDASN) 75 FN("^=", 2, P_ASSIGN, O_BXORASN) 76 FN("|=", 2, P_ASSIGN, O_BORASN) 77 /* binary non-assignment operators */ 78 #ifndef MKSH_LEGACY_MODE 79 FN("^<", 2, P_SHIFT, O_ROL) /* before ^ */ 80 FN("^>", 2, P_SHIFT, O_ROR) /* before ^ */ 81 #endif 82 FN("<<", 2, P_SHIFT, O_LSHIFT) 83 FN(">>", 2, P_SHIFT, O_RSHIFT) 84 FN("<=", 2, P_RELATION, O_LE) 85 FN(">=", 2, P_RELATION, O_GE) 86 FN("<", 1, P_RELATION, O_LT) 87 FN(">", 1, P_RELATION, O_GT) 88 FN("&&", 2, P_LAND, O_LAND) 89 FN("||", 2, P_LOR, O_LOR) 90 FN("*", 1, P_MULT, O_TIMES) 91 FN("/", 1, P_MULT, O_DIV) 92 FN("%", 1, P_MULT, O_MOD) 93 FN("+", 1, P_ADD, O_PLUS) 94 FN("-", 1, P_ADD, O_MINUS) 95 FN("&", 1, P_BAND, O_BAND) 96 FN("^", 1, P_BXOR, O_BXOR) 97 FN("|", 1, P_BOR, O_BOR) 98 FN("?", 1, P_TERN, O_TERN) 99 FN(",", 1, P_COMMA, O_COMMA) 100 /* things after this aren't used as binary operators */ 101 /* unary that are not also binaries */ 102 FN("~", 1, P_PRIMARY, O_BNOT) 103 FN("!", 1, P_PRIMARY, O_LNOT) 104 /* misc */ 105 FN("(", 1, P_PRIMARY, OPEN_PAREN) 106 FN(")", 1, P_PRIMARY, CLOSE_PAREN) 107 FN(":", 1, P_PRIMARY, CTERN) 108 /* things that don't appear in the opinfo[] table */ 109 F1(VAR) /*XXX should be F2 */ 110 F2(LIT) 111 F2(END) 112 F9(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