2 * Lexical scanner for command line parsing
4 * Copyright 1993 Eric Youngdale
15 #ifndef DONT_USE_READLINE
17 #define YY_INPUT(buf,result,max_size) \
18 if ( (result = dbg_read((char *) buf, max_size )) < 0 ) \
19 YY_FATAL_ERROR( "read() in flex scanner failed" );
21 extern char * readline(char *);
22 extern void add_history(char *);
23 static int dbg_read(char * buf, int size);
24 static char * make_symbol(char *);
27 #endif /* DONT_USE_READLINE */
31 static int syntax_error;
37 IDENTIFIER [_a-zA-Z~][_a-zA-Z0-9~@]*
38 PATHNAME [/_a-zA-Z\.~][/_a-zA-Z0-9\.~@]*
52 \n { BEGIN(0); syntax_error = 0;
53 return tEOL; } /*Indicates end of command. Reset state. */
55 "||" { return OP_LOR; }
56 "&&" { return OP_LAND; }
57 "==" { return OP_EQ; }
58 "!=" { return OP_NE; }
59 "<=" { return OP_LE; }
60 ">=" { return OP_GE; }
61 "<<" { return OP_SHL; }
62 ">>" { return OP_SHR; }
63 "->" { return OP_DRF; }
64 [-+<=>|&^()*/%:!~,\.] { return *yytext; }
65 "[" { return *yytext; }
66 "]" { return *yytext; }
68 "0x"{HEXDIGIT}+ { sscanf(yytext, "%x", &yylval.integer); return tNUM; }
69 {DIGIT}+ { sscanf(yytext, "%d", &yylval.integer); return tNUM; }
72 <FORMAT_EXPECTED>"/"{DIGIT}+{FORMAT} { char * last;
73 yylval.integer = strtol( yytext+1, &last, NULL );
74 yylval.integer = (yylval.integer << 8) | *last;
78 <FORMAT_EXPECTED>"/"{FORMAT} { yylval.integer = (1 << 8) | yytext[1]; return tFORMAT; }
80 {STRING} { yylval.string = make_symbol(yytext); return tSTRING; }
82 $pc { yylval.reg = REG_EIP; return tREG; }
83 $flags { yylval.reg = REG_EFL; return tREG; }
84 $eip { yylval.reg = REG_EIP; return tREG; }
85 $ip { yylval.reg = REG_IP; return tREG; }
86 $esp { yylval.reg = REG_ESP; return tREG; }
87 $sp { yylval.reg = REG_SP; return tREG; }
88 $eax { yylval.reg = REG_EAX; return tREG; }
89 $ebx { yylval.reg = REG_EBX; return tREG; }
90 $ecx { yylval.reg = REG_ECX; return tREG; }
91 $edx { yylval.reg = REG_EDX; return tREG; }
92 $esi { yylval.reg = REG_ESI; return tREG; }
93 $edi { yylval.reg = REG_EDI; return tREG; }
94 $ebp { yylval.reg = REG_EBP; return tREG; }
95 $ax { yylval.reg = REG_AX; return tREG; }
96 $bx { yylval.reg = REG_BX; return tREG; }
97 $cx { yylval.reg = REG_CX; return tREG; }
98 $dx { yylval.reg = REG_DX; return tREG; }
99 $si { yylval.reg = REG_SI; return tREG; }
100 $di { yylval.reg = REG_DI; return tREG; }
101 $bp { yylval.reg = REG_BP; return tREG; }
102 $es { yylval.reg = REG_ES; return tREG; }
103 $ds { yylval.reg = REG_DS; return tREG; }
104 $cs { yylval.reg = REG_CS; return tREG; }
105 $ss { yylval.reg = REG_SS; return tREG; }
106 $fs { yylval.reg = REG_FS; return tREG; }
107 $gs { yylval.reg = REG_GS; return tREG; }
109 <INITIAL>info|inf|in { BEGIN(INFO_CMD); return tINFO; }
110 <INITIAL>up { BEGIN(NOCMD); return tUP; }
111 <INITIAL>down|dow|do { BEGIN(NOCMD); return tDOWN; }
112 <INITIAL>frame|fram|fra|fr { BEGIN(NOCMD); return tFRAME; }
113 <INITIAL>list|lis|li|l { BEGIN(PATH_EXPECTED); return tLIST; }
114 <INITIAL>enable|enabl|enab|ena { BEGIN(NOCMD); return tENABLE;}
115 <INITIAL>disable|disabl|disab|disa|dis { BEGIN(NOCMD); return tDISABLE; }
116 <INITIAL>disassemble|disassembl|disassemb|disassem|disasse|disass|disas { BEGIN(NOCMD); return tDISASSEMBLE; }
117 <INITIAL,INFO_CMD,DEL_CMD>display|displa|displ|disp { BEGIN(FORMAT_EXPECTED); return tDISPLAY; }
118 <INITIAL>undisplay|undispla|undispl|undisp|undis|undi|und { BEGIN(NOCMD); return tUNDISPLAY; }
119 <INITIAL>delete|delet|dele|del { BEGIN(DEL_CMD); return tDELETE; }
120 <INITIAL>quit|qui|qu|q { BEGIN(NOCMD); return tQUIT; }
121 <INITIAL>set|se { BEGIN(NOCMD); return tSET; }
122 <INITIAL>walk|w { BEGIN(WALK_CMD); return tWALK; }
123 <INITIAL>x { BEGIN(FORMAT_EXPECTED); return tEXAM; }
124 <INITIAL>help|hel|he|"?" { BEGIN(HELP_CMD); return tHELP; }
126 <INITIAL>backtrace|backtrac|backtra|backt|back|bac|ba|bt { BEGIN(NOCMD); return tBACKTRACE; }
127 <INITIAL>where|wher|whe { BEGIN(NOCMD); return tBACKTRACE; }
129 <INITIAL>cont|con|co|c { BEGIN(NOCMD); return tCONT; }
130 <INITIAL>condition|conditio|conditi|condit|condi|cond { BEGIN(NOCMD); return tCOND; }
131 <INITIAL>step|ste|st|s { BEGIN(NOCMD); return tSTEP; }
132 <INITIAL>next|nex|ne|n { BEGIN(NOCMD); return tNEXT; }
133 <INITIAL>stepi|si { BEGIN(NOCMD); return tSTEPI; }
134 <INITIAL>nexti|ni { BEGIN(NOCMD); return tNEXTI; }
135 <INITIAL>finish|finis|fini|fin|fi { BEGIN(NOCMD); return tFINISH; }
137 <INITIAL>abort|abor|abo { BEGIN(NOCMD); return tABORT; }
138 <INITIAL>print|prin|pri|pr|p { BEGIN(FORMAT_EXPECTED); return tPRINT; }
140 <INITIAL>mode { BEGIN(NOCMD); return tMODE; }
141 <INITIAL>show|sho|sh { BEGIN(SHOW_CMD); return tSHOW; }
143 <INITIAL,INFO_CMD,DEL_CMD>break|brea|bre|br|b { BEGIN(PATH_EXPECTED); return tBREAK; }
145 <INFO_CMD>share|shar|sha { return tSHARE; }
146 <INFO_CMD>locals|local|loca|loc { return tLOCAL; }
147 <INFO_CMD,WALK_CMD>class|clas|cla { return tCLASS; }
148 <INFO_CMD,WALK_CMD>module|modul|modu|mod { return tMODULE; }
149 <INFO_CMD,WALK_CMD>queue|queu|que { return tQUEUE; }
150 <INFO_CMD>registers|regs|reg|re { return tREGS; }
151 <INFO_CMD>segments|segment|segm|seg|se { return tSEGMENTS; }
152 <INFO_CMD>stack|stac|sta|st { return tSTACK; }
153 <INFO_CMD>maps|map { return tMAPS; }
154 <INFO_CMD,WALK_CMD>window|windo|wind|win|wnd { return tWND; }
155 <HELP_CMD>info|inf|in { return tINFO; }
157 <INITIAL,SHOW_CMD>directories|directorie|directori|director|directo|direct|direc|direc|dir {
158 BEGIN(PATH_EXPECTED); return tDIR; }
160 char { return tCHAR; }
161 short { return tSHORT; }
163 long { return tLONG; }
164 float { return tFLOAT; }
165 double { return tDOUBLE; }
166 unsigned { return tUNSIGNED; }
167 signed { return tSIGNED; }
168 struct { return tSTRUCT; }
169 union { return tUNION; }
170 enum { return tENUM; }
172 {IDENTIFIER} { yylval.string = make_symbol(yytext); return tIDENTIFIER; }
174 <PATH_EXPECTED>{PATHNAME} { yylval.string = make_symbol(yytext); return tPATH; }
176 [ \t]+ /* Eat up whitespace */
178 . { if (syntax_error == 0)
180 syntax_error ++; fprintf(stderr, "Syntax Error\n");
188 int yywrap(void) { return 1; }
191 #ifndef DONT_USE_READLINE
194 #define whitespace(c) (((c) == ' ') || ((c) == '\t'))
198 /* Strip whitespace from the start and end of STRING. */
199 static void stripwhite (char *string)
203 while (whitespace (string[i]))
207 strcpy (string, string + i);
209 i = strlen (string) - 1;
211 while (i > 0 && whitespace (string[i]))
217 static int dbg_read(char * buf, int size)
219 static char last_line[256] = "";
226 line = readline ("Wine-dbg>");
229 fprintf( stderr, "\n" );
233 /* Remove leading and trailing whitespace from the line */
237 /* If there is anything left, add it to the history list
238 and execute it. Otherwise, re-execute last command. */
243 strncpy( last_line, line, 255 );
244 last_line[255] = '\0';
250 if ((len = strlen(line)) > 0)
254 fprintf(stderr,"Fatal readline goof.\n");
265 static char *local_symbols[30];
266 static int next_symbol;
268 char * make_symbol(char * symbol){
269 return local_symbols[next_symbol++] = xstrdup(symbol);
274 while(--next_symbol>= 0) free(local_symbols[next_symbol]);
278 #endif /* DONT_USE_READLINE */