1: #include "c0.h" 2: /* 3: * info on operators: 4: * 01-- is binary operator 5: * 02-- left (or only) operand must be lvalue 6: * 04-- is relational operator 7: * 010-- is assignment-type operator 8: * 020-- non-float req. on left 9: * 040-- non-float req. on right 10: * 0100-- is commutative 11: * 0200-- is right, not left-associative 12: * 0400-- is leaf of tree 13: * *0XX000-- XX is priority of operator 14: */ 15: int opdope[] = { 16: 000000, /* EOFC */ 17: 000000, /* ; */ 18: 000000, /* { */ 19: 000000, /* } */ 20: 036001, /* [ */ 21: 002000, /* ] */ 22: 037000, /* ( */ 23: 002000, /* ) */ 24: 014201, /* : */ 25: 007001, /* , */ 26: 000001, /* field selection */ 27: 034201, /* CAST */ 28: 000000, /* ETYPE */ 29: 000001, /* integer->ptr */ 30: 000001, /* ptr->integer */ 31: 000001, /* long->ptr */ 32: 000000, /* 16 */ 33: 000000, /* 17 */ 34: 000000, /* 18 */ 35: 000000, /* 19 */ 36: 000400, /* name */ 37: 000400, /* short constant */ 38: 000400, /* string */ 39: 000400, /* float */ 40: 000400, /* double */ 41: 000400, /* long constant */ 42: 000400, /* long constant <= 16 bits */ 43: 000000, /* 27 */ 44: 000000, /* 28 */ 45: 000400, /* () empty arglist */ 46: 074203, /* ++pre */ 47: 074203, /* --pre */ 48: 074203, /* ++post */ 49: 074203, /* --post */ 50: 034200, /* !un */ 51: 034202, /* &un */ 52: 034220, /* *un */ 53: 034200, /* -un */ 54: 034220, /* ~un */ 55: 036001, /* . (structure reference) */ 56: 070101, /* + */ 57: 070001, /* - */ 58: 032101, /* * */ 59: 032001, /* / */ 60: 032001, /* % */ 61: 026061, /* >> */ 62: 026061, /* << */ 63: 020161, /* & */ 64: 017161, /* | */ 65: 017161, /* ^ */ 66: 036001, /* -> */ 67: 000000, /* int -> double */ 68: 000000, /* double -> int */ 69: 016001, /* && */ 70: 015001, /* || */ 71: 030001, /* &~ */ 72: 000000, /* 56 */ 73: 000000, /* 57 */ 74: 000000, /* 58 */ 75: 000000, /* 59 */ 76: 022005, /* == */ 77: 022005, /* != */ 78: 024005, /* <= */ 79: 024005, /* < */ 80: 024005, /* >= */ 81: 024005, /* > */ 82: 024005, /* <p */ 83: 024005, /* <=p */ 84: 024005, /* >p */ 85: 024005, /* >=p */ 86: 052213, /* += */ 87: 052213, /* -= */ 88: 012213, /* *= */ 89: 012213, /* /= */ 90: 012213, /* %= */ 91: 012253, /* >>= */ 92: 012253, /* <<= */ 93: 012253, /* &= */ 94: 012253, /* |= */ 95: 012253, /* ^= */ 96: 012213, /* = */ 97: 000000, /* 81 */ 98: 000000, /* 82 */ 99: 000000, /* 83 */ 100: 000000, /* 84 */ 101: 000000, /* 85 */ 102: 000000, /* 86 */ 103: 000000, /* 87 */ 104: 000000, /* 88 */ 105: 000000, /* 89 */ 106: 014201, /* ? */ 107: 034200, /* sizeof */ 108: 000000, /* 92 */ 109: 021101, /* min */ 110: 021101, /* minp */ 111: 021101, /* max */ 112: 021101, /* maxp */ 113: 007001, /* , */ 114: 000000, /* 98 */ 115: 000000, /* 99 */ 116: 036001, /* call */ 117: 036001, /* mcall */ 118: 000000, /* goto */ 119: 000000, /* jump cond */ 120: 000000, /* branch cond */ 121: 000000, /* 105 */ 122: 000000, /* 106 */ 123: 000000, /* 107 */ 124: 000000, /* 108 */ 125: 000000, /* char->int */ 126: 000000, /* 109 - force r0 */ 127: 000000, /* 110 */ 128: 000000, /* 111 */ 129: 000000, /* 112 */ 130: 000000, /* 113 */ 131: 000000, /* 114 */ 132: 000000, /* 115 */ 133: 000000, /* 116 */ 134: 000000, /* 117 */ 135: 000000, /* 118 */ 136: 000000, /* 119 */ 137: 000000, /* 120 */ 138: 000000, /* 121 */ 139: 000000, /* 122 */ 140: 000000, /* 123 */ 141: 000000, /* 124 */ 142: 000000, /* 125 */ 143: 000000, /* 126 */ 144: 000000, /* 127 */ 145: 026061, /* 128 - << unsigned long */ 146: 012253 /* 129 - <<= unsigned long */ 147: }; 148: 149: /* 150: * conversion table: 151: * FTI: float (or double) to integer 152: * ITF: integer to float 153: * ITP: integer to pointer 154: * ITL: integer to long 155: * LTI: long to integer 156: * LTF: long to float 157: * FTL: float to long 158: * PTI: pointer to integer 159: * LTP: long to ptr (ptr[long]) 160: * XX: usually illegal 161: * When FTI, LTI, FTL are added in they specify 162: * that it is the left operand that should be converted. 163: * For + this is done and the conversion is turned back into 164: * ITF, ITL, LTF. 165: * For = however the left operand can't be converted 166: * and the specified conversion is applied to the rhs. 167: */ 168: char cvtab[4][4] = { 169: /* int double long ptr */ 170: /* int */ 0, (FTI<<4)+ITF, (LTI<<4)+ITL, (ITP<<4)+ITP, 171: /* double */ ITF, 0, LTF, XX, 172: /* long */ ITL, (FTL<<4)+LTF, 0, (LTP<<4)+LTP, 173: /* ptr */ ITP, XX, LTP, PTI, 174: }; 175: 176: /* 177: * relate conversion numbers to operators 178: */ 179: char cvntab[] = { 180: 0, ITOF, ITOL, LTOF, ITOP, PTOI, FTOI, LTOI, FTOL, LTOP, 181: }; 182: 183: /* 184: * character type table 185: */ 186: char ctab[] = { 187: EOFC, UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, 188: UNKN, SPACE, NEWLN, SPACE, SPACE, UNKN, UNKN, UNKN, 189: UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, 190: UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, UNKN, 191: SPACE, EXCLA, DQUOTE, SHARP, UNKN, MOD, AND, SQUOTE, 192: LPARN, RPARN, TIMES, PLUS, COMMA, MINUS, PERIOD, DIVIDE, 193: DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, DIGIT, 194: DIGIT, DIGIT, COLON, SEMI, LESS, ASSIGN, GREAT, QUEST, 195: UNKN, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, 196: LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, 197: LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, 198: LETTER, LETTER, LETTER, LBRACK, BSLASH, RBRACK, EXOR, LETTER, 199: UNKN, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, 200: LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, 201: LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, LETTER, 202: LETTER, LETTER, LETTER, LBRACE, OR, RBRACE, COMPL, UNKN 203: };