Release 940301
[wine] / debugger / debug.l
1
2
3 /* Lexical scanner for command line parsing in the Wine debugger
4  *
5  * Version 1.0
6  * Eric Youngdale
7  * 9/93
8  */
9
10 %{
11 #include <stdio.h>
12 #include <string.h>
13 #include "dbg.tab.h"
14 #include "regpos.h"
15
16 #ifdef USE_READLINE
17 #undef YY_INPUT
18 #define YY_INPUT(buf,result,max_size) \
19         if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
20             YY_FATAL_ERROR( "read() in flex scanner failed" );
21 #endif
22
23 extern char * readline(char *);
24 static char * make_symbol(char *);
25 void flush_symbols();
26 static int syntax_error;
27 extern int yylval;
28 %}
29
30 DIGIT   [0-9]
31 HEXDIGIT [0-9a-fA-F]
32
33 IDENTIFIER [_a-zA-Z\.~][_a-zA-Z0-9\.~]*
34
35 %%
36
37 \n              { syntax_error = 0; return '\n'; } /* Indicate end of command */
38
39 "+"             { return '+'; } 
40
41 "-"             { return '-'; } 
42
43 "/"             { return '/'; } 
44
45 "="             { return '='; } 
46
47 "("             { return '('; } 
48
49 ")"             { return ')'; } 
50
51 "*"             { return '*'; } 
52
53 "?"             { return HELP; }
54
55 "0x"+{HEXDIGIT}+   {
56                 sscanf(yytext, "%lx", &yylval);
57                 return NUM;
58                 }
59
60 {DIGIT}+   {
61                 sscanf(yytext, "%lx", &yylval);
62                 return NUM;
63                 }
64
65 $pc             { yylval = RN_EIP; return REG;}
66 $sp             { yylval = RN_ESP; return REG;}
67 $eip            { yylval = RN_EIP; return REG;}
68 $esp            { yylval = RN_ESP; return REG;}
69 $ebp            { yylval = RN_EBP; return REG;}
70 $eax            { yylval = RN_EAX; return REG;}
71 $ebx            { yylval = RN_EBX; return REG;}
72 $ecx            { yylval = RN_ECX; return REG;}
73 $edx            { yylval = RN_EDX; return REG;}
74 $esi            { yylval = RN_ESI; return REG;}
75 $edi            { yylval = RN_EDI; return REG;}
76
77 info|inf|in             { return INFO; }
78
79 quit|qui|qu     { return QUIT; }
80
81 help|hel|he     { return HELP; }
82
83 set|se          { return SET; }
84
85 cont|con|co             { return CONT; }
86
87 symbolfile|symbolfil|symbolfi|symbolf|symbol|symbo|symb { return SYMBOLFILE; }
88
89 define|defin|defi|def|de        { return DEFINE; }
90 print|prin|pri|pr               { return PRINT; }
91
92 regs|reg|re     { return REGS; }
93
94 stack|stac|sta|st       { return STACK; }
95
96 x               { return 'x'; }
97 d               { return 'd'; }
98 i               { return 'i'; }
99 w               { return 'w'; }
100 b               { return 'b'; }
101 s               { return 's'; }
102 c               { return 'c'; }
103
104 {IDENTIFIER}    {yylval = (int) make_symbol(yytext); 
105                   return IDENTIFIER;
106                  }
107
108 [ \t]+        /* Eat up whitespace */
109
110 .               { if(syntax_error == 0) {
111                 syntax_error ++; fprintf(stderr, "Syntax Error\n"); }
112                 }
113
114 %%
115
116 #ifndef yywrap
117 int yywrap(void) { return 1; }
118 #endif
119
120 #ifdef USE_READLINE
121 #ifndef whitespace
122 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
123 #endif
124
125 #if 0
126 /* Used only with GNU readline */
127 #include "readline/readline.h"
128 #include "readline/chardefs.h"
129 #endif
130
131 dbg_read(char * buf, int size){
132         char * line;
133         int len;
134
135         do{
136                 flush_symbols();
137                 line = readline ("Wine-dbg>");
138                 len = strlen(line);
139                                 
140                 if (!line)
141                 {
142                         return 0;
143                 }
144                 else
145                 {
146                         /* Remove leading and trailing whitespace from the line.
147                            Then, if there is anything left, add it to the history list
148                            and execute it. */
149                         stripwhite (line);
150                         
151                         if (*line)
152                         {
153                                 add_history (line);
154                                 if(size < len + 1){
155                                         fprintf(stderr,"Fatal readline goof.\n");
156                                         exit(0);
157                                 };
158                                 strcpy(buf, line);
159                                 buf[len] = '\n';
160                                 buf[len+1] = 0;
161                                 free(line);
162                                 return len + 1;
163                         }
164                 }
165
166         } while (1==1);
167 }
168
169 /* Strip whitespace from the start and end of STRING. */
170 stripwhite (string)
171      char *string;
172 {
173   register int i = 0;
174
175   while (whitespace (string[i]))
176     i++;
177
178   if (i)
179     strcpy (string, string + i);
180
181   i = strlen (string) - 1;
182
183   while (i > 0 && whitespace (string[i]))
184     i--;
185
186   string[++i] = '\0';
187 }
188
189 static char *local_symbols[10];
190 static int next_symbol;
191
192 char * make_symbol(char * symbol){
193         return local_symbols[next_symbol++] = strdup(symbol);
194 }
195
196 void
197 flush_symbols(){
198         while(--next_symbol>= 0) free(local_symbols[next_symbol]);
199         next_symbol = 0;
200 }
201
202 #endif