expread.tab.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398
  1. # line 31 "expread.y"
  2. #include "defs.h"
  3. #include "param.h"
  4. #include "symtab.h"
  5. #include "frame.h"
  6. #include "expression.h"
  7. #include <stdio.h>
  8. static struct expression *expout;
  9. static int expout_size;
  10. static int expout_ptr;
  11. static int yylex ();
  12. static yyerror ();
  13. static void write_exp_elt ();
  14. static void write_exp_string ();
  15. static void start_arglist ();
  16. static int end_arglist ();
  17. static void free_funcalls ();
  18. static char *copy_name ();
  19. /* If this is nonzero, this block is used as the lexical context
  20. for symbol names. */
  21. static struct block *expression_context_block;
  22. /* Number of arguments seen so far in innermost function call. */
  23. static int arglist_len;
  24. /* Data structure for saving values of arglist_len
  25. for function calls whose arguments contain other function calls. */
  26. struct funcall
  27. {
  28. struct funcall *next;
  29. int arglist_len;
  30. };
  31. struct funcall *funcall_chain;
  32. /* This kind of datum is used to represent the name
  33. of a symbol token. */
  34. struct stoken
  35. {
  36. char *ptr;
  37. int length;
  38. };
  39. # line 85 "expread.y"
  40. typedef union
  41. {
  42. long lval;
  43. double dval;
  44. struct symbol *sym;
  45. struct type *tval;
  46. struct stoken sval;
  47. int voidval;
  48. struct block *bval;
  49. enum exp_opcode opcode;
  50. struct internalvar *ivar;
  51. } YYSTYPE;
  52. # define INT 257
  53. # define CHAR 258
  54. # define FLOAT 259
  55. # define NAME 260
  56. # define TYPENAME 261
  57. # define STRING 262
  58. # define STRUCT 263
  59. # define UNION 264
  60. # define ENUM 265
  61. # define SIZEOF 266
  62. # define UNSIGNED 267
  63. # define COLONCOLON 268
  64. # define LAST 269
  65. # define REGNAME 270
  66. # define VARIABLE 271
  67. # define ASSIGN_MODIFY 272
  68. # define ABOVE_COMMA 273
  69. # define OR 274
  70. # define AND 275
  71. # define EQUAL 276
  72. # define NOTEQUAL 277
  73. # define LEQ 278
  74. # define GEQ 279
  75. # define LSH 280
  76. # define RSH 281
  77. # define UNARY 282
  78. # define INCREMENT 283
  79. # define DECREMENT 284
  80. # define ARROW 285
  81. #define yyclearin yychar = -1
  82. #define yyerrok yyerrflag = 0
  83. extern int yychar;
  84. extern short yyerrflag;
  85. #ifndef YYMAXDEPTH
  86. #define YYMAXDEPTH 150
  87. #endif
  88. YYSTYPE yylval, yyval;
  89. # define YYERRCODE 256
  90. # line 496 "expread.y"
  91. /* Begin counting arguments for a function call,
  92. saving the data about any containing call. */
  93. static void
  94. start_arglist ()
  95. {
  96. register struct funcall *new = (struct funcall *) xmalloc (sizeof (struct funcall));
  97. new->next = funcall_chain;
  98. new->arglist_len = arglist_len;
  99. arglist_len = 0;
  100. funcall_chain = new;
  101. }
  102. /* Return the number of arguments in a function call just terminated,
  103. and restore the data for the containing function call. */
  104. static int
  105. end_arglist ()
  106. {
  107. register int val = arglist_len;
  108. register struct funcall *call = funcall_chain;
  109. funcall_chain = call->next;
  110. arglist_len = call->arglist_len;
  111. free (call);
  112. return val;
  113. }
  114. /* Free everything in the funcall chain.
  115. Used when there is an error inside parsing. */
  116. static void
  117. free_funcalls ()
  118. {
  119. register struct funcall *call, *next;
  120. for (call = funcall_chain; call; call = next)
  121. {
  122. next = call->next;
  123. free (call);
  124. }
  125. }
  126. /* This page contains the functions for adding data to the struct expression
  127. being constructed. */
  128. /* Add one element to the end of the expression. */
  129. static void
  130. write_exp_elt (expelt)
  131. union exp_element expelt;
  132. {
  133. if (expout_ptr >= expout_size)
  134. {
  135. expout_size *= 2;
  136. expout = (struct expression *) xrealloc (expout,
  137. sizeof (struct expression)
  138. + expout_size * sizeof (union exp_element));
  139. }
  140. expout->elts[expout_ptr++] = expelt;
  141. }
  142. /* Add a string constant to the end of the expression.
  143. Follow it by its length in bytes, as a separate exp_element. */
  144. static void
  145. write_exp_string (str)
  146. struct stoken str;
  147. {
  148. register int len = str.length;
  149. register int lenelt
  150. = (len + sizeof (union exp_element)) / sizeof (union exp_element);
  151. expout_ptr += lenelt;
  152. if (expout_ptr >= expout_size)
  153. {
  154. expout_size = max (expout_size * 2, expout_ptr + 10);
  155. expout = (struct expression *) xrealloc (expout,
  156. sizeof (struct expression)
  157. + expout_size * sizeof (union exp_element));
  158. }
  159. bcopy (str.ptr, (char *) &expout->elts[expout_ptr - lenelt], len);
  160. ((char *) &expout->elts[expout_ptr - lenelt])[len] = 0;
  161. write_exp_elt (len);
  162. }
  163. /* During parsing of a C expression, the pointer to the next character
  164. is in this variable. */
  165. static char *lexptr;
  166. /* Tokens that refer to names do so with explicit pointer and length,
  167. so they can share the storage that lexptr is parsing.
  168. When it is necessary to pass a name to a function that expects
  169. a null-terminated string, the substring is copied out
  170. into a block of storage that namecopy points to.
  171. namecopy is allocated once, guaranteed big enough, for each parsing. */
  172. static char *namecopy;
  173. /* Take care of parsing a number (anything that starts with a digit).
  174. Set yylval and return the token type; update lexptr.
  175. LEN is the number of characters in it. */
  176. /*** Needs some error checking for the float case ***/
  177. static int
  178. parse_number (olen)
  179. int olen;
  180. {
  181. register char *p = lexptr;
  182. register long n = 0;
  183. register int c;
  184. register int base = 10;
  185. register len = olen;
  186. char *err_copy;
  187. extern double atof ();
  188. for (c = 0; c < len; c++)
  189. if (p[c] == '.')
  190. {
  191. /* It's a float since it contains a point. */
  192. yylval.dval = atof (p);
  193. lexptr += len;
  194. return FLOAT;
  195. }
  196. if (len >= 3 && (!strncmp (p, "0x", 2) || !strncmp (p, "0X", 2)))
  197. {
  198. p += 2;
  199. base = 16;
  200. len -= 2;
  201. }
  202. else if (*p == '0')
  203. base = 8;
  204. while (len-- > 0)
  205. {
  206. c = *p++;
  207. n *= base;
  208. if (c >= '0' && c <= '9')
  209. n += c - '0';
  210. else
  211. {
  212. if (c >= 'A' && c <= 'Z') c += 'a' - 'A';
  213. if (base == 16 && c >= 'a' && c <= 'f')
  214. n += c - 'a' + 10;
  215. else if (len == 0 && c == 'l')
  216. ;
  217. else
  218. {
  219. err_copy = (char *) alloca (olen + 1);
  220. bcopy (lexptr, err_copy, olen);
  221. err_copy[olen] = 0;
  222. error ("Invalid number \"%s\".", err_copy);
  223. }
  224. }
  225. }
  226. lexptr = p;
  227. yylval.lval = n;
  228. return INT;
  229. }
  230. struct token
  231. {
  232. char *operator;
  233. int token;
  234. enum exp_opcode opcode;
  235. };
  236. static struct token tokentab3[] =
  237. {
  238. {">>=", ASSIGN_MODIFY, BINOP_RSH},
  239. {"<<=", ASSIGN_MODIFY, BINOP_LSH}
  240. };
  241. static struct token tokentab2[] =
  242. {
  243. {"+=", ASSIGN_MODIFY, BINOP_ADD},
  244. {"-=", ASSIGN_MODIFY, BINOP_SUB},
  245. {"*=", ASSIGN_MODIFY, BINOP_MUL},
  246. {"/=", ASSIGN_MODIFY, BINOP_DIV},
  247. {"%=", ASSIGN_MODIFY, BINOP_REM},
  248. {"|=", ASSIGN_MODIFY, BINOP_LOGIOR},
  249. {"&=", ASSIGN_MODIFY, BINOP_LOGAND},
  250. {"^=", ASSIGN_MODIFY, BINOP_LOGXOR},
  251. {"++", INCREMENT, BINOP_END},
  252. {"--", DECREMENT, BINOP_END},
  253. {"->", ARROW, BINOP_END},
  254. {"&&", AND, BINOP_END},
  255. {"||", OR, BINOP_END},
  256. {"::", COLONCOLON, BINOP_END},
  257. {"<<", LSH, BINOP_END},
  258. {">>", RSH, BINOP_END},
  259. {"==", EQUAL, BINOP_END},
  260. {"!=", NOTEQUAL, BINOP_END},
  261. {"<=", LEQ, BINOP_END},
  262. {">=", GEQ, BINOP_END}
  263. };
  264. /* Read one token, getting characters through lexptr. */
  265. static int
  266. yylex ()
  267. {
  268. register int c;
  269. register int namelen;
  270. register int i;
  271. register char *tokstart;
  272. retry:
  273. tokstart = lexptr;
  274. /* See if it is a special token of length 3. */
  275. for (i = 0; i < sizeof tokentab3 / sizeof tokentab3[0]; i++)
  276. if (!strncmp (tokstart, tokentab3[i].operator, 3))
  277. {
  278. lexptr += 3;
  279. yylval.opcode = tokentab3[i].opcode;
  280. return tokentab3[i].token;
  281. }
  282. /* See if it is a special token of length 2. */
  283. for (i = 0; i < sizeof tokentab2 / sizeof tokentab2[0]; i++)
  284. if (!strncmp (tokstart, tokentab2[i].operator, 2))
  285. {
  286. lexptr += 2;
  287. yylval.opcode = tokentab2[i].opcode;
  288. return tokentab2[i].token;
  289. }
  290. switch (c = *tokstart)
  291. {
  292. case 0:
  293. return 0;
  294. case ' ':
  295. case '\t':
  296. case '\n':
  297. lexptr++;
  298. goto retry;
  299. case '\'':
  300. lexptr++;
  301. c = *lexptr++;
  302. if (c == '\\')
  303. c = parse_escape (&lexptr);
  304. yylval.lval = c;
  305. c = *lexptr++;
  306. if (c != '\'')
  307. error ("Invalid character constant.");
  308. return CHAR;
  309. case '+':
  310. case '-':
  311. case '*':
  312. case '/':
  313. case '%':
  314. case '|':
  315. case '&':
  316. case '^':
  317. case '~':
  318. case '!':
  319. case '@':
  320. case '<':
  321. case '>':
  322. case '(':
  323. case ')':
  324. case '[':
  325. case ']':
  326. case '.':
  327. case '?':
  328. case ':':
  329. case '=':
  330. case '{':
  331. case '}':
  332. case ',':
  333. lexptr++;
  334. return c;
  335. case '"':
  336. for (namelen = 1; (c = tokstart[namelen]) != '"'; namelen++)
  337. if (c == '\\')
  338. {
  339. c = tokstart[++namelen];
  340. if (c >= '0' && c <= '9')
  341. {
  342. c = tokstart[++namelen];
  343. if (c >= '0' && c <= '9')
  344. c = tokstart[++namelen];
  345. }
  346. }
  347. yylval.sval.ptr = tokstart + 1;
  348. yylval.sval.length = namelen - 1;
  349. lexptr += namelen + 1;
  350. return STRING;
  351. }
  352. if (c >= '0' && c <= '9')
  353. {
  354. /* It's a number */
  355. for (namelen = 0;
  356. c = tokstart[namelen],
  357. (c == '_' || c == '$' || c == '.' || (c >= '0' && c <= '9')
  358. || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
  359. namelen++)
  360. ;
  361. return parse_number (namelen);
  362. }
  363. if (!(c == '_' || c == '$'
  364. || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')))
  365. error ("Invalid token in expression.");
  366. /* It is a name. See how long it is. */
  367. for (namelen = 0;
  368. c = tokstart[namelen],
  369. (c == '_' || c == '$' || (c >= '0' && c <= '9')
  370. || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
  371. namelen++)
  372. ;
  373. /* The token "if" terminates the expression and is NOT
  374. removed from the input stream. */
  375. if (namelen == 2 && tokstart[0] == 'i' && tokstart[1] == 'f')
  376. {
  377. return 0;
  378. }
  379. lexptr += namelen;
  380. /* Handle the tokens $digits; also $ (short for $0) and $$ (short for $$1)
  381. and $$digits (equivalent to $<-digits> if you could type that).
  382. Make token type LAST, and put the number (the digits) in yylval. */
  383. if (*tokstart == '$')
  384. {
  385. register int negate = 0;
  386. c = 1;
  387. /* Double dollar means negate the number and add -1 as well.
  388. Thus $$ alone means -1. */
  389. if (namelen >= 2 && tokstart[1] == '$')
  390. {
  391. negate = 1;
  392. c = 2;
  393. }
  394. if (c == namelen)
  395. {
  396. /* Just dollars (one or two) */
  397. yylval.lval = - negate;
  398. return LAST;
  399. }
  400. /* Is the rest of the token digits? */
  401. for (; c < namelen; c++)
  402. if (!(tokstart[c] >= '0' && tokstart[c] <= '9'))
  403. break;
  404. if (c == namelen)
  405. {
  406. yylval.lval = atoi (tokstart + 1 + negate);
  407. if (negate)
  408. yylval.lval = - yylval.lval;
  409. return LAST;
  410. }
  411. }
  412. /* Handle tokens that refer to machine registers:
  413. $ followed by a register name. */
  414. if (*tokstart == '$')
  415. for (c = 0; c < NUM_REGS; c++)
  416. if (namelen - 1 == strlen (reg_names[c])
  417. && !strncmp (tokstart + 1, reg_names[c], namelen - 1))
  418. {
  419. yylval.lval = c;
  420. return REGNAME;
  421. }
  422. if (namelen == 6 && !strncmp (tokstart, "struct", 6))
  423. {
  424. return STRUCT;
  425. }
  426. if (namelen == 5 && !strncmp (tokstart, "union", 5))
  427. {
  428. return UNION;
  429. }
  430. if (namelen == 4 && !strncmp (tokstart, "enum", 4))
  431. {
  432. return ENUM;
  433. }
  434. if (namelen == 6 && !strncmp (tokstart, "sizeof", 6))
  435. {
  436. return SIZEOF;
  437. }
  438. if (namelen == 8 && !strncmp (tokstart, "unsigned", 6))
  439. {
  440. return UNSIGNED;
  441. }
  442. yylval.sval.ptr = tokstart;
  443. yylval.sval.length = namelen;
  444. /* Any other names starting in $ are debugger internal variables. */
  445. if (*tokstart == '$')
  446. {
  447. yylval.ivar = (struct internalvar *) lookup_internalvar (copy_name (yylval.sval) + 1);
  448. return VARIABLE;
  449. }
  450. /* Use token-type TYPENAME for symbols that happen to be defined
  451. currently as names of types; NAME for other symbols.
  452. The caller is not constrained to care about the distinction. */
  453. if (lookup_typename (copy_name (yylval.sval), expression_context_block, 1))
  454. return TYPENAME;
  455. return NAME;
  456. }
  457. static
  458. yyerror ()
  459. {
  460. error ("Invalid syntax in expression.");
  461. }
  462. /* Return a null-terminated temporary copy of the name
  463. of a string token. */
  464. static char *
  465. copy_name (token)
  466. struct stoken token;
  467. {
  468. bcopy (token.ptr, namecopy, token.length);
  469. namecopy[token.length] = 0;
  470. return namecopy;
  471. }
  472. /* Reverse an expression from suffix form (in which it is constructed)
  473. to prefix form (in which we can conveniently print or execute it). */
  474. static void prefixify_subexp ();
  475. static void
  476. prefixify_expression (expr)
  477. register struct expression *expr;
  478. {
  479. register int len = sizeof (struct expression) +
  480. expr->nelts * sizeof (union exp_element);
  481. register struct expression *temp
  482. = (struct expression *) alloca (len);
  483. register int inpos = expr->nelts, outpos = 0;
  484. /* Copy the original expression into temp. */
  485. bcopy (expr, temp, len);
  486. prefixify_subexp (temp, expr, inpos, outpos);
  487. }
  488. /* Return the number of exp_elements in the subexpression of EXPR
  489. whose last exp_element is at index ENDPOS - 1 in EXPR. */
  490. static int
  491. length_of_subexp (expr, endpos)
  492. register struct expression *expr;
  493. register int endpos;
  494. {
  495. register int oplen = 1;
  496. register int args = 0;
  497. register int i;
  498. i = (int) expr->elts[endpos - 1].opcode;
  499. switch (i)
  500. {
  501. case OP_LONG:
  502. case OP_DOUBLE:
  503. oplen = 4;
  504. break;
  505. case OP_VAR_VALUE:
  506. case OP_LAST:
  507. case OP_REGISTER:
  508. case OP_INTERNALVAR:
  509. oplen = 3;
  510. break;
  511. case OP_FUNCALL:
  512. oplen = 3;
  513. args = 1 + expr->elts[endpos - 2].longconst;
  514. break;
  515. case UNOP_CAST:
  516. case UNOP_MEMVAL:
  517. oplen = 3;
  518. args = 1;
  519. break;
  520. case STRUCTOP_STRUCT:
  521. case STRUCTOP_PTR:
  522. args = 1;
  523. case OP_STRING:
  524. oplen = 3 + ((expr->elts[endpos - 2].longconst
  525. + sizeof (union exp_element))
  526. / sizeof (union exp_element));
  527. break;
  528. case TERNOP_COND:
  529. args = 3;
  530. break;
  531. case BINOP_ASSIGN_MODIFY:
  532. oplen = 3;
  533. args = 2;
  534. break;
  535. default:
  536. args = 1 + (i < (int) BINOP_END);
  537. }
  538. while (args > 0)
  539. {
  540. oplen += length_of_subexp (expr, endpos - oplen);
  541. args--;
  542. }
  543. return oplen;
  544. }
  545. /* Copy the subexpression ending just before index INEND in INEXPR
  546. into OUTEXPR, starting at index OUTBEG.
  547. In the process, convert it from suffix to prefix form. */
  548. static void
  549. prefixify_subexp (inexpr, outexpr, inend, outbeg)
  550. register struct expression *inexpr;
  551. struct expression *outexpr;
  552. register int inend;
  553. int outbeg;
  554. {
  555. register int oplen = 1;
  556. register int args = 0;
  557. register int i;
  558. int *arglens;
  559. enum exp_opcode opcode;
  560. /* Compute how long the last operation is (in OPLEN),
  561. and also how many preceding subexpressions serve as
  562. arguments for it (in ARGS). */
  563. opcode = inexpr->elts[inend - 1].opcode;
  564. switch (opcode)
  565. {
  566. case OP_LONG:
  567. case OP_DOUBLE:
  568. oplen = 4;
  569. break;
  570. case OP_VAR_VALUE:
  571. case OP_LAST:
  572. case OP_REGISTER:
  573. case OP_INTERNALVAR:
  574. oplen = 3;
  575. break;
  576. case OP_FUNCALL:
  577. oplen = 3;
  578. args = 1 + inexpr->elts[inend - 2].longconst;
  579. break;
  580. case UNOP_CAST:
  581. case UNOP_MEMVAL:
  582. oplen = 3;
  583. args = 1;
  584. break;
  585. case STRUCTOP_STRUCT:
  586. case STRUCTOP_PTR:
  587. args = 1;
  588. case OP_STRING:
  589. oplen = 3 + ((inexpr->elts[inend - 2].longconst
  590. + sizeof (union exp_element))
  591. / sizeof (union exp_element));
  592. break;
  593. case TERNOP_COND:
  594. args = 3;
  595. break;
  596. case BINOP_ASSIGN_MODIFY:
  597. oplen = 3;
  598. args = 2;
  599. break;
  600. default:
  601. args = 1 + ((int) opcode < (int) BINOP_END);
  602. }
  603. /* Copy the final operator itself, from the end of the input
  604. to the beginning of the output. */
  605. inend -= oplen;
  606. bcopy (&inexpr->elts[inend], &outexpr->elts[outbeg],
  607. oplen * sizeof (union exp_element));
  608. outbeg += oplen;
  609. /* Find the lengths of the arg subexpressions. */
  610. arglens = (int *) alloca (args * sizeof (int));
  611. for (i = args - 1; i >= 0; i--)
  612. {
  613. oplen = length_of_subexp (inexpr, inend);
  614. arglens[i] = oplen;
  615. inend -= oplen;
  616. }
  617. /* Now copy each subexpression, preserving the order of
  618. the subexpressions, but prefixifying each one.
  619. In this loop, inend starts at the beginning of
  620. the expression this level is working on
  621. and marches forward over the arguments.
  622. outbeg does similarly in the output. */
  623. for (i = 0; i < args; i++)
  624. {
  625. oplen = arglens[i];
  626. inend += oplen;
  627. prefixify_subexp (inexpr, outexpr, inend, outbeg);
  628. outbeg += oplen;
  629. }
  630. }
  631. /* This page contains the two entry points to this file. */
  632. /* Read a C expression from the string *STRINGPTR points to,
  633. parse it, and return a pointer to a struct expression that we malloc.
  634. Use block BLOCK as the lexical context for variable names;
  635. if BLOCK is zero, use the block of the selected stack frame.
  636. Meanwhile, advance *STRINGPTR to point after the expression,
  637. at the first nonwhite character that is not part of the expression
  638. (possibly a null character). */
  639. struct expression *
  640. parse_c_1 (stringptr, block)
  641. char **stringptr;
  642. struct block *block;
  643. {
  644. struct cleanup *old_chain;
  645. lexptr = *stringptr;
  646. if (lexptr == 0 || *lexptr == 0)
  647. error_no_arg ("expression to compute");
  648. old_chain = make_cleanup (free_funcalls, 0);
  649. funcall_chain = 0;
  650. expression_context_block = block ? block : get_selected_block ();
  651. namecopy = (char *) alloca (strlen (lexptr) + 1);
  652. expout_size = 10;
  653. expout_ptr = 0;
  654. expout = (struct expression *) xmalloc (sizeof (struct expression)
  655. + expout_size * sizeof (union exp_element));
  656. make_cleanup (free_current_contents, &expout);
  657. if (yyparse ())
  658. yyerror ();
  659. discard_cleanups (old_chain);
  660. expout->nelts = expout_ptr;
  661. expout = (struct expression *)
  662. xrealloc (expout,
  663. sizeof (struct expression)
  664. + expout_ptr * sizeof (union exp_element));
  665. prefixify_expression (expout);
  666. *stringptr = lexptr;
  667. return expout;
  668. }
  669. /* Parse STRING as an expression, and complain if this fails
  670. to use up all of the contents of STRING. */
  671. struct expression *
  672. parse_c_expression (string)
  673. char *string;
  674. {
  675. register struct expression *exp;
  676. exp = parse_c_1 (&string, 0);
  677. if (*string)
  678. error ("Junk after end of expression.");
  679. return exp;
  680. }
  681. short yyexca[] ={
  682. -1, 1,
  683. 0, -1,
  684. -2, 0,
  685. -1, 23,
  686. 268, 67,
  687. -2, 59,
  688. -1, 73,
  689. 268, 68,
  690. -2, 62,
  691. -1, 112,
  692. 268, 57,
  693. -2, 58,
  694. };
  695. # define YYNPROD 69
  696. # define YYLAST 803
  697. short yyact[]={
  698. 36, 47, 74, 32, 26, 34, 37, 105, 38, 30,
  699. 35, 66, 26, 67, 68, 69, 32, 70, 77, 25,
  700. 64, 116, 30, 45, 53, 46, 52, 33, 120, 111,
  701. 114, 121, 26, 80, 71, 36, 47, 22, 32, 52,
  702. 34, 37, 65, 38, 30, 35, 117, 105, 110, 105,
  703. 72, 2, 17, 113, 31, 1, 0, 48, 45, 53,
  704. 46, 52, 33, 0, 0, 0, 0, 31, 0, 0,
  705. 36, 47, 0, 32, 0, 34, 37, 0, 38, 30,
  706. 35, 0, 79, 0, 103, 0, 0, 49, 0, 31,
  707. 104, 0, 48, 45, 0, 46, 52, 33, 0, 0,
  708. 0, 0, 0, 0, 0, 36, 47, 0, 32, 0,
  709. 34, 37, 0, 38, 30, 35, 0, 0, 0, 0,
  710. 0, 0, 49, 0, 31, 0, 0, 48, 45, 0,
  711. 46, 52, 33, 0, 0, 0, 0, 0, 0, 0,
  712. 36, 47, 0, 32, 0, 34, 37, 0, 38, 30,
  713. 35, 0, 0, 0, 24, 0, 0, 49, 0, 31,
  714. 0, 0, 48, 45, 32, 46, 52, 33, 0, 0,
  715. 30, 0, 0, 36, 47, 0, 32, 0, 34, 37,
  716. 0, 38, 30, 35, 76, 78, 0, 52, 33, 0,
  717. 0, 0, 49, 0, 31, 0, 45, 48, 46, 52,
  718. 33, 7, 0, 0, 0, 0, 5, 0, 13, 0,
  719. 4, 0, 0, 6, 0, 31, 0, 0, 0, 0,
  720. 0, 0, 106, 107, 108, 109, 0, 31, 0, 112,
  721. 0, 0, 0, 0, 0, 54, 0, 51, 50, 41,
  722. 42, 43, 44, 39, 40, 7, 27, 28, 29, 0,
  723. 5, 0, 13, 0, 4, 0, 0, 6, 0, 27,
  724. 28, 29, 0, 0, 0, 0, 0, 0, 0, 0,
  725. 54, 0, 51, 50, 41, 42, 43, 44, 39, 40,
  726. 7, 27, 28, 29, 0, 5, 0, 63, 0, 4,
  727. 0, 12, 6, 0, 8, 0, 36, 0, 0, 32,
  728. 0, 34, 37, 0, 38, 30, 35, 0, 50, 41,
  729. 42, 43, 44, 39, 40, 0, 27, 28, 29, 45,
  730. 0, 46, 52, 33, 0, 0, 0, 0, 0, 0,
  731. 0, 36, 0, 0, 32, 12, 34, 37, 8, 38,
  732. 30, 35, 0, 0, 41, 42, 43, 44, 39, 40,
  733. 31, 27, 28, 29, 45, 0, 46, 52, 33, 0,
  734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  735. 12, 0, 0, 8, 0, 0, 0, 0, 0, 41,
  736. 42, 43, 44, 39, 40, 31, 27, 28, 29, 0,
  737. 0, 0, 0, 0, 0, 0, 36, 0, 0, 32,
  738. 0, 34, 37, 0, 38, 30, 35, 27, 28, 29,
  739. 0, 0, 41, 42, 43, 44, 39, 40, 0, 27,
  740. 28, 29, 52, 33, 0, 14, 15, 16, 23, 73,
  741. 21, 67, 68, 69, 11, 70, 0, 18, 19, 20,
  742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  743. 31, 9, 10, 0, 0, 0, 0, 0, 36, 0,
  744. 0, 32, 0, 34, 37, 0, 38, 30, 35, 14,
  745. 15, 16, 23, 25, 21, 0, 0, 0, 11, 0,
  746. 0, 18, 19, 20, 52, 33, 0, 0, 0, 0,
  747. 0, 0, 0, 0, 0, 9, 10, 0, 0, 0,
  748. 0, 0, 0, 0, 14, 15, 16, 23, 25, 21,
  749. 0, 0, 31, 11, 0, 0, 18, 19, 20, 0,
  750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  751. 9, 10, 0, 0, 0, 41, 42, 43, 44, 39,
  752. 40, 0, 27, 28, 29, 0, 0, 0, 0, 0,
  753. 0, 0, 0, 0, 36, 0, 0, 32, 0, 34,
  754. 0, 0, 0, 30, 35, 0, 0, 0, 0, 0,
  755. 0, 0, 43, 44, 39, 40, 0, 27, 28, 29,
  756. 52, 33, 0, 0, 0, 0, 0, 0, 0, 0,
  757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  758. 0, 0, 0, 0, 0, 0, 0, 0, 31, 0,
  759. 0, 3, 0, 0, 0, 0, 55, 56, 57, 58,
  760. 59, 60, 61, 62, 0, 0, 0, 0, 0, 0,
  761. 0, 0, 0, 0, 0, 0, 0, 0, 75, 39,
  762. 40, 0, 27, 28, 29, 81, 82, 83, 84, 85,
  763. 86, 87, 88, 89, 90, 91, 92, 93, 94, 95,
  764. 96, 97, 98, 99, 100, 101, 102, 0, 0, 0,
  765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  767. 0, 0, 115, 0, 0, 0, 0, 0, 0, 0,
  768. 0, 0, 0, 0, 27, 28, 29, 0, 0, 0,
  769. 0, 0, 0, 0, 0, 0, 118, 0, 0, 0,
  770. 0, 0, 119, 0, 0, 0, 0, 0, 122, 119,
  771. 0, 0, 0, 123, 0, 0, 0, 0, 0, 0,
  772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  778. 27, 28, 29 };
  779. short yypact[]={
  780. 212,-1000, -32, -2, 212, 212, 212, 212, 212, 212,
  781. 212, 247,-250, 168,-1000,-1000,-1000,-1000,-1000,-1000,
  782. -1000,-1000,-266,-1000,-1000,-1000, 212,-1000,-1000,-242,
  783. -242, 212,-1000, 212, 212, 212, 212, 212, 212, 212,
  784. 212, 212, 212, 212, 212, 212, 212, 212, 212, 212,
  785. 212, 212, 212, 212, 212, -24, -24, -24, -24, -24,
  786. -24, -24, -24, 168, -35,-1000,-1000,-242,-242,-242,
  787. -242, 7, -12,-1000,-242, -2,-1000,-1000,-1000, -40,
  788. 212, -24, 124, 124, 124, 517, 517, 421, 421, 294,
  789. 294, 359, 359, 359, 359, 259, 136, 103, 68, 33,
  790. -37, -2, -2, 5, 212,-1000,-1000,-1000,-1000,-1000,
  791. 212,-1000,-1000,-1000, -13, -2, 212, 212, -24, -24,
  792. -1000, 212, -2, -2 };
  793. short yypgo[]={
  794. 0, 611, 50, 55, 52, 20, 42, 37, 154, 33,
  795. 30 };
  796. short yyr1[]={
  797. 0, 3, 2, 2, 1, 1, 1, 1, 1, 1,
  798. 1, 1, 1, 1, 1, 1, 1, 9, 1, 10,
  799. 10, 10, 1, 1, 1, 1, 1, 1, 1, 1,
  800. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  801. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  802. 1, 1, 1, 1, 1, 1, 7, 7, 4, 4,
  803. 5, 5, 6, 6, 6, 6, 6, 8, 8 };
  804. short yyr2[]={
  805. 0, 1, 1, 3, 2, 2, 2, 2, 2, 2,
  806. 2, 2, 2, 2, 3, 3, 4, 0, 5, 0,
  807. 1, 3, 4, 4, 3, 3, 3, 3, 3, 3,
  808. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  809. 3, 3, 3, 3, 5, 3, 3, 1, 1, 1,
  810. 1, 1, 1, 1, 4, 1, 1, 3, 3, 1,
  811. 1, 2, 1, 2, 2, 2, 2, 1, 1 };
  812. short yychk[]={
  813. -1000, -3, -2, -1, 42, 38, 45, 33, 126, 283,
  814. 284, 266, 123, 40, 257, 258, 259, -4, 269, 270,
  815. 271, 262, -7, 260, -8, 261, 44, 283, 284, 285,
  816. 46, 91, 40, 64, 42, 47, 37, 43, 45, 280,
  817. 281, 276, 277, 278, 279, 60, 62, 38, 94, 124,
  818. 275, 274, 63, 61, 272, -1, -1, -1, -1, -1,
  819. -1, -1, -1, 40, -5, -6, 261, 263, 264, 265,
  820. 267, -5, -2, 261, 268, -1, -8, 260, -8, -2,
  821. -9, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  822. -1, -1, -1, -1, -1, -1, -1, -1, -1, -1,
  823. -1, -1, -1, -5, 125, 42, -8, -8, -8, -8,
  824. 41, 41, -8, 93, -10, -1, 58, 41, -1, -1,
  825. 41, 44, -1, -1 };
  826. short yydef[]={
  827. 0, -2, 1, 2, 0, 0, 0, 0, 0, 0,
  828. 0, 0, 0, 0, 47, 48, 49, 50, 51, 52,
  829. 53, 55, 0, -2, 56, 68, 0, 11, 12, 0,
  830. 0, 0, 17, 0, 0, 0, 0, 0, 0, 0,
  831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  832. 0, 0, 0, 0, 0, 4, 5, 6, 7, 8,
  833. 9, 10, 13, 0, 0, 60, 62, 0, 0, 0,
  834. 0, 0, 0, -2, 0, 3, 14, 67, 15, 0,
  835. 19, 25, 26, 27, 28, 29, 30, 31, 32, 33,
  836. 34, 35, 36, 37, 38, 39, 40, 41, 42, 43,
  837. 0, 45, 46, 0, 0, 61, 63, 64, 65, 66,
  838. 0, 24, -2, 16, 0, 20, 0, 54, 22, 23,
  839. 18, 0, 44, 21 };
  840. #ifndef lint
  841. static char yaccpar_sccsid[] = "@(#)yaccpar 4.1 (Berkeley) 2/11/83";
  842. #endif not lint
  843. #
  844. # define YYFLAG -1000
  845. # define YYERROR goto yyerrlab
  846. # define YYACCEPT return(0)
  847. # define YYABORT return(1)
  848. /* parser for yacc output */
  849. #ifdef YYDEBUG
  850. int yydebug = 0; /* 1 for debugging */
  851. #endif
  852. YYSTYPE yyv[YYMAXDEPTH]; /* where the values are stored */
  853. int yychar = -1; /* current input token number */
  854. int yynerrs = 0; /* number of errors */
  855. short yyerrflag = 0; /* error recovery flag */
  856. yyparse() {
  857. short yys[YYMAXDEPTH];
  858. short yyj, yym;
  859. register YYSTYPE *yypvt;
  860. register short yystate, *yyps, yyn;
  861. register YYSTYPE *yypv;
  862. register short *yyxi;
  863. yystate = 0;
  864. yychar = -1;
  865. yynerrs = 0;
  866. yyerrflag = 0;
  867. yyps= &yys[-1];
  868. yypv= &yyv[-1];
  869. yystack: /* put a state and value onto the stack */
  870. #ifdef YYDEBUG
  871. if( yydebug ) printf( "state %d, char 0%o\n", yystate, yychar );
  872. #endif
  873. if( ++yyps> &yys[YYMAXDEPTH] ) { yyerror( "yacc stack overflow" ); return(1); }
  874. *yyps = yystate;
  875. ++yypv;
  876. *yypv = yyval;
  877. yynewstate:
  878. yyn = yypact[yystate];
  879. if( yyn<= YYFLAG ) goto yydefault; /* simple state */
  880. if( yychar<0 ) if( (yychar=yylex())<0 ) yychar=0;
  881. if( (yyn += yychar)<0 || yyn >= YYLAST ) goto yydefault;
  882. if( yychk[ yyn=yyact[ yyn ] ] == yychar ){ /* valid shift */
  883. yychar = -1;
  884. yyval = yylval;
  885. yystate = yyn;
  886. if( yyerrflag > 0 ) --yyerrflag;
  887. goto yystack;
  888. }
  889. yydefault:
  890. /* default state action */
  891. if( (yyn=yydef[yystate]) == -2 ) {
  892. if( yychar<0 ) if( (yychar=yylex())<0 ) yychar = 0;
  893. /* look through exception table */
  894. for( yyxi=yyexca; (*yyxi!= (-1)) || (yyxi[1]!=yystate) ; yyxi += 2 ) ; /* VOID */
  895. while( *(yyxi+=2) >= 0 ){
  896. if( *yyxi == yychar ) break;
  897. }
  898. if( (yyn = yyxi[1]) < 0 ) return(0); /* accept */
  899. }
  900. if( yyn == 0 ){ /* error */
  901. /* error ... attempt to resume parsing */
  902. switch( yyerrflag ){
  903. case 0: /* brand new error */
  904. yyerror( "syntax error" );
  905. yyerrlab:
  906. ++yynerrs;
  907. case 1:
  908. case 2: /* incompletely recovered error ... try again */
  909. yyerrflag = 3;
  910. /* find a state where "error" is a legal shift action */
  911. while ( yyps >= yys ) {
  912. yyn = yypact[*yyps] + YYERRCODE;
  913. if( yyn>= 0 && yyn < YYLAST && yychk[yyact[yyn]] == YYERRCODE ){
  914. yystate = yyact[yyn]; /* simulate a shift of "error" */
  915. goto yystack;
  916. }
  917. yyn = yypact[*yyps];
  918. /* the current yyps has no shift onn "error", pop stack */
  919. #ifdef YYDEBUG
  920. if( yydebug ) printf( "error recovery pops state %d, uncovers %d\n", *yyps, yyps[-1] );
  921. #endif
  922. --yyps;
  923. --yypv;
  924. }
  925. /* there is no state on the stack with an error shift ... abort */
  926. yyabort:
  927. return(1);
  928. case 3: /* no shift yet; clobber input char */
  929. #ifdef YYDEBUG
  930. if( yydebug ) printf( "error recovery discards char %d\n", yychar );
  931. #endif
  932. if( yychar == 0 ) goto yyabort; /* don't discard EOF, quit */
  933. yychar = -1;
  934. goto yynewstate; /* try again in the same state */
  935. }
  936. }
  937. /* reduction by production yyn */
  938. #ifdef YYDEBUG
  939. if( yydebug ) printf("reduce %d\n",yyn);
  940. #endif
  941. yyps -= yyr2[yyn];
  942. yypvt = yypv;
  943. yypv -= yyr2[yyn];
  944. yyval = yypv[1];
  945. yym=yyn;
  946. /* consult goto table to find next state */
  947. yyn = yyr1[yyn];
  948. yyj = yypgo[yyn] + *yyps + 1;
  949. if( yyj>=YYLAST || yychk[ yystate = yyact[yyj] ] != -yyn ) yystate = yyact[yypgo[yyn]];
  950. switch(yym){
  951. case 3:
  952. # line 151 "expread.y"
  953. { write_exp_elt (BINOP_COMMA); } break;
  954. case 4:
  955. # line 156 "expread.y"
  956. { write_exp_elt (UNOP_IND); } break;
  957. case 5:
  958. # line 159 "expread.y"
  959. { write_exp_elt (UNOP_ADDR); } break;
  960. case 6:
  961. # line 162 "expread.y"
  962. { write_exp_elt (UNOP_NEG); } break;
  963. case 7:
  964. # line 166 "expread.y"
  965. { write_exp_elt (UNOP_ZEROP); } break;
  966. case 8:
  967. # line 170 "expread.y"
  968. { write_exp_elt (UNOP_LOGNOT); } break;
  969. case 9:
  970. # line 174 "expread.y"
  971. { write_exp_elt (UNOP_PREINCREMENT); } break;
  972. case 10:
  973. # line 178 "expread.y"
  974. { write_exp_elt (UNOP_PREDECREMENT); } break;
  975. case 11:
  976. # line 182 "expread.y"
  977. { write_exp_elt (UNOP_POSTINCREMENT); } break;
  978. case 12:
  979. # line 186 "expread.y"
  980. { write_exp_elt (UNOP_POSTDECREMENT); } break;
  981. case 13:
  982. # line 190 "expread.y"
  983. { write_exp_elt (UNOP_SIZEOF); } break;
  984. case 14:
  985. # line 194 "expread.y"
  986. { write_exp_elt (STRUCTOP_PTR);
  987. write_exp_string (yypvt[-0].sval);
  988. write_exp_elt (STRUCTOP_PTR); } break;
  989. case 15:
  990. # line 200 "expread.y"
  991. { write_exp_elt (STRUCTOP_STRUCT);
  992. write_exp_string (yypvt[-0].sval);
  993. write_exp_elt (STRUCTOP_STRUCT); } break;
  994. case 16:
  995. # line 206 "expread.y"
  996. { write_exp_elt (BINOP_SUBSCRIPT); } break;
  997. case 17:
  998. # line 212 "expread.y"
  999. { start_arglist (); } break;
  1000. case 18:
  1001. # line 214 "expread.y"
  1002. { write_exp_elt (OP_FUNCALL);
  1003. write_exp_elt (end_arglist ());
  1004. write_exp_elt (OP_FUNCALL); } break;
  1005. case 20:
  1006. # line 223 "expread.y"
  1007. { arglist_len = 1; } break;
  1008. case 21:
  1009. # line 227 "expread.y"
  1010. { arglist_len++; } break;
  1011. case 22:
  1012. # line 231 "expread.y"
  1013. { write_exp_elt (UNOP_MEMVAL);
  1014. write_exp_elt (yypvt[-2].tval);
  1015. write_exp_elt (UNOP_MEMVAL); } break;
  1016. case 23:
  1017. # line 237 "expread.y"
  1018. { write_exp_elt (UNOP_CAST);
  1019. write_exp_elt (yypvt[-2].tval);
  1020. write_exp_elt (UNOP_CAST); } break;
  1021. case 24:
  1022. # line 243 "expread.y"
  1023. { } break;
  1024. case 25:
  1025. # line 249 "expread.y"
  1026. { write_exp_elt (BINOP_REPEAT); } break;
  1027. case 26:
  1028. # line 253 "expread.y"
  1029. { write_exp_elt (BINOP_MUL); } break;
  1030. case 27:
  1031. # line 257 "expread.y"
  1032. { write_exp_elt (BINOP_DIV); } break;
  1033. case 28:
  1034. # line 261 "expread.y"
  1035. { write_exp_elt (BINOP_REM); } break;
  1036. case 29:
  1037. # line 265 "expread.y"
  1038. { write_exp_elt (BINOP_ADD); } break;
  1039. case 30:
  1040. # line 269 "expread.y"
  1041. { write_exp_elt (BINOP_SUB); } break;
  1042. case 31:
  1043. # line 273 "expread.y"
  1044. { write_exp_elt (BINOP_LSH); } break;
  1045. case 32:
  1046. # line 277 "expread.y"
  1047. { write_exp_elt (BINOP_RSH); } break;
  1048. case 33:
  1049. # line 281 "expread.y"
  1050. { write_exp_elt (BINOP_EQUAL); } break;
  1051. case 34:
  1052. # line 285 "expread.y"
  1053. { write_exp_elt (BINOP_NOTEQUAL); } break;
  1054. case 35:
  1055. # line 289 "expread.y"
  1056. { write_exp_elt (BINOP_LEQ); } break;
  1057. case 36:
  1058. # line 293 "expread.y"
  1059. { write_exp_elt (BINOP_GEQ); } break;
  1060. case 37:
  1061. # line 297 "expread.y"
  1062. { write_exp_elt (BINOP_LESS); } break;
  1063. case 38:
  1064. # line 301 "expread.y"
  1065. { write_exp_elt (BINOP_GTR); } break;
  1066. case 39:
  1067. # line 305 "expread.y"
  1068. { write_exp_elt (BINOP_LOGAND); } break;
  1069. case 40:
  1070. # line 309 "expread.y"
  1071. { write_exp_elt (BINOP_LOGXOR); } break;
  1072. case 41:
  1073. # line 313 "expread.y"
  1074. { write_exp_elt (BINOP_LOGIOR); } break;
  1075. case 42:
  1076. # line 317 "expread.y"
  1077. { write_exp_elt (BINOP_AND); } break;
  1078. case 43:
  1079. # line 321 "expread.y"
  1080. { write_exp_elt (BINOP_OR); } break;
  1081. case 44:
  1082. # line 325 "expread.y"
  1083. { write_exp_elt (TERNOP_COND); } break;
  1084. case 45:
  1085. # line 329 "expread.y"
  1086. { write_exp_elt (BINOP_ASSIGN); } break;
  1087. case 46:
  1088. # line 333 "expread.y"
  1089. { write_exp_elt (BINOP_ASSIGN_MODIFY);
  1090. write_exp_elt (yypvt[-1].opcode);
  1091. write_exp_elt (BINOP_ASSIGN_MODIFY); } break;
  1092. case 47:
  1093. # line 339 "expread.y"
  1094. { write_exp_elt (OP_LONG);
  1095. write_exp_elt (builtin_type_long);
  1096. write_exp_elt (yypvt[-0].lval);
  1097. write_exp_elt (OP_LONG); } break;
  1098. case 48:
  1099. # line 346 "expread.y"
  1100. { write_exp_elt (OP_LONG);
  1101. write_exp_elt (builtin_type_char);
  1102. write_exp_elt (yypvt[-0].lval);
  1103. write_exp_elt (OP_LONG); } break;
  1104. case 49:
  1105. # line 353 "expread.y"
  1106. { write_exp_elt (OP_DOUBLE);
  1107. write_exp_elt (builtin_type_double);
  1108. write_exp_elt (yypvt[-0].dval);
  1109. write_exp_elt (OP_DOUBLE); } break;
  1110. case 51:
  1111. # line 363 "expread.y"
  1112. { write_exp_elt (OP_LAST);
  1113. write_exp_elt (yypvt[-0].lval);
  1114. write_exp_elt (OP_LAST); } break;
  1115. case 52:
  1116. # line 369 "expread.y"
  1117. { write_exp_elt (OP_REGISTER);
  1118. write_exp_elt (yypvt[-0].lval);
  1119. write_exp_elt (OP_REGISTER); } break;
  1120. case 53:
  1121. # line 375 "expread.y"
  1122. { write_exp_elt (OP_INTERNALVAR);
  1123. write_exp_elt (yypvt[-0].ivar);
  1124. write_exp_elt (OP_INTERNALVAR); } break;
  1125. case 54:
  1126. # line 381 "expread.y"
  1127. { write_exp_elt (OP_LONG);
  1128. write_exp_elt (builtin_type_int);
  1129. write_exp_elt ((long) TYPE_LENGTH (yypvt[-1].tval));
  1130. write_exp_elt (OP_LONG); } break;
  1131. case 55:
  1132. # line 388 "expread.y"
  1133. { write_exp_elt (OP_STRING);
  1134. write_exp_string (yypvt[-0].sval);
  1135. write_exp_elt (OP_STRING); } break;
  1136. case 56:
  1137. # line 394 "expread.y"
  1138. { struct symtab *tem = lookup_symtab (copy_name (yypvt[-0].sval));
  1139. struct symbol *sym;
  1140. if (tem)
  1141. yyval.bval = BLOCKVECTOR_BLOCK (BLOCKVECTOR (tem), 1);
  1142. else
  1143. {
  1144. sym = lookup_symbol (copy_name (yypvt[-0].sval),
  1145. expression_context_block,
  1146. VAR_NAMESPACE);
  1147. if (sym && SYMBOL_CLASS (sym) == LOC_BLOCK)
  1148. yyval.bval = SYMBOL_BLOCK_VALUE (sym);
  1149. else
  1150. error ("No file or function \"%s\".",
  1151. copy_name (yypvt[-0].sval));
  1152. }} break;
  1153. case 57:
  1154. # line 413 "expread.y"
  1155. { struct symbol *tem
  1156. = lookup_symbol (yypvt[-0].sval, copy_name (yypvt[-2].bval), VAR_NAMESPACE);
  1157. if (!tem || SYMBOL_CLASS (tem) != LOC_BLOCK)
  1158. error ("No function \"%s\" in specified context.",
  1159. copy_name (yypvt[-2].bval));
  1160. yyval.bval = SYMBOL_BLOCK_VALUE (tem); } break;
  1161. case 58:
  1162. # line 422 "expread.y"
  1163. { struct symbol *sym;
  1164. sym = lookup_symbol (yypvt[-0].sval, copy_name (yypvt[-2].bval), VAR_NAMESPACE);
  1165. if (sym == 0)
  1166. error ("No symbol \"%s\" in specified context.",
  1167. copy_name (yypvt[-0].sval));
  1168. write_exp_elt (OP_VAR_VALUE);
  1169. write_exp_elt (sym);
  1170. write_exp_elt (OP_VAR_VALUE); } break;
  1171. case 59:
  1172. # line 433 "expread.y"
  1173. { struct symbol *sym;
  1174. sym = lookup_symbol (copy_name (yypvt[-0].sval),
  1175. expression_context_block,
  1176. VAR_NAMESPACE);
  1177. if (sym)
  1178. {
  1179. write_exp_elt (OP_VAR_VALUE);
  1180. write_exp_elt (sym);
  1181. write_exp_elt (OP_VAR_VALUE);
  1182. }
  1183. else
  1184. {
  1185. register char *arg = copy_name (yypvt[-0].sval);
  1186. register int i;
  1187. for (i = 0; i < misc_function_count; i++)
  1188. if (!strcmp (misc_function_vector[i].name, arg))
  1189. break;
  1190. if (i < misc_function_count)
  1191. {
  1192. write_exp_elt (OP_LONG);
  1193. write_exp_elt (builtin_type_int);
  1194. write_exp_elt (misc_function_vector[i].address);
  1195. write_exp_elt (OP_LONG);
  1196. write_exp_elt (UNOP_MEMVAL);
  1197. write_exp_elt (builtin_type_char);
  1198. write_exp_elt (UNOP_MEMVAL);
  1199. }
  1200. else
  1201. if (symtab_list == 0)
  1202. error ("No symbol table is loaded. Use the \"symbol-file\" command.");
  1203. else
  1204. error ("No symbol \"%s\" in current context.",
  1205. copy_name (yypvt[-0].sval));
  1206. }
  1207. } break;
  1208. case 61:
  1209. # line 473 "expread.y"
  1210. { yyval.tval = lookup_pointer_type (yypvt[-1].tval); } break;
  1211. case 62:
  1212. # line 478 "expread.y"
  1213. { yyval.tval = lookup_typename (copy_name (yypvt[-0].sval),
  1214. expression_context_block, 0); } break;
  1215. case 63:
  1216. # line 481 "expread.y"
  1217. { yyval.tval = lookup_struct (copy_name (yypvt[-0].sval),
  1218. expression_context_block); } break;
  1219. case 64:
  1220. # line 484 "expread.y"
  1221. { yyval.tval = lookup_union (copy_name (yypvt[-0].sval),
  1222. expression_context_block); } break;
  1223. case 65:
  1224. # line 487 "expread.y"
  1225. { yyval.tval = lookup_enum (copy_name (yypvt[-0].sval),
  1226. expression_context_block); } break;
  1227. case 66:
  1228. # line 490 "expread.y"
  1229. { yyval.tval = lookup_unsigned_typename (copy_name (yypvt[-0].sval)); } break;
  1230. }
  1231. goto yystack; /* stack new state and value */
  1232. }