2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
26 * $FreeBSD: src/sys/ddb/db_expr.c,v 1.13 1999/08/28 00:41:07 peter Exp $
30 * Author: David B. Golub, Carnegie Mellon University
33 #include <sys/param.h>
36 #include <ddb/db_lex.h>
37 #include <ddb/db_access.h>
38 #include <ddb/db_command.h>
40 static boolean_t
db_add_expr (db_expr_t
*valuep
);
41 static boolean_t
db_mult_expr (db_expr_t
*valuep
);
42 static boolean_t
db_shift_expr (db_expr_t
*valuep
);
43 static boolean_t
db_term (db_expr_t
*valuep
);
44 static boolean_t
db_unary (db_expr_t
*valuep
);
47 db_term(db_expr_t
*valuep
)
53 if (!db_value_of_name(db_tok_string
, valuep
)) {
54 db_error("Symbol not found\n");
60 *valuep
= (db_expr_t
)db_tok_number
;
64 *valuep
= (db_expr_t
)db_dot
;
68 *valuep
= (db_expr_t
)db_prev
;
72 *valuep
= (db_expr_t
) db_next
;
76 *valuep
= (db_expr_t
)db_last_addr
;
80 if (!db_get_variable(valuep
))
85 if (!db_expression(valuep
)) {
86 db_error("Syntax error\n");
91 db_error("Syntax error\n");
101 db_unary(db_expr_t
*valuep
)
107 if (!db_unary(valuep
)) {
108 db_error("Syntax error\n");
116 if (!db_unary(valuep
)) {
117 db_error("Syntax error\n");
120 *valuep
= db_get_value((db_addr_t
)*valuep
, sizeof(int), FALSE
);
124 return (db_term(valuep
));
128 db_mult_expr(db_expr_t
*valuep
)
133 *valuep
= 0; /* silence gcc */
139 while (t
== tSTAR
|| t
== tSLASH
|| t
== tPCT
|| t
== tHASH
) {
140 if (!db_term(&rhs
)) {
141 db_error("Syntax error\n");
148 db_error("Divide by 0\n");
156 lhs
= roundup(lhs
, rhs
);
166 db_add_expr(db_expr_t
*valuep
)
171 *valuep
= 0; /* silence gcc */
173 if (!db_mult_expr(&lhs
))
177 while (t
== tPLUS
|| t
== tMINUS
) {
178 if (!db_mult_expr(&rhs
)) {
179 db_error("Syntax error\n");
194 db_shift_expr(db_expr_t
*valuep
)
199 if (!db_add_expr(&lhs
))
203 while (t
== tSHIFT_L
|| t
== tSHIFT_R
) {
204 if (!db_add_expr(&rhs
)) {
205 db_error("Syntax error\n");
209 db_error("Negative shift amount\n");
215 /* Shift right is unsigned */
216 lhs
= (unsigned) lhs
>> rhs
;
226 db_expression(db_expr_t
*valuep
)
228 return (db_shift_expr(valuep
));