1 /* $OpenBSD: db_lex.c,v 1.9 2006/03/13 06:23:20 jsg Exp $ */
2 /* $NetBSD: db_lex.c,v 1.8 1996/02/05 01:57:05 christos Exp $ */
5 * Mach Operating System
6 * Copyright (c) 1993,1992,1991,1990 Carnegie Mellon University
9 * Permission to use, copy, modify and distribute this software and its
10 * documentation is hereby granted, provided that both the copyright
11 * notice and this permission notice appear in all copies of the
12 * software, derivative works or modified versions, and any portions
13 * thereof, and that both notices appear in supporting documentation.
15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
17 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
19 * Carnegie Mellon requests users of this software to return to
21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
22 * School of Computer Science
23 * Carnegie Mellon University
24 * Pittsburgh PA 15213-3890
26 * any improvements or extensions that they make and grant Carnegie Mellon
27 * the rights to redistribute these changes.
29 * Author: David B. Golub, Carnegie Mellon University
36 #include <sys/param.h>
39 #include <uvm/uvm_extern.h>
41 #include <machine/db_machdep.h>
43 #include <ddb/db_lex.h>
44 #include <ddb/db_output.h>
45 #include <ddb/db_command.h>
46 #include <ddb/db_sym.h>
47 #include <ddb/db_extern.h>
48 #include <ddb/db_var.h>
51 char * db_lp
, *db_endlp
;
53 db_expr_t db_tok_number
;
54 char db_tok_string
[TOK_STRING_SIZE
];
61 i
= db_readline(db_line
, sizeof(db_line
));
83 if (db_look_char
!= 0) {
87 else if (db_lp
>= db_endlp
)
100 int db_look_token
= 0;
103 db_unread_token(int t
)
136 while (c
<= ' ' || c
> '~') {
137 if (c
== '\n' || c
== -1)
142 if (c
>= '0' && c
<= '9') {
150 if (c
== 'O' || c
== 'o')
152 else if (c
== 'T' || c
== 't')
154 else if (c
== 'X' || c
== 'x')
164 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
166 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
167 (c
>= 'a' && c
<= 'f'))) {
169 digit
= c
- 'a' + 10;
171 digit
= c
- 'A' + 10;
175 db_tok_number
= db_tok_number
* r
+ digit
;
178 if ((c
>= '0' && c
<= '9') ||
179 (c
>= 'A' && c
<= 'Z') ||
180 (c
>= 'a' && c
<= 'z') ||
183 db_error("Bad character in number\n");
189 if ((c
>= 'A' && c
<= 'Z') ||
190 (c
>= 'a' && c
<= 'z') ||
191 c
== '_' || c
== '\\')
199 if (c
== '\n' || c
== -1) {
200 db_error("Bad escape\n");
207 if ((c
>= 'A' && c
<= 'Z') ||
208 (c
>= 'a' && c
<= 'z') ||
209 (c
>= '0' && c
<= '9') ||
210 c
== '_' || c
== '\\' || c
== ':')
214 if (c
== '\n' || c
== -1) {
215 db_error("Bad escape\n");
220 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
221 db_error("String too long\n");
283 db_printf("Bad character\n");