1 /****************************************************************************
2     Copyright (C) 1987-2015 by Jeffery P. Hansen
3 
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8 
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12     GNU General Public License for more details.
13 
14     You should have received a copy of the GNU General Public License along
15     with this program; if not, write to the Free Software Foundation, Inc.,
16     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17 
18     Last edit by hansen on Wed Jan  7 14:51:23 2004
19 ****************************************************************************/
20 %token <I> MICROCODE MACROCODE MAP
21 
22 %token BANK FIELD REGISTERS OPERANDS OP KWBEGIN KWEND NL
23 
24 %token SEMI COLON COMMA ASGN HASH TILDE PERCENT PLUS AT BOGOCHAR MINUS
25 %token LBRACE RBRACE LPAREN RPAREN LBRACK RBRACK
26 
27 %token <I> DSHORT DLONG DBYTE DSYMBOL DBSS DPROC DEND
28 
29 %token <I> NUMBER
30 %token <S> LITERAL
31 %token <I> REGISTER
32 %token <S> STRING
33 
34 %type <S>  label
35 %type <I> what dtype register offset opasgn
36 %type <R> brange obrange
37 %type <N> number
38 
39 %{
40 #include "parser.h"
41 #include "grammar.h"
42 %}
43 
44 %%
45 
46 prog		: top_item
47 		| prog top_item
48 		;
49 
50 top_item	: bank_decl
51 		| field_decl
52 		| reg_decl
53 		| operand_decl
54 		| op_decl
55 		| ucode
56 		| mcode
57 		| error SEMI { yyerrok; }
58 		| error KWEND { yyerrok; }
59 		;
60 
61 /***********************************************************************
62  * Bank and map declarations
63  ***********************************************************************/
64 bank_decl	: what BANK brange LITERAL SEMI 	{ ycBank($1,&$3,$4,0); }
65 		| what BANK brange LITERAL brange SEMI	{ ycBank($1,&$3,$4,&$5); }
66 		;
67 
68 /***********************************************************************
69  * Field declarations
70  ***********************************************************************/
71 field_decl	: FIELD fitems SEMI
72 		;
73 
74 fitems		: fitem
75 		| fitems COMMA fitem
76 		;
77 
78 fitem		: TILDE LITERAL brange			{ ycField($2,&$3,1); }
79 		| LITERAL brange			{ ycField($1,&$2,0); }
80 		| LITERAL brange ASGN { ycField($1,&$2,0); } enumset
81 		;
82 
83 enumset		: LBRACE eitems RBRACE
84 		;
85 
86 eitems		: eitem
87 		| eitems COMMA eitem
88 		;
89 
90 eitem		: LITERAL ASGN NUMBER			{ ycEnum($1,$3); }
91 		;
92 
93 /***********************************************************************
94  * Register declarations
95  ***********************************************************************/
96 reg_decl	: REGISTERS regs SEMI
97 		;
98 
99 regs		: reg
100 		| regs COMMA reg
101 		;
102 
103 reg		: LITERAL ASGN NUMBER			{ ycRegRecord($1,$3); }
104 		;
105 /***********************************************************************
106  * Operand declarations
107  ***********************************************************************/
108 operand_decl	: OPERANDS LITERAL LBRACE { ycBeginOprGroup($2); } operdefs
109 			{ ycEndOprGroup(); } RBRACE SEMI
110 		;
111 
112 operdefs	:
113 		| operdefs operdef
114 		;
115 
116 operdef		: {ycBeginOperand();} oprlhss ASGN LBRACE opasgns RBRACE SEMI {ycEndOperand();}
117 		| {ycBeginOperand();} MINUS ASGN LBRACE opasgns RBRACE SEMI {ycEndOperand();}
118 
119 		;
120 
121 oprlhss		: oprlhs
122 		| oprlhss COMMA oprlhs
123 		;
124 
125 oprlhs		: PERCENT NUMBER				 { ycOLHS(AM_DIRECT,$2,0); }
126 		| HASH NUMBER					 { ycOLHS(AM_IMMEDIATE,0,$2); }
127 		| LPAREN PERCENT NUMBER RPAREN			 { ycOLHS(AM_INDIRECT,$3,0); }
128 		| HASH NUMBER LPAREN PERCENT NUMBER RPAREN	 { ycOLHS(AM_INDEXED,$5,$2); }
129 		| LPAREN HASH NUMBER RPAREN			 { ycOLHS(AM_IMMIND,0,$3); }
130 		;
131 
132 opasgns		:
133 		| opasgns opasgn SEMI
134 		;
135 
136 opasgn		: PLUS NUMBER obrange ASGN NUMBER obrange		{ ycORHS(OI_DATA,$2,&$3,$5,&$6,0); $$ = $5; }
137 		| PLUS NUMBER obrange ASGN HASH NUMBER offset obrange	{ ycORHS(OI_RELNUMOP,$2,&$3,$6,&$8,$7); $$ = 0; }
138 		| PLUS NUMBER obrange ASGN HASH NUMBER obrange		{ ycORHS(OI_NUMOP,$2,&$3,$6,&$7,0); $$ = 0; }
139 		| PLUS NUMBER obrange ASGN PERCENT NUMBER obrange	{ ycORHS(OI_REGOP,$2,&$3,$6,&$7,0); $$ = 0; }
140 		;
141 
142 offset 		: AT NUMBER	{ $$ = $2; }
143 		| AT		{ $$ = 0; }
144 		;
145 
146 /***********************************************************************
147  * Opcode declarations
148  ***********************************************************************/
149 op_decl		: OP LITERAL LBRACE { ycBeginOp($2); } opditems { ycEndOp(); } RBRACE SEMI
150 		;
151 
152 opditems	:
153 		| opditems opditem
154 		;
155 
156 opditem		: MAP number COLON number SEMI		{ ycMap(&$2,&$4); }
157 		| MAP number COLON opasgn SEMI		{ Number N; N.v.d = $4; N.ntype = NT_VALUE; ycMap(&$2,&N); }
158 		| opasgn SEMI { }
159 		| OPERANDS LITERAL SEMI { ycAddOprGroup($2); }
160 		| OPERANDS LBRACE  { ycBeginOprGroup(0); } operdefs
161 			{ ycEndOprGroup(); } RBRACE SEMI
162 		;
163 
164 /***********************************************************************
165  * Microcode declarations
166  ***********************************************************************/
167 ucode		: KWBEGIN MICROCODE AT NUMBER { ycBeginUCode($4); } uops KWEND { ycEndUCode(); }
168 		;
169 
170 uops		:
171 		| uops uop { ycUNext(); }
172 		;
173 
174 uop		: uspecs SEMI
175 		| label { ycULabel($1); } uspecs SEMI
176 		| error SEMI { yyerrok; }
177 		;
178 
179 uspecs		: uspec
180 		| uspecs uspec
181 		;
182 
183 uspec		: number			{ ycUSpec(&$1,0); }
184 		| number ASGN number		{ ycUSpec(&$1,&$3); }
185 		;
186 
187 
188 /***********************************************************************
189  * Macrocode declarations
190  ***********************************************************************/
191 
192 mcode		: KWBEGIN MACROCODE AT NUMBER { BeginMA(); ycBeginMCode($4); } NL
193 			mops KWEND { ycEndMCode(); BeginBA(); }
194 		;
195 
196 mops		:
197 		| mops lmop NL { ycMNext(); }
198 		| error NL { yyerrok; }
199 		;
200 
201 lmop		: mop
202 		| label { ycMLabel($1); } mop
203 		| label DSYMBOL NUMBER { ycMSymbol($1,$3); }
204 		| DPROC LITERAL { ycBeginProc($2); }
205 		| DEND { ycEndProc(); }
206 		;
207 
208 mop		: LITERAL { ycMOp($1); } operands
209 		| LITERAL { ycMOp($1); }
210 		| dtype { ycData($1); } bsl_items
211 		| DBSS NUMBER { ycBss($2); }
212 		|
213 		;
214 
215 dtype		: DBYTE		 { $$ = $1; }
216 		| DSHORT	 { $$ = $1; }
217 		| DLONG		 { $$ = $1; }
218 		;
219 
220 bsl_items	: bsl_item
221 		| bsl_items COMMA bsl_item
222 		;
223 
224 bsl_item	: NUMBER	{ ycDataNum($1); }
225 		| LITERAL	{ ycDataLit($1); }
226 		| STRING	{ ycDataStr($1); }
227 		;
228 
229 operands	: operand
230 		| operands COMMA operand
231 		;
232 
233 operand		: number				{ ycMOperand(AM_IMMEDIATE,Number_copy(&$1),0); }
234 		| register				{ ycMOperand(AM_DIRECT,0,$1); }
235 		| LPAREN register RPAREN		{ ycMOperand(AM_INDIRECT,0,$2); }
236 		| number LPAREN register RPAREN		{ ycMOperand(AM_INDEXED,Number_copy(&$1),$3); }
237 		| LPAREN number RPAREN			{ ycMOperand(AM_IMMIND,Number_copy(&$2),0); }
238 		;
239 
240 number		: HASH NUMBER	{ $$.ntype = NT_VALUE; $$.v.d = $2; }
241 		| NUMBER	{ $$.ntype = NT_VALUE; $$.v.d = $1; }
242 		| HASH LITERAL	{ $$.ntype = NT_SYMBOL; $$.v.s = $2; }
243 		| LITERAL	{ $$.ntype = NT_SYMBOL; $$.v.s = $1; }
244 		;
245 
246 /***********************************************************************
247  * Generic declarations
248  ***********************************************************************/
249 brange		: LBRACK NUMBER COLON NUMBER RBRACK	{ $$.msb = $2; $$.lsb = $4; }
250 		| LBRACK NUMBER RBRACK			{ $$.msb = $$.lsb = $2; }
251 		;
252 
253 obrange		:					{ $$.msb = $$.lsb = -1; }
254 		| brange				{ $$ = $1; }
255 		;
256 
257 what		: MICROCODE	{ $$ = $1; }
258 		| MACROCODE	{ $$ = $1; }
259 		| MAP		{ $$ = $1; }
260 		;
261 
262 label		: LITERAL COLON				{ $$ = $1; }
263 		;
264 
265 register	: REGISTER				{ $$ = $1; }
266 		| PERCENT REGISTER			{ $$ = $2; }
267 		;
268