/[pearpc]/src/debug/lex.l
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /src/debug/lex.l

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Wed Sep 5 17:11:21 2007 UTC (16 years, 7 months ago) by dpavlin
File size: 7498 byte(s)
import upstream CVS
1 dpavlin 1 %{
2     #define USE_PURE_PARSER
3    
4     #ifdef USE_PURE_PARSER
5     #define YY_DECL int yylex (YYSTYPE *lvalp)
6     #define YY_LVALP lvalp
7     #else
8     #define YY_LVALP (&yylval)
9     #endif
10    
11     /* get current pos (offset from start of line) */
12     #define YY_USER_ACTION lex_pos=yy_bp - YY_CURRENT_BUFFER->yy_ch_buf;
13    
14     #include <stdio.h>
15     #include <string.h>
16     #include <stdlib.h>
17     #include <ctype.h>
18    
19     #include "debug/debugtype.h"
20     #include "debugparse.h"
21     #include "parsehelper.h"
22    
23     static int lex_pos;
24    
25     static int char2int(char a, int base)
26     {
27     int i;
28     if ((a>='A') && (a<='Z')) {
29     i=a-'A'+10;
30     } else if ((a>='a') && (a<='z')) {
31     i=a-'a'+10;
32     } else if ((a>='0') && (a<='9')) {
33     i=a-'0';
34     } else return -1;
35     if (i>=base) return -1;
36     return i;
37     }
38    
39     static int parse_integer(struct eval_scalar *i, char *num, int base, int lenmod)
40     {
41     uint64 k = 0;
42     int l = strlen(num)+lenmod;
43     while (l--) {
44     int c = char2int(*num, base);
45     if (c==-1) return 0;
46     k *= base;
47     k += c;
48     num++;
49     }
50     i->type = SCALAR_INT;
51     i->scalar.integer.value = k;
52     i->scalar.integer.type = TYPE_UNKNOWN;
53     return 1;
54     }
55    
56     static int parse_gpr(struct eval_scalar *i, char *s)
57     {
58     int r = 0;
59     if (tolower(*s) != 'r') return 0;
60     s++;
61     do {
62     int c = char2int(*s, 10);
63     if (c == -1) return 0;
64     r *= 10;
65     r += c;
66     s++;
67     } while (*s);
68     if (r>31) return 0;
69     i->type = SCALAR_REG;
70     i->scalar.reg.type = REG_GPR;
71     i->scalar.reg.num = r;
72     return 1;
73     }
74    
75     static int parse_fpr(struct eval_scalar *i, char *s)
76     {
77     int r = 0;
78     if (tolower(*s) != 'f') return 0;
79     s++;
80     if (tolower(*s) != 'r') return 0;
81     s++;
82     do {
83     int c = char2int(*s, 10);
84     if (c == -1) return 0;
85     r *= 10;
86     r += c;
87     s++;
88     } while (*s);
89     if (r>31) return 0;
90     i->type = SCALAR_REG;
91     i->scalar.reg.type = REG_FPR;
92     i->scalar.reg.num = r;
93     return 1;
94     }
95    
96     static int parse_float(struct eval_scalar *f, char *fpn)
97     {
98     char *end;
99     double d;
100     d=strtod(fpn, &end);
101     if (*end==0) {
102     f->type=SCALAR_FLOAT;
103     f->scalar.floatnum.value=d;
104     return 1;
105     }
106     return 0;
107     }
108    
109     static int parse_cstring(struct eval_scalar *r, char *s, int len)
110     {
111     char *result;
112    
113     int alloclen=len;
114     if (!len) alloclen=1;
115    
116     r->type=SCALAR_STR;
117     r->scalar.str.value=(char*)malloc(alloclen);
118     /* translate */
119     result=r->scalar.str.value;
120    
121     while (s && *s && len) {
122     if (*s == '\\') {
123     s++;len--;if (!len) break;
124     switch (*s) {
125     case '0':
126     *result++='\0';
127     break;
128     case 'a':
129     *result++='\a';
130     break;
131     case 'b':
132     *result++='\b';
133     break;
134     case 'e':
135     *result++='\e';
136     break;
137     case 'f':
138     *result++='\f';
139     break;
140     case 'n':
141     *result++='\n';
142     break;
143     case 'r':
144     *result++='\r';
145     break;
146     case 't':
147     *result++='\t';
148     break;
149     case 'v':
150     *result++='\v';
151     break;
152     case '\"':
153     *result++='"';
154     break;
155     case '\\':
156     *result++='\\';
157     break;
158     case 'x': {
159     int p, q;
160     s++;len--;if (!len) break;
161     p=char2int(*s, 16);
162     if (p==-1) return 0;
163     s++;len--;if (!len) break;
164     q=char2int(*s, 16);
165     if (q==-1) return 0;
166     *result++=(char)p*16+q;
167     break;
168     }
169     default:
170     *result++='\\';
171     if (len) *result++=*s;
172     break;
173     }
174     } else {
175     *result++ = *s;
176     }
177     s++;len--;
178     }
179    
180     r->scalar.str.len=result-r->scalar.str.value;
181    
182     return 1;
183     }
184    
185     static int parse_pstring(struct eval_scalar *s, char *cstr, int len)
186     {
187     int alloclen = len;
188     if (!len) alloclen = 1;
189    
190     s->type = SCALAR_STR;
191     s->scalar.str.value = (char*)malloc(alloclen);
192     memmove(s->scalar.str.value, cstr, len);
193     s->scalar.str.len = len;
194     return 1;
195     }
196    
197     void *lex_current_buffer()
198     {
199     return (void*)YY_CURRENT_BUFFER;
200     }
201    
202     int lex_current_buffer_pos()
203     {
204     return lex_pos;
205     }
206    
207     void lex_switch_buffer(void *buffer)
208     {
209     yy_switch_to_buffer(buffer);
210     }
211    
212     void lex_delete_buffer(void *buffer)
213     {
214     yy_delete_buffer(buffer);
215     }
216    
217     void *lex_scan_string_buffer(const char *str)
218     {
219     return yy_scan_string(str);
220     }
221    
222     %}
223    
224     %option noyywrap
225    
226     %%
227     [ \t]+ /* nop */
228     \"(\\\"|[^"])*\" if (parse_cstring(&YY_LVALP->scalar, yytext+1, strlen(yytext+1)-1)) return EVAL_STR;
229     '[^']*' if (parse_pstring(&YY_LVALP->scalar, yytext+1, strlen(yytext+1)-1)) return EVAL_STR;
230     \*\* return EVAL_POW;
231     \<\< return EVAL_SHL;
232     \>\> return EVAL_SHR;
233     \< return EVAL_LT;
234     \<\= return EVAL_LE;
235     \> return EVAL_GT;
236     \>\= return EVAL_GE;
237     \=\= return EVAL_EQ;
238     \!\= return EVAL_NE;
239     \&\& return EVAL_LAND;
240     \|\| return EVAL_LOR;
241     \^\^ return EVAL_LXOR;
242     print |
243     p |
244     eval return EVAL_PRINT;
245     regs return EVAL_REGS;
246     f |
247     fprs |
248     floats return EVAL_FLOATS;
249     setreg return EVAL_SETREG;
250     break |
251     b return EVAL_BREAK;
252     list_break |
253     lb return EVAL_LIST_BREAK;
254     step return EVAL_STEP;
255     s return EVAL_STEP;
256     next return EVAL_NEXT;
257     n return EVAL_NEXT;
258     continue |
259     cont |
260     c return EVAL_CONTINUE;
261     quit |
262     bye return EVAL_QUIT;
263     virt_to_phys |
264     ea_to_pa |
265     e2p |
266     v2p return EVAL_E2P;
267     inspect_byte |
268     ib return EVAL_INSPECT_BYTE;
269     inspect_half |
270     ih return EVAL_INSPECT_HALF;
271     inspect_word |
272     iw return EVAL_INSPECT_WORD;
273     inspect_dword |
274     id return EVAL_INSPECT_DWORD;
275     inspect_string |
276     is return EVAL_INSPECT_STRING;
277     inspect_memory |
278     im return EVAL_INSPECT_MEM;
279     watch |
280     w return EVAL_WATCH;
281     watch_byte |
282     wb return EVAL_WATCH_BYTE;
283     watch_half |
284     wh return EVAL_WATCH_HALF;
285     watch_word |
286     ww return EVAL_WATCH_WORD;
287     watch_dword |
288     wd return EVAL_WATCH_DWORD;
289     delete_watch |
290     dw return EVAL_DELETE_WATCH;
291     dump |
292     d return EVAL_DUMP;
293     disasm |
294     unasm |
295     u return EVAL_DISASM;
296     help |
297     h return EVAL_HELP;
298     [#][^\n]* /* comment */
299     [pP][cC] { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_PC; return EVAL_REG_PC; }
300     [cC][rR] { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_CR; return EVAL_REG_CR; }
301     [lL][rR] { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_LR; return EVAL_REG_LR; }
302     [xX][eE][rR] { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_XER; return EVAL_REG_XER; }
303     [cC][tT][rR] { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_CTR; return EVAL_REG_CTR; }
304     [mM][sS][rR] { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_MSR; return EVAL_REG_MSR; }
305     [sS][rR][rR]0 { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_SRR0; return EVAL_REG_SRR0; }
306     [sS][rR][rR]1 { YY_LVALP->scalar.type=SCALAR_REG; YY_LVALP->scalar.scalar.reg.type=REG_SRR1; return EVAL_REG_SRR1; }
307     [rR][0-3]?[0-9] if (parse_gpr(&YY_LVALP->scalar, yytext)) return EVAL_GPR;
308     [fF][rR][0-3]?[0-9] if (parse_fpr(&YY_LVALP->scalar, yytext)) return EVAL_FPR;
309     [$@a-zA-Z_][a-zA-Z0-9_]* YY_LVALP->ident=strdup(yytext); return EVAL_IDENT;
310     [0-9]+\.[0-9]+([eE][+-]?[0-9]+)? if (parse_float(&YY_LVALP->scalar, yytext)) return EVAL_FLOAT;
311     [0-9]+ if (parse_integer(&YY_LVALP->scalar, yytext, 10, 0)) return EVAL_INT;
312     0x[0-9a-fA-F]+ if (parse_integer(&YY_LVALP->scalar, yytext+2, 16, 0)) return EVAL_INT;
313     [0-9][0-9a-fA-F]*h if (parse_integer(&YY_LVALP->scalar, yytext, 16, -1)) return EVAL_INT;
314     [0-9]+d if (parse_integer(&YY_LVALP->scalar, yytext, 10, -1)) return EVAL_INT;
315     [0-7]+o if (parse_integer(&YY_LVALP->scalar, yytext, 8, -1)) return EVAL_INT;
316     [0-1]+b if (parse_integer(&YY_LVALP->scalar, yytext, 2, -1)) return EVAL_INT;
317     \n return '\n';
318     . return *yytext;
319    
320     %%
321    

  ViewVC Help
Powered by ViewVC 1.1.26