File: commandy.y

package info (click to toggle)
fuse-emulator 1.0.0.1a%2Bdfsg1-4
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 9,568 kB
  • sloc: ansic: 67,895; sh: 10,265; perl: 3,386; makefile: 787; yacc: 227; lex: 139
file content (303 lines) | stat: -rw-r--r-- 8,682 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/* commandy.y: Parse a debugger command
   Copyright (c) 2002-2008 Philip Kendall

   $Id: commandy.y 3657 2008-06-08 15:04:37Z pak21 $

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.	 See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License along
   with this program; if not, write to the Free Software Foundation, Inc.,
   51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

   Author contact information:

   E-mail: philip-fuse@shadowmagic.org.uk

*/

%{

#include <config.h>

#include <stdio.h>		/* Needed by NetBSD yacc */
#include <stdlib.h>
#include <string.h>

#include "debugger.h"
#include "debugger_internals.h"
#include "mempool.h"
#include "ui/ui.h"
#include "z80/z80.h"
#include "z80/z80_macros.h"

#define YYDEBUG 1
#define YYERROR_VERBOSE

%}

%union {

  int token;
  int reg;

  libspectrum_dword integer;
  char *string;

  debugger_breakpoint_type bptype;
  debugger_breakpoint_life bplife;
  struct { int value1; libspectrum_word value2; } pair;

  debugger_expression* exp;

}

%debug

/* Tokens as returned from the Flex scanner (commandl.l) */

/* Some tokens are named DEBUGGER_* to avoid clashes with <windows.h> */

%token		 LOGICAL_OR	/* || */
%token		 LOGICAL_AND	/* && */
%token <token>	 COMPARISON	/* < > <= >= */
%token <token>   EQUALITY	/* == != */
%token <token>   NEGATE		/* ! ~ */
%token <token>	 TIMES_DIVIDE	/* * / */

%token		 BASE
%token		 BREAK
%token		 TBREAK
%token		 CLEAR
%token           COMMANDS
%token		 CONDITION
%token		 CONTINUE
%token		 DEBUGGER_DELETE
%token		 DISASSEMBLE
%token           DEBUGGER_END
%token		 EVENT
%token		 EXIT
%token		 FINISH
%token		 IF
%token		 DEBUGGER_IGNORE
%token		 NEXT
%token		 DEBUGGER_OUT
%token		 PORT
%token		 DEBUGGER_PRINT
%token		 READ
%token		 SET
%token		 STEP
%token		 TIME
%token		 WRITE

%token <integer> PAGE
%token <reg>	 DEBUGGER_REGISTER

%token <integer> NUMBER

%token <string>	 STRING
%token <string>	 VARIABLE

%token		 DEBUGGER_ERROR

/* Derived types */

%type  <bplife>  breakpointlife
%type  <bptype>  breakpointtype
%type  <integer> pageornumber
%type  <pair>    breakpointpair
%type  <bptype>  portbreakpointtype
%type  <integer> numberorpc
%type  <integer> number

%type  <exp>     optionalcondition

%type  <exp>     expressionornull
%type  <exp>     expression;

%type  <string>  debuggercommand
%type  <string>  debuggercommands

/* Operator precedences */

/* Low precedence */

%left LOGICAL_OR
%left LOGICAL_AND
%left '|'
%left '^'
%left '&'
%left EQUALITY
%left COMPARISON
%left '+' '-'
%left TIMES_DIVIDE
%right NEGATE		/* Unary minus, unary plus, !, ~ */

/* High precedence */

%%

input:	 /* empty */
       | command
       | error
       | input '\n' command
;

command:   BASE number { debugger_output_base = $2; }
	 | breakpointlife breakpointtype breakpointpair optionalcondition {
             debugger_breakpoint_add_address( $2, $3.value1, $3.value2, 0, $1,
					      $4 );
	   }
	 | breakpointlife PORT portbreakpointtype breakpointpair optionalcondition {
	     int mask; libspectrum_word port;
	     mask = $4.value1; port = $4.value2;
	     if( mask == -1 ) mask = ( port < 0x100 ? 0x00ff : 0xffff );
	     debugger_breakpoint_add_port( $3, port, mask, 0, $1, $5 );
           }
	 | breakpointlife TIME number optionalcondition {
	     debugger_breakpoint_add_time( DEBUGGER_BREAKPOINT_TYPE_TIME,
					   $3, 0, $1, $4 );
	   }
	 | breakpointlife EVENT STRING ':' STRING optionalcondition {
	     debugger_breakpoint_add_event( DEBUGGER_BREAKPOINT_TYPE_EVENT,
					    $3, $5, 0, $1, $6 );
	   }
	 | CLEAR numberorpc { debugger_breakpoint_clear( $2 ); }
	 | COMMANDS number '\n' debuggercommands DEBUGGER_END { debugger_breakpoint_set_commands( $2, $4 ); }
	 | CONDITION NUMBER expressionornull {
	     debugger_breakpoint_set_condition( $2, $3 );
           }
	 | CONTINUE { debugger_run(); }
	 | DEBUGGER_DELETE { debugger_breakpoint_remove_all(); }
	 | DEBUGGER_DELETE number { debugger_breakpoint_remove( $2 ); }
	 | DISASSEMBLE number { ui_debugger_disassemble( $2 ); }
	 | EXIT     { debugger_exit_emulator(); }
	 | FINISH   { debugger_breakpoint_exit(); }
	 | DEBUGGER_IGNORE NUMBER number {
	     debugger_breakpoint_ignore( $2, $3 );
	   }
	 | NEXT	    { debugger_next(); }
	 | DEBUGGER_OUT number NUMBER { debugger_port_write( $2, $3 ); }
	 | DEBUGGER_PRINT number { printf( "0x%x\n", $2 ); }
	 | SET NUMBER number { debugger_poke( $2, $3 ); }
	 | SET DEBUGGER_REGISTER number { debugger_register_set( $2, $3 ); }
	 | SET VARIABLE number { debugger_variable_set( $2, $3 ); }
	 | STEP	    { debugger_step(); }
;

breakpointlife:   BREAK  { $$ = DEBUGGER_BREAKPOINT_LIFE_PERMANENT; }
		| TBREAK { $$ = DEBUGGER_BREAKPOINT_LIFE_ONESHOT; }
;

breakpointtype:   /* empty */ { $$ = DEBUGGER_BREAKPOINT_TYPE_EXECUTE; }
	        | READ        { $$ = DEBUGGER_BREAKPOINT_TYPE_READ; }
                | WRITE       { $$ = DEBUGGER_BREAKPOINT_TYPE_WRITE; }
;

breakpointpair:   numberorpc { $$.value1 = -1; $$.value2 = $1; }
		| pageornumber ':' number { $$.value1 = $1; $$.value2 = $3; }
;

pageornumber:   PAGE { $$ = $1; }
	      | number { $$ = $1; }

portbreakpointtype:   READ  { $$ = DEBUGGER_BREAKPOINT_TYPE_PORT_READ; }
		    | WRITE { $$ = DEBUGGER_BREAKPOINT_TYPE_PORT_WRITE; }
;

optionalcondition:   /* empty */   { $$ = NULL; }
		   | IF expression { $$ = $2; }
;

numberorpc:   /* empty */ { $$ = PC; }
	    | number      { $$ = $1; }
;

expressionornull:   /* empty */ { $$ = NULL; }
	          | expression  { $$ = $1; }
;

number:   expression { $$ = debugger_expression_evaluate( $1 ); }
;

expression:   NUMBER { $$ = debugger_expression_new_number( $1, debugger_memory_pool );
		       if( !$$ ) YYABORT;
		     }
	    | DEBUGGER_REGISTER { $$ = debugger_expression_new_register( $1, debugger_memory_pool );
			 if( !$$ ) YYABORT;
		       }
	    | VARIABLE { $$ = debugger_expression_new_variable( $1, debugger_memory_pool );
			 if( !$$ ) YYABORT;
		       }
	    | '(' expression ')' { $$ = $2; }
	    | '+' expression %prec NEGATE { $$ = $2; }
	    | '-' expression %prec NEGATE {
	        $$ = debugger_expression_new_unaryop( '-', $2, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | NEGATE expression {
	        $$ = debugger_expression_new_unaryop( $1, $2, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression '+' expression {
	        $$ = debugger_expression_new_binaryop( '+', $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression '-' expression {
	        $$ = debugger_expression_new_binaryop( '-', $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression TIMES_DIVIDE expression {
	        $$ = debugger_expression_new_binaryop( $2, $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression EQUALITY expression {
	        $$ = debugger_expression_new_binaryop( $2, $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression COMPARISON expression {
	        $$ = debugger_expression_new_binaryop( $2, $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression '&' expression {
	        $$ = debugger_expression_new_binaryop( '&', $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression '^' expression {
	        $$ = debugger_expression_new_binaryop( '^', $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression '|' expression {
	        $$ = debugger_expression_new_binaryop( '|', $1, $3, debugger_memory_pool );
		if( !$$ ) YYABORT;
	      }
	    | expression LOGICAL_AND expression {
	        $$ = debugger_expression_new_binaryop(
		  DEBUGGER_TOKEN_LOGICAL_AND, $1, $3, debugger_memory_pool
                );
		if( !$$ ) YYABORT;
	      }
	    | expression LOGICAL_OR expression {
	        $$ = debugger_expression_new_binaryop(
		  DEBUGGER_TOKEN_LOGICAL_OR, $1, $3, debugger_memory_pool
		);
		if( !$$ ) YYABORT;
	      }
;

debuggercommands:   debuggercommand { $$ = $1; }
                  | debuggercommands debuggercommand {
                      $$ = mempool_alloc( debugger_memory_pool, strlen( $1 ) + strlen( $2 ) + 2 );
                      sprintf( $$, "%s\n%s", $1, $2 );
                    }

debuggercommand: STRING '\n'

%%