Make

xiaoxiao2021-03-06  91

1 %{

2 #Define Edit_Source

3 # DEFINE NO_OPCODES

4 #include "std.h"

5 #include "make_func.h"

6 #include "lex.h"

7 #include "preprocess.h"

8 #include "edit_source.h"

9

10 #ifdef Win32

11 #define msdos

12 #include

13 #ENDIF

14

15 void mf_fatal (char *);

16

17 int num_buff = 0;

18 INTOP_CODE, EFUN_CODE, EFUN1_CODE

19 char * OPER_CODES [MAX_FUNC];

20 char * efun_codes [max_func], * EFUN1_CODES [MAX_FUNC];

21 char * efun_names [max_func], * EFUN1_NAMES [MAX_FUNC];

22 char * key [max_func], * buf [max_func];

twenty three

24 INT min_arg = -1, LIMIT_MAX = 0;

25

26 / *

27 * arg_types is the Types of all arguments. A 0 is used as a delimiter,

28 * Marking Next Argument. An Argument CAN Have Several Types.

29 * /

30 int Arg_Types [400], Last_Current_Type;

31

32 / *

33 * Store The Types of the current efun. The current efun. The current efun.

34 * arg_types list if They bere not already there (to save memory).

35 * /

36 INT curr_arg_types [40], curr_arg_type_size;

37

38 struct type {

39 char * name;

40 int Num;

41} Types [] = {

42 {"void", void},

43 {"Int", int},

44 {"String", string},

45 {"Object", Object},

46 {"mapping", mapping},

47 {"Mixed", Mixed},

48 {"unknown", unknown},

49 {"float", float},

50 {"function", function},

51 {"buffer", buffer}

52};

53

54 #define Nlems (Sizeof Arr / Sizeof Arr [0])

55%}

56

57% union {

58 int Number;

59 char * STRING;

60}

61

62% token ID Num Default Operator63

64% Type Type Arg_list Basic Typel Arg_Type Typel2 Num

65

66% Type ID OPTIONAL_ID OPTIONAL_DEFAULT

67

68 %%

69

70 SPECS: / * EMPTY * / | SPECS SPEC;

71

72 SPEC: OPERATOR | FUNC;

73

74 Operator: Operator op_list ';';

75

76 OP_List: OP | OP_LIST ',' OP;

77

78 op: ID

79 {

80 char f_name [500], c;

81 I = 2;

82 Sprintf (f_name, "f_% s", $ 1);

83 While ((c = f_name [i])) {

84 IF (islower (c)) f_name [i ] = TouPper (C);

85 ELSE I ;

86}

87 OPER_CODES [OP_CODE] = (char *) Malloc (i 1);

88 STRCPY (OPER_CODES [OP_CODE], F_NAME);

89 Free ($ 1);

90

91 OP_CODE ;

92};

93

94 OPTIONAL_ID: ID | / * Empty * / {$$ = "";

95

96 Optional_Default: / * Empty * / {$$ = "default_none";

97 | Default ':' Num

98 {

99 Static Char BUF [40];

100 Sprintf (buf, "% i", $ 3);

101 $$ = BUF;

102}

103 | Default ':' ID

104 {

105 IF (STRCMP ($ 3, "f__this_object"))))

106 YYERROR ("Illegal default");

107 $$ = "Default_this_Object";

108}

109

110 func: type id optional_id '(' arg_list optional_default ')'; '

111 {

112 char buff [500];

113 char f_name [500];

114 INT I, LEN;

115 IF (min_arg == -1) 116 min_arg = $ 5;

117 IF (min_arg> 4) mf_fatal ("min_arg> 4 / n");

118 IF ($ 3 [0] == '/ 0') {

119 IF (Strlen ($ 2) 1 2> sizeof f_name)

120 mf_fatal ("A Local Buffer Was TOO SMALL! (1) / N");

121 Sprintf (f_name, "f_% s", $ 2);

122 LEN = Strlen (f_name);

123 for (i = 0; i

124 IF (Islower (f_name [i]))

125

f_name [i] = TouPper (f_name [i]);

126}

127 if (min_arg == 1 &&! LIMIT_MAX & $ 5 == 1) {

128 EFUN1_CODES [EFUN1_CODE] = (char *) Malloc (LEN 1);

129 STRCPY (EFUN1_CODES [EFUN1_CODE], F_NAME);

130 EFUN1_NAMES [EFUN1_CODE] = (char *) Malloc (len - 1);

131 STRCPY (EFUN1_NAMES [EFUN1_CODE], $ 2);

132 EFUN1_CODE ;

133} else {

134 EFUN_CODES [EFUN_CODE] = (char *) Malloc (LEN 1);

135 STRCPY (EFUN_CODES [EFUN_CODE], F_NAME);

136 EFUN_NAMES [EFUN_CODE] = (char *) Malloc (LEN - 1);

137 STRCPY (EFUN_NAMES [EFUN_CODE], $ 2);

138 EFUN_CODE ;

139}

110} else {

141 IF (Strlen ($ 3) 1 17> SizeOf f_name)

142 mf_fatal ("A Local Buffer Was TOO SMALL (2)! / N");

143 Sprintf (f_name, "f_% s | f_alias_flag", $ 3);

144 LEN = Strlen (f_name);

145 for (i = 0; i

146 IF (Islower (f_name [i]))

147

f_name [i] = TouPper (f_name [i]); 148}

149 Free ($ 3);

150}

151 for (i = 0; i

152 INT J;

153 for (j = 0; J i

154 {

155 IF (curr_arg_types [j]! = Arg_types [i j])

156 Break;

157}

158 IF (j == curr_arg_type_size)

159 Break;

160}

161 if (i == last_current_type) {

162 INT J;

163 for (j = 0; j

164 arg_types [last_current_type ] = curr_arg_types [j];

165 if (Last_Current_Type == NELEMS (arg_types))

166 YYERROR ("Array 'Arg_Types' Is Too Small");

167}

168}

169 IF (! STRCMP ($ 2, "call_other") &&! Lookup_define ("cast_call_others")) {

170 $ 1 = Mixed;

171}

172 sprintf (buff, "{/"% s / ",% s, 0, 0,% D,% D,% S,% S,% S,% S,% S,% D,% s}, / N ",

173 $ 2, f_name, min_arg, limited_max? -1: $ 5,

174 $ 1! = Void? Ctype ($ 1): "Type_novalue",

175 ETYPE (0), ETYPE (1), ETYPE (2), ETYPE (3), I, $ 6);

176 IF (Strlen> Sizeof Buff)

177 mf_fatal ("Local Buffer Overwritten! / N");

178

179 Key [Num_Buff] = $ 2;

180 BUF [Num_Buff] = (char *) Malloc (Strlen 1);

181 strcpy (buf [num_buff], buff);

182 NUM_BUFF ;

183 min_arg = -1;

184 limit_max = 0;

185 CURR_ARG_TYPE_SIZE = 0; 186};

187

188 TYPE: BASIC | Basic '*' {$$ = $ 1 | 0x10000;

189

190 Basic: ID

191 {

192 I = NELEMS (Types);

193 $$ = 0;

194 While (i -) {

195 IF (Strcmp ($ 1, Types [i] .Name) == 0) {

196 $$ = Types [i] .num;

197 Break;

198}

199}

200 IF (! $$) {

201 char buf [256];

202 Sprintf (BUF, "Invalid Type:% S", $ 1);

203 YYERROR (BUF);

204}

205 Free ($ 1);

206};

207

208 arg_list: / * Empty * / {$$ = 0;

209 | Typel2 {$$ = 1; if ($ 1) min_arg = 0;}

210 | arg_list ',' Typel2 {$$ = $ 1 1; if ($ 3) min_arg = $$ - 1;

211

212 Typel2: Typel

213 {

214 $$ = $ 1;

215 curr_arg_types [curr_arg_type_size ] = 0;

216 if (curr_arg_type_size == NELEMS (CURR_ARG_TYPES))

217 YYERROR ("Too Many Arguments");

218};

219

220 arg_type: Type

221 {

222 IF ($ 1! = Void) {

223 curr_arg_types [curr_arg_type_size ] = $ 1;

224 if (curr_arg_type_size == NELEMS (CURR_ARG_TYPES))

225 YYERROR ("Too Many Arguments");

226}

227 $$ = $ 1;

228}

229

230 Typel: arg_type {$$ = ($ 1 == VOID && min_arg == -1);}

231 | Typel '|' Arg_Type {$$ = (min_arg == -1 && ($ 1 || $ 3 == VOID);

232 | '.' '' '' '.' {$$ = min_arg == -1; Limit_Max = 1;}; 233

234 %%

235

236 Char * CTYPE P1 (int, n)

237 {

238 Static Char Buff [100]; / * 100 is Such a comfortable size :-) * /

239 char * p = (char *) NULL;

240

241 IF (N & 0x10000)

242 STRCPY (BUFF, "Type_Mod_Array |");

243 else

244 BUF [0] = '/ 0';

245 n & = ~ 0x10000;

246 switch (n) {

247 case float: p = "type_real"; Break;

248 case function: p = "type_function"; Break;

249 case void: P = "type_void"; Break;

250 case string: p = "type_string"; Break;

251 Case Int: P = "Type_Number"; Break;

252 Case Object: P = "Type_Object"; Break;

253 case mapping: p = "type_mapping"; Break;

254 Case Buffer: P = "Type_buffer"; Break;

255 case mixed: p = "type_any"; Break;

256 case unknown: p = "type_unknown"; Break;

257 Default: YYERROR ("Bad Type!");

258}

259 strcat (buff, p);

260 if (strlen (buff) 1> Sizeof Buff)

261 mf_fatal ("Local Buffer Overwritten In CType ()");

262 Return BUFF;

263}

264

265 char * ETYPE1 P1 (int, n)

266 {

267 if (N & 0x10000)

268 return "t_array";

269 ​​switch (n) {

270 Case Float:

271 Return "T_Real";

272 Case Function:

273 return "t_function";

274 case Int:

275 Return "T_Number";

276 Case Object:

277 Return "T_Object";

278 case mapping:

279 Return "T_mapping"; 280 Case String:

281 Return "T_String";

282 Case Buffer:

283 RETURN "T_Buffer";

284 Case Mixed:

285 Return "T_Any"; / * 0 means any type * /

286 Default:

287 YYERROR ("Illegal Type for Argument");

288}

289 RETURN "What?"

290}

291

292 Char * ETYPE P1 (int, n)

293 {

294 INT I;

295 int logal_size = 100;

296 char * buff = (char *) malloc (local_size);

297

298 for (i = 0; i

299 IF (n == 0)

300 Break;

301 IF (curr_arg_types [i] == 0)

302 n -;

303}

304 IF (i == curr_arg_type_size)

305 Return "T_Any";

306 BUF [0] = '/ 0';

307 for (; curr_arg_types [i]! = 0; i ) {

308 char * p;

309 IF (curr_arg_types [i] == void)

310 Continue;

311 IF (buff [0]! = '/ 0')

312 STRCAT (BUFF, "|");

313 p = ETYPE1 (curr_arg_types [i]);

314 / *

315 * The number 2 Below is to include the zero-byte and the next

316 * '|' (Which May Not Come).

317 * /

318 IF (Strlen (P) Strlen (BUFF) 2> local_size) {

319 FPRINTF (stderr, "buffer overflow! / N");

320 exit (1);

321}

322 strcat (buff, eType1 (curr_arg_types [i]));

323}

324 if (! Strcmp (BUFF, ")))

325 STRCPY (BUFF, "T_Any");

326 Return BUFF;

327}

328

329 Int IDENT PROT ((int));

330

331 int yylex () {

332 Register INT C;

333

334 for (;;) {

335 Switch (c = getc (yyin)) {336 case '':

337 Case '/ T':

338 Continue;

339 case '/ n':

340 Current_Line ;

341 Continue;

342 Case '!':

343 {

344 char buff [2048];

345 FGETS (BUFF, 2047, YYIN);

346 FPRINTF (stderr, "configure problem:% s / n", buff);

347 exit (-1);

348}

349 case '#':

350 {

351 int line;

352

353 Char Abuf [2048], FNAME [2048];

354 FGETS (Abuf, 2047, yyin);

355 IF (SSCANF (Abuf, "% D /"% [^ / "] /" ", & line, fname)) {

356 Current_Line = line;

357 if (current_file) free (current_file);

358 current_file = (char *) Malloc (Strlen (FNAME) 1);

359 STRCPY (Current_File, FNAME);

360} Else

361 IF (SSCANF (ABUF, "% D", & line)) current_line = line;

362 Current_Line ;

363 Continue;

364}

365 Case EOF:

366 fclose (yyn);

367 return -1;

368 DEFAULT:

369 IF ((C> = '0' && c <= '9') || c == '-') {

370 INT V;

371 int NEG = 0;

372 V = 0;

373 IF (c == '-') {

374 NEG = 1;

375

C = '0';

376}

377 DO {

378 V = V * 10 (C - '0');

379

C = getc (yyn);

380} While (C> = '0' && c <= '9'); 381 Ungetc (C, YYIN);

382 Yylval.number = (NEG? -V: V);

383 return NUM;

384}

385 IF (isalunum (c))

386 Return Ident (C);

387 RETURN C;

388}

389}

390}

391

392 IDENT P1 (int, c)

393 {

394 char buff [100];

395 int Len;

396

397 for (len = 0; isalunum (c); c = getc (yyn)) {

398 BUFF [LEN ] = C;

399 IF (len == Sizeof Buff - 1) {

400 YYERROR ("Too Long Indentifier";

401 Break;

402}

403}

404 (Void) UNGETC (C, YYIN);

405 buff [len] = '/ 0';

406 IF (! Strcmp (buff, "default")))

407 returnifault;

408 IF (! Strcmp (buff, "operator"))

409 return operation;

410

411 Yylval.string = (char *) Malloc (strlen 1);

412 strcpy (yylval.string, buff);

413 return id;

414}

转载请注明原文地址:https://www.9cbs.com/read-124292.html

New Post(0)