comm2.y 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. /* $Header$ */
  2. /*
  3. * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
  4. * See the copyright notice in the ACK home directory, in the file "Copyright".
  5. */
  6. /* @(#)comm2.y 1.7 */
  7. /*
  8. * delay inclusion of machine dependent stuff (see comm0.h)
  9. */
  10. #define _include #include
  11. %{
  12. #include "comm0.h"
  13. #include "comm1.h"
  14. %}
  15. /* ========== Machine independent Yacc definitions ========== */
  16. %union {
  17. word_t y_word;
  18. valu_t y_valu;
  19. expr_t y_expr;
  20. item_t *y_item;
  21. #ifdef ASLD
  22. char *y_strp;
  23. #endif
  24. };
  25. #ifdef ASLD
  26. %token <y_strp> MODULE
  27. #endif
  28. %token STRING
  29. %token <y_item> IDENT
  30. %token <y_item> FBSYM
  31. %token <y_valu> CODE1
  32. %token <y_valu> CODE2
  33. %token <y_valu> CODE4
  34. %token NUMBER0 /* keep NUMBER* in this order */
  35. %token NUMBER1
  36. %token NUMBER2
  37. %token NUMBER3
  38. %token <y_valu> NUMBER
  39. %token DOT
  40. %token EXTERN
  41. %token <y_word> DATA
  42. %token <y_word> ASCII
  43. %token SECTION
  44. %token COMMON
  45. %token BASE
  46. %token SYMB
  47. %token ALIGN
  48. %token ASSERT
  49. %token SPACE
  50. %token <y_word> LINE
  51. %token FILe
  52. %token <y_word> LIST
  53. %token OP_EQ
  54. %token OP_NE
  55. %token OP_LE
  56. %token OP_GE
  57. %token OP_LL
  58. %token OP_RR
  59. %token OP_OO
  60. %token OP_AA
  61. %left OP_OO
  62. %left OP_AA
  63. %left '|'
  64. %left '^'
  65. %left '&'
  66. %left OP_EQ OP_NE
  67. %left '<' '>' OP_LE OP_GE
  68. %left OP_LL OP_RR
  69. %left '+' '-'
  70. %left '*' '/' '%'
  71. %nonassoc '~'
  72. %type <y_valu> absexp optabs1 optabs2
  73. %type <y_expr> expr
  74. %type <y_item> id_fb
  75. /* ========== Machine dependent Yacc definitions ========== */
  76. #include "mach2.c"
  77. %%
  78. /* ========== Machine independent rules ========== */
  79. #ifdef LISTING
  80. #define LISTLINE(n) listline(n)
  81. #else
  82. #define LISTLINE(n) /* empty */
  83. #endif LISTING
  84. #ifdef ASLD
  85. #define RELODONE /* empty */
  86. #else
  87. #define RELODONE assert(relonami == 0)
  88. #endif
  89. program : /* empty */
  90. #ifdef ASLD
  91. | program MODULE /* not in PASS_1 */
  92. { newmodule($2);}
  93. #endif
  94. | program IDENT ':'
  95. { newident($2, DOTTYP); newlabel($2);}
  96. | program NUMBER ':'
  97. { if ($2 < 0 || $2 > 9) {
  98. serror("bad f/b label");
  99. $2 = 0;
  100. }
  101. newlabel(fb_shift((int)$2));
  102. }
  103. | program CODE1
  104. { emit1((char)$2); LISTLINE(0);}
  105. | program CODE2
  106. { emit2((short)$2); LISTLINE(0);}
  107. | program CODE4
  108. { emit4((long)$2); LISTLINE(0);}
  109. | program operation ';'
  110. | program operation '\n'
  111. { lineno++; LISTLINE(1); RELODONE;}
  112. | program '#' NUMBER STRING '\n'
  113. { lineno++; LISTLINE(1); RELODONE;}
  114. | program error '\n'
  115. { serror("syntax error"); yyerrok;
  116. lineno++; LISTLINE(1); RELODONE;
  117. }
  118. ;
  119. #undef LISTLINE
  120. #undef RELODONE
  121. operation
  122. : /* empty */
  123. | IDENT '=' expr
  124. {
  125. #ifdef LISTING
  126. if (listflag & 1)
  127. listcolm += printx(VALWIDTH, $3.val);
  128. #endif
  129. newequate($1, $3.typ);
  130. store($1, $3.val);
  131. }
  132. #ifdef LISTING
  133. | LIST
  134. { if ($1)
  135. listtemp = listmode;
  136. else if ((dflag & 01000) == 0)
  137. listtemp = 0;
  138. }
  139. #endif
  140. | SECTION IDENT
  141. { newsect($2);}
  142. | COMMON IDENT ',' absexp
  143. { newcomm($2, $4);}
  144. | BASE absexp
  145. { if (pass == PASS_1) newbase($2);}
  146. | ASSERT expr
  147. { if ($2.val == 0 && pass == PASS_3)
  148. warning("assertion failed");
  149. }
  150. | SYMB STRING ',' expr optabs2 optabs2
  151. { if ((sflag & SYM_SMB) && PASS_SYMB) {
  152. #ifndef ASLD
  153. if (
  154. pass == PASS_3
  155. &&
  156. ($4.typ & S_TYP) == S_UND
  157. ) {
  158. serror("expression undefined");
  159. relonami = -1;
  160. }
  161. #endif
  162. newsymb(
  163. stringbuf+1,
  164. (short)(
  165. ($4.typ & (S_EXT|S_TYP))
  166. |
  167. ((ushort)$5<<8)
  168. ),
  169. (short)$6,
  170. $4.val
  171. );
  172. }
  173. }
  174. | LINE optabs1
  175. { if ((sflag & SYM_LIN) && PASS_SYMB) {
  176. if ($2)
  177. hllino = (short)$2;
  178. else
  179. hllino++;
  180. newsymb(
  181. (char *)0,
  182. (short)(DOTTYP | S_LIN),
  183. (short)hllino,
  184. (valu_t)DOTVAL
  185. );
  186. }
  187. }
  188. | FILe STRING
  189. { if ((sflag & SYM_LIN) && PASS_SYMB) {
  190. hllino = 0;
  191. newsymb(
  192. stringbuf+1,
  193. (short)(DOTTYP | S_FIL),
  194. (short)0,
  195. (valu_t)DOTVAL
  196. );
  197. }
  198. }
  199. | EXTERN externlist
  200. | ALIGN optabs1
  201. { align($2);}
  202. | SPACE absexp
  203. { if (DOTSCT == NULL)
  204. nosect();
  205. DOTVAL += $2;
  206. DOTSCT->s_zero += $2;
  207. }
  208. | DATA datalist
  209. | ASCII STRING
  210. { emitstr($1);}
  211. ;
  212. externlist
  213. : IDENT
  214. { $1->i_type |= S_EXT;}
  215. | externlist ',' IDENT
  216. { $3->i_type |= S_EXT;}
  217. ;
  218. datalist
  219. : expr
  220. {
  221. #ifdef RELOCATION
  222. if (rflag != 0 && PASS_RELO)
  223. newrelo($1.typ, (int)$<y_word>0|MACHREL_BWR);
  224. #endif
  225. emitx($1.val, (int)$<y_word>0);
  226. }
  227. | datalist ',' expr
  228. {
  229. #ifdef RELOCATION
  230. if (rflag != 0 && PASS_RELO)
  231. newrelo($3.typ, (int)$<y_word>0|MACHREL_BWR);
  232. #endif
  233. emitx($3.val, (int)$<y_word>0);
  234. }
  235. ;
  236. expr : error
  237. { serror("expr syntax err");
  238. $$.val = 0; $$.typ = S_UND;
  239. }
  240. | NUMBER
  241. { $$.val = $1; $$.typ = S_ABS;}
  242. | id_fb
  243. { $$.val = load($1);
  244. $$.typ = $1->i_type & ~S_EXT;
  245. }
  246. | STRING
  247. { if (stringbuf[0] != 1)
  248. serror("too many chars");
  249. $$.val = stringbuf[1];
  250. $$.typ = S_ABS;
  251. }
  252. | ASC_LPAR expr ASC_RPAR
  253. { $$ = $2;}
  254. | expr OP_OO expr
  255. { $$.val = ($1.val || $3.val);
  256. $$.typ = combine($1.typ, $3.typ, 0);
  257. }
  258. | expr OP_AA expr
  259. { $$.val = ($1.val && $3.val);
  260. $$.typ = combine($1.typ, $3.typ, 0);
  261. }
  262. | expr '|' expr
  263. { $$.val = ($1.val | $3.val);
  264. $$.typ = combine($1.typ, $3.typ, 0);
  265. }
  266. | expr '^' expr
  267. { $$.val = ($1.val ^ $3.val);
  268. $$.typ = combine($1.typ, $3.typ, 0);
  269. }
  270. | expr '&' expr
  271. { $$.val = ($1.val & $3.val);
  272. $$.typ = combine($1.typ, $3.typ, 0);
  273. }
  274. | expr OP_EQ expr
  275. { $$.val = ($1.val == $3.val);
  276. $$.typ = combine($1.typ, $3.typ, '>');
  277. }
  278. | expr OP_NE expr
  279. { $$.val = ($1.val != $3.val);
  280. $$.typ = combine($1.typ, $3.typ, '>');
  281. }
  282. | expr '<' expr
  283. { $$.val = ($1.val < $3.val);
  284. $$.typ = combine($1.typ, $3.typ, '>');
  285. }
  286. | expr '>' expr
  287. { $$.val = ($1.val > $3.val);
  288. $$.typ = combine($1.typ, $3.typ, '>');
  289. }
  290. | expr OP_LE expr
  291. { $$.val = ($1.val <= $3.val);
  292. $$.typ = combine($1.typ, $3.typ, '>');
  293. }
  294. | expr OP_GE expr
  295. { $$.val = ($1.val >= $3.val);
  296. $$.typ = combine($1.typ, $3.typ, '>');
  297. }
  298. | expr OP_RR expr
  299. { $$.val = ($1.val >> $3.val);
  300. $$.typ = combine($1.typ, $3.typ, 0);
  301. }
  302. | expr OP_LL expr
  303. { $$.val = ($1.val << $3.val);
  304. $$.typ = combine($1.typ, $3.typ, 0);
  305. }
  306. | expr '+' expr
  307. { $$.val = ($1.val + $3.val);
  308. $$.typ = combine($1.typ, $3.typ, '+');
  309. }
  310. | expr '-' expr
  311. { $$.val = ($1.val - $3.val);
  312. $$.typ = combine($1.typ, $3.typ, '-');
  313. }
  314. | expr '*' expr
  315. { $$.val = ($1.val * $3.val);
  316. $$.typ = combine($1.typ, $3.typ, 0);
  317. }
  318. | expr '/' expr
  319. { if ($3.val == 0) {
  320. if (pass == PASS_3)
  321. serror("divide by zero");
  322. $$.val = 0;
  323. } else
  324. $$.val = ($1.val / $3.val);
  325. $$.typ = combine($1.typ, $3.typ, 0);
  326. }
  327. | expr '%' expr
  328. { if ($3.val == 0) {
  329. if (pass == PASS_3)
  330. serror("divide by zero");
  331. $$.val = 0;
  332. } else
  333. $$.val = ($1.val % $3.val);
  334. $$.typ = combine($1.typ, $3.typ, 0);
  335. }
  336. | '+' expr %prec '*'
  337. { $$.val = $2.val;
  338. $$.typ = combine(S_ABS, $2.typ, 0);
  339. }
  340. | '-' expr %prec '*'
  341. { $$.val = -$2.val;
  342. $$.typ = combine(S_ABS, $2.typ, 0);
  343. }
  344. | '~' expr
  345. { $$.val = ~$2.val;
  346. $$.typ = combine(S_ABS, $2.typ, 0);
  347. }
  348. | DOT
  349. { $$.val = DOTVAL;
  350. $$.typ = DOTTYP|S_DOT;
  351. }
  352. ;
  353. id_fb : IDENT
  354. | FBSYM
  355. ;
  356. absexp : expr
  357. { if (($1.typ & ~S_EXT) != S_ABS)
  358. serror("must be absolute");
  359. $$ = $1.val;
  360. }
  361. ;
  362. optabs1
  363. : /* empty */
  364. { $$ = 0;}
  365. | absexp
  366. { $$ = $1;}
  367. ;
  368. optabs2
  369. : /* empty */
  370. { $$ = 0;}
  371. | ',' absexp
  372. { $$ = $2;}
  373. ;
  374. /* ========== Machine dependent rules ========== */
  375. #include "mach4.c"
  376. %%