1 /* Scheme/Guile language support routines for GDB, the GNU debugger.
2 Copyright 1995 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "expression.h"
24 #include "parser-defs.h"
31 #define USE_EXPRSTRING 0
33 static void scm_lreadparen
PARAMS ((int));
34 static int scm_skip_ws
PARAMS ((void));
35 static void scm_read_token
PARAMS ((int, int));
36 static LONGEST scm_istring2number
PARAMS ((char *, int, int));
37 static LONGEST scm_istr2int
PARAMS ((char *, int, int));
38 static void scm_lreadr
PARAMS ((int));
41 scm_istr2int(str
, len
, radix
)
51 if (0 >= len
) return SCM_BOOL_F
; /* zero scm_length */
58 return SCM_BOOL_F
; /* bad if lone `+' or `-' */
61 switch (c
= str
[i
++]) {
62 case '0': case '1': case '2': case '3': case '4':
63 case '5': case '6': case '7': case '8': case '9':
66 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
69 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
72 if (c
>= radix
) return SCM_BOOL_F
; /* bad digit for radix */
77 return SCM_BOOL_F
; /* not a digit */
82 return SCM_MAKINUM (inum
);
86 scm_istring2number(str
, len
, radix
)
93 char ex_p
= 0, rx_p
= 0; /* Only allow 1 exactness and 1 radix prefix */
98 if (*str
=='+' || *str
=='-') /* Catches lone `+' and `-' for speed */
101 while ((len
-i
) >= 2 && str
[i
]=='#' && ++i
)
103 case 'b': case 'B': if (rx_p
++) return SCM_BOOL_F
; radix
= 2; break;
104 case 'o': case 'O': if (rx_p
++) return SCM_BOOL_F
; radix
= 8; break;
105 case 'd': case 'D': if (rx_p
++) return SCM_BOOL_F
; radix
= 10; break;
106 case 'x': case 'X': if (rx_p
++) return SCM_BOOL_F
; radix
= 16; break;
107 case 'i': case 'I': if (ex_p
++) return SCM_BOOL_F
; ex
= 2; break;
108 case 'e': case 'E': if (ex_p
++) return SCM_BOOL_F
; ex
= 1; break;
109 default: return SCM_BOOL_F
;
114 return scm_istr2int(&str
[i
], len
-i
, radix
);
116 return scm_istr2int(&str
[i
], len
-i
, radix
);
118 if NFALSEP(res
) return res
;
120 case 2: return scm_istr2flo(&str
[i
], len
-i
, radix
);
128 scm_read_token (c
, weird
)
143 case ' ': case '\t': case '\r': case '\f':
147 case '\0': /* End of line */
188 switch ((c
= *lexptr
++))
195 switch ((c
= *lexptr
++))
204 case ' ': case '\t': case '\r': case '\f': case '\n':
212 scm_lreadparen (skipping
)
217 int c
= scm_skip_ws ();
218 if (')' == c
|| ']' == c
)
222 error ("missing close paren");
223 scm_lreadr (skipping
);
228 scm_lreadr (skipping
)
243 scm_lreadparen (skipping
);
247 error ("unexpected #\\%c", c
);
251 str
.ptr
= lexptr
- 1;
252 scm_lreadr (skipping
);
255 value_ptr val
= scm_evaluate_string (str
.ptr
, lexptr
- str
.ptr
);
256 if (!is_scmvalue_type (VALUE_TYPE (val
)))
257 error ("quoted scm form yields non-SCM value");
258 svalue
= extract_signed_integer (VALUE_CONTENTS (val
),
259 TYPE_LENGTH (VALUE_TYPE (val
)));
260 goto handle_immediate
;
267 scm_lreadr (skipping
);
275 scm_lreadparen (skipping
);
279 goto handle_immediate
;
282 goto handle_immediate
;
292 case '*': /* bitvector */
293 scm_read_token (c
, 0);
296 scm_read_token (c
, 1);
298 case '\\': /* character */
300 scm_read_token (c
, 0);
303 j
= 1; /* here j is the comment nesting depth */
310 error ("unbalanced comment");
314 if ('#' != (c
= *lexptr
++))
320 if ('|' != (c
= *lexptr
++))
331 scm_lreadr (skipping
);
335 while ('\"' != (c
= *lexptr
++))
338 switch (c
= *lexptr
++)
341 error ("non-terminated string literal");
355 case '0': case '1': case '2': case '3': case '4':
356 case '5': case '6': case '7': case '8': case '9':
363 scm_read_token (c
, 0);
366 svalue
= scm_istring2number (str
.ptr
, lexptr
- str
.ptr
, 10);
367 if (svalue
!= SCM_BOOL_F
)
368 goto handle_immediate
;
374 scm_read_token ('-', 0);
381 scm_read_token (c
, 0);
385 str
.length
= lexptr
- str
.ptr
;
386 if (str
.ptr
[0] == '$')
388 write_dollar_variable (str
);
391 write_exp_elt_opcode (OP_NAME
);
392 write_exp_string (str
);
393 write_exp_elt_opcode (OP_NAME
);
400 write_exp_elt_opcode (OP_LONG
);
401 write_exp_elt_type (builtin_type_scm
);
402 write_exp_elt_longcst (svalue
);
403 write_exp_elt_opcode (OP_LONG
);
411 while (*lexptr
== ' ')
414 scm_lreadr (USE_EXPRSTRING
);
416 str
.length
= lexptr
- start
;
418 write_exp_elt_opcode (OP_EXPRSTRING
);
419 write_exp_string (str
);
420 write_exp_elt_opcode (OP_EXPRSTRING
);