1/* 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 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. 11 * 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. 15 * 16 * Carnegie Mellon requests users of this software to return to 17 * 18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 * School of Computer Science 20 * Carnegie Mellon University 21 * Pittsburgh PA 15213-3890 22 * 23 * any improvements or extensions that they make and grant Carnegie the 24 * rights to redistribute these changes. 25 *
| 1/* 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 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. 11 * 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. 15 * 16 * Carnegie Mellon requests users of this software to return to 17 * 18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 19 * School of Computer Science 20 * Carnegie Mellon University 21 * Pittsburgh PA 15213-3890 22 * 23 * any improvements or extensions that they make and grant Carnegie the 24 * rights to redistribute these changes. 25 *
|
26 * $Id$
| 26 * $Id: db_expr.c,v 1.2 1993/10/16 16:47:14 rgrimes Exp $
|
27 */ 28 29/* 30 * Author: David B. Golub, Carnegie Mellon University 31 * Date: 7/90 32 */ 33#include "param.h"
| 27 */ 28 29/* 30 * Author: David B. Golub, Carnegie Mellon University 31 * Date: 7/90 32 */ 33#include "param.h"
|
| 34#include "systm.h"
|
34#include "proc.h"
| 35#include "proc.h"
|
35#include <machine/db_machdep.h>
| 36#include "ddb/ddb.h"
|
36#include <ddb/db_lex.h> 37#include <ddb/db_access.h> 38#include <ddb/db_command.h> 39 40boolean_t 41db_term(valuep) 42 db_expr_t *valuep; 43{ 44 int t; 45 46 t = db_read_token(); 47 if (t == tIDENT) { 48 if (!db_value_of_name(db_tok_string, valuep)) { 49 db_error("Symbol not found\n"); 50 /*NOTREACHED*/ 51 } 52 return (TRUE); 53 } 54 if (t == tNUMBER) { 55 *valuep = (db_expr_t)db_tok_number; 56 return (TRUE); 57 } 58 if (t == tDOT) { 59 *valuep = (db_expr_t)db_dot; 60 return (TRUE); 61 } 62 if (t == tDOTDOT) { 63 *valuep = (db_expr_t)db_prev; 64 return (TRUE); 65 } 66 if (t == tPLUS) { 67 *valuep = (db_expr_t) db_next; 68 return (TRUE); 69 } 70 if (t == tDITTO) { 71 *valuep = (db_expr_t)db_last_addr; 72 return (TRUE); 73 } 74 if (t == tDOLLAR) { 75 if (!db_get_variable(valuep)) 76 return (FALSE); 77 return (TRUE); 78 } 79 if (t == tLPAREN) { 80 if (!db_expression(valuep)) { 81 db_error("Syntax error\n"); 82 /*NOTREACHED*/ 83 } 84 t = db_read_token(); 85 if (t != tRPAREN) { 86 db_error("Syntax error\n"); 87 /*NOTREACHED*/ 88 } 89 return (TRUE); 90 } 91 db_unread_token(t); 92 return (FALSE); 93} 94 95boolean_t 96db_unary(valuep) 97 db_expr_t *valuep; 98{ 99 int t; 100 101 t = db_read_token(); 102 if (t == tMINUS) { 103 if (!db_unary(valuep)) { 104 db_error("Syntax error\n"); 105 /*NOTREACHED*/ 106 } 107 *valuep = -*valuep; 108 return (TRUE); 109 } 110 if (t == tSTAR) { 111 /* indirection */ 112 if (!db_unary(valuep)) { 113 db_error("Syntax error\n"); 114 /*NOTREACHED*/ 115 } 116 *valuep = db_get_value((db_addr_t)*valuep, sizeof(int), FALSE); 117 return (TRUE); 118 } 119 db_unread_token(t); 120 return (db_term(valuep)); 121} 122 123boolean_t 124db_mult_expr(valuep) 125 db_expr_t *valuep; 126{ 127 db_expr_t lhs, rhs; 128 int t; 129 130 if (!db_unary(&lhs)) 131 return (FALSE); 132 133 t = db_read_token(); 134 while (t == tSTAR || t == tSLASH || t == tPCT || t == tHASH) { 135 if (!db_term(&rhs)) { 136 db_error("Syntax error\n"); 137 /*NOTREACHED*/ 138 } 139 if (t == tSTAR) 140 lhs *= rhs; 141 else { 142 if (rhs == 0) { 143 db_error("Divide by 0\n"); 144 /*NOTREACHED*/ 145 } 146 if (t == tSLASH) 147 lhs /= rhs; 148 else if (t == tPCT) 149 lhs %= rhs; 150 else 151 lhs = ((lhs+rhs-1)/rhs)*rhs; 152 } 153 t = db_read_token(); 154 } 155 db_unread_token(t); 156 *valuep = lhs; 157 return (TRUE); 158} 159 160boolean_t 161db_add_expr(valuep) 162 db_expr_t *valuep; 163{ 164 db_expr_t lhs, rhs; 165 int t; 166 167 if (!db_mult_expr(&lhs)) 168 return (FALSE); 169 170 t = db_read_token(); 171 while (t == tPLUS || t == tMINUS) { 172 if (!db_mult_expr(&rhs)) { 173 db_error("Syntax error\n"); 174 /*NOTREACHED*/ 175 } 176 if (t == tPLUS) 177 lhs += rhs; 178 else 179 lhs -= rhs; 180 t = db_read_token(); 181 } 182 db_unread_token(t); 183 *valuep = lhs; 184 return (TRUE); 185} 186 187boolean_t 188db_shift_expr(valuep) 189 db_expr_t *valuep; 190{ 191 db_expr_t lhs, rhs; 192 int t; 193 194 if (!db_add_expr(&lhs)) 195 return (FALSE); 196 197 t = db_read_token(); 198 while (t == tSHIFT_L || t == tSHIFT_R) { 199 if (!db_add_expr(&rhs)) { 200 db_error("Syntax error\n"); 201 /*NOTREACHED*/ 202 } 203 if (rhs < 0) { 204 db_error("Negative shift amount\n"); 205 /*NOTREACHED*/ 206 } 207 if (t == tSHIFT_L) 208 lhs <<= rhs; 209 else { 210 /* Shift right is unsigned */ 211 lhs = (unsigned) lhs >> rhs; 212 } 213 t = db_read_token(); 214 } 215 db_unread_token(t); 216 *valuep = lhs; 217 return (TRUE); 218} 219 220int 221db_expression(valuep) 222 db_expr_t *valuep; 223{ 224 return (db_shift_expr(valuep)); 225}
| 37#include <ddb/db_lex.h> 38#include <ddb/db_access.h> 39#include <ddb/db_command.h> 40 41boolean_t 42db_term(valuep) 43 db_expr_t *valuep; 44{ 45 int t; 46 47 t = db_read_token(); 48 if (t == tIDENT) { 49 if (!db_value_of_name(db_tok_string, valuep)) { 50 db_error("Symbol not found\n"); 51 /*NOTREACHED*/ 52 } 53 return (TRUE); 54 } 55 if (t == tNUMBER) { 56 *valuep = (db_expr_t)db_tok_number; 57 return (TRUE); 58 } 59 if (t == tDOT) { 60 *valuep = (db_expr_t)db_dot; 61 return (TRUE); 62 } 63 if (t == tDOTDOT) { 64 *valuep = (db_expr_t)db_prev; 65 return (TRUE); 66 } 67 if (t == tPLUS) { 68 *valuep = (db_expr_t) db_next; 69 return (TRUE); 70 } 71 if (t == tDITTO) { 72 *valuep = (db_expr_t)db_last_addr; 73 return (TRUE); 74 } 75 if (t == tDOLLAR) { 76 if (!db_get_variable(valuep)) 77 return (FALSE); 78 return (TRUE); 79 } 80 if (t == tLPAREN) { 81 if (!db_expression(valuep)) { 82 db_error("Syntax error\n"); 83 /*NOTREACHED*/ 84 } 85 t = db_read_token(); 86 if (t != tRPAREN) { 87 db_error("Syntax error\n"); 88 /*NOTREACHED*/ 89 } 90 return (TRUE); 91 } 92 db_unread_token(t); 93 return (FALSE); 94} 95 96boolean_t 97db_unary(valuep) 98 db_expr_t *valuep; 99{ 100 int t; 101 102 t = db_read_token(); 103 if (t == tMINUS) { 104 if (!db_unary(valuep)) { 105 db_error("Syntax error\n"); 106 /*NOTREACHED*/ 107 } 108 *valuep = -*valuep; 109 return (TRUE); 110 } 111 if (t == tSTAR) { 112 /* indirection */ 113 if (!db_unary(valuep)) { 114 db_error("Syntax error\n"); 115 /*NOTREACHED*/ 116 } 117 *valuep = db_get_value((db_addr_t)*valuep, sizeof(int), FALSE); 118 return (TRUE); 119 } 120 db_unread_token(t); 121 return (db_term(valuep)); 122} 123 124boolean_t 125db_mult_expr(valuep) 126 db_expr_t *valuep; 127{ 128 db_expr_t lhs, rhs; 129 int t; 130 131 if (!db_unary(&lhs)) 132 return (FALSE); 133 134 t = db_read_token(); 135 while (t == tSTAR || t == tSLASH || t == tPCT || t == tHASH) { 136 if (!db_term(&rhs)) { 137 db_error("Syntax error\n"); 138 /*NOTREACHED*/ 139 } 140 if (t == tSTAR) 141 lhs *= rhs; 142 else { 143 if (rhs == 0) { 144 db_error("Divide by 0\n"); 145 /*NOTREACHED*/ 146 } 147 if (t == tSLASH) 148 lhs /= rhs; 149 else if (t == tPCT) 150 lhs %= rhs; 151 else 152 lhs = ((lhs+rhs-1)/rhs)*rhs; 153 } 154 t = db_read_token(); 155 } 156 db_unread_token(t); 157 *valuep = lhs; 158 return (TRUE); 159} 160 161boolean_t 162db_add_expr(valuep) 163 db_expr_t *valuep; 164{ 165 db_expr_t lhs, rhs; 166 int t; 167 168 if (!db_mult_expr(&lhs)) 169 return (FALSE); 170 171 t = db_read_token(); 172 while (t == tPLUS || t == tMINUS) { 173 if (!db_mult_expr(&rhs)) { 174 db_error("Syntax error\n"); 175 /*NOTREACHED*/ 176 } 177 if (t == tPLUS) 178 lhs += rhs; 179 else 180 lhs -= rhs; 181 t = db_read_token(); 182 } 183 db_unread_token(t); 184 *valuep = lhs; 185 return (TRUE); 186} 187 188boolean_t 189db_shift_expr(valuep) 190 db_expr_t *valuep; 191{ 192 db_expr_t lhs, rhs; 193 int t; 194 195 if (!db_add_expr(&lhs)) 196 return (FALSE); 197 198 t = db_read_token(); 199 while (t == tSHIFT_L || t == tSHIFT_R) { 200 if (!db_add_expr(&rhs)) { 201 db_error("Syntax error\n"); 202 /*NOTREACHED*/ 203 } 204 if (rhs < 0) { 205 db_error("Negative shift amount\n"); 206 /*NOTREACHED*/ 207 } 208 if (t == tSHIFT_L) 209 lhs <<= rhs; 210 else { 211 /* Shift right is unsigned */ 212 lhs = (unsigned) lhs >> rhs; 213 } 214 t = db_read_token(); 215 } 216 db_unread_token(t); 217 *valuep = lhs; 218 return (TRUE); 219} 220 221int 222db_expression(valuep) 223 db_expr_t *valuep; 224{ 225 return (db_shift_expr(valuep)); 226}
|