1 /*- 2 * SPDX-License-Identifier: MIT-CMU 3 * 4 * Mach Operating System 5 * Copyright (c) 1991,1990 Carnegie Mellon University 6 * All Rights Reserved. 7 * 8 * Permission to use, copy, modify and distribute this software and its 9 * documentation is hereby granted, provided that both the copyright 10 * notice and this permission notice appear in all copies of the 11 * software, derivative works or modified versions, and any portions 12 * thereof, and that both notices appear in supporting documentation. 13 * 14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS 15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 17 * 18 * Carnegie Mellon requests users of this software to return to 19 * 20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 21 * School of Computer Science 22 * Carnegie Mellon University 23 * Pittsburgh PA 15213-3890 24 * 25 * any improvements or extensions that they make and grant Carnegie the 26 * rights to redistribute these changes. 27 */ 28 29 #ifndef _DDB_DB_LEX_H_ 30 #define _DDB_DB_LEX_H_ 31 32 /* 33 * Author: David B. Golub, Carnegie Mellon University 34 * Date: 7/90 35 */ 36 /* 37 * Lexical analyzer. 38 */ 39 40 /* 41 * Options and flags can configure db_read_token() => db_lex() behavior. 42 * 43 * When a radix other than DRT_DEFAULT_RADIX is used, it overrides 44 * auto-detection, as well as the user-specified db_radix, in db_lex() of 45 * 'tNUMBER' tokens. 46 */ 47 enum { 48 /* Infer or use db_radix using the old logic. */ 49 DRT_DEFAULT_RADIX = 0, 50 /* The following set an explicit base for tNUMBER lex. */ 51 DRT_OCTAL, 52 DRT_DECIMAL, 53 DRT_HEXADECIMAL, 54 }; 55 #define DRT_RADIX_MASK 0x3 56 /* 57 * Flag bit powers of two for db_read_token_flags. 58 * The low 2 bits are reserved for radix selection. 59 * 60 * WSPACE: Yield explicit tWSPACE tokens when one or more whitespace characters 61 * is consumed. 62 * HEX: Allow tNUMBER tokens to start with 'A'-'F' without explicit "0x" 63 * prefix. 64 */ 65 enum { 66 _DRT_WSPACE = 2, 67 _DRT_HEX, 68 }; 69 #ifndef BIT 70 #define BIT(n) (1ull << (n)) 71 #endif 72 enum { 73 DRT_WSPACE = BIT(_DRT_WSPACE), 74 DRT_HEX = BIT(_DRT_HEX), 75 }; 76 #define DRT_VALID_FLAGS_MASK ((int)DRT_RADIX_MASK | \ 77 DRT_WSPACE | \ 78 DRT_HEX) 79 80 void db_flush_lex(void); 81 char *db_get_line(void); 82 void db_inject_line(const char *command); 83 int db_read_line(void); 84 int db_read_token_flags(int); 85 void db_unread_token(int t); 86 87 static inline int 88 db_read_token(void) 89 { 90 return (db_read_token_flags(0)); 91 } 92 93 extern db_expr_t db_tok_number; 94 #define TOK_STRING_SIZE 120 95 extern char db_tok_string[TOK_STRING_SIZE]; 96 97 #define tEOF (-1) 98 #define tEOL 1 99 #define tNUMBER 2 100 #define tIDENT 3 101 #define tPLUS 4 102 #define tMINUS 5 103 #define tDOT 6 104 #define tSTAR 7 105 #define tSLASH 8 106 #define tEQ 9 107 #define tLPAREN 10 108 #define tRPAREN 11 109 #define tPCT 12 110 #define tHASH 13 111 #define tCOMMA 14 112 #define tDITTO 15 113 #define tDOLLAR 16 114 #define tEXCL 17 115 #define tSHIFT_L 18 116 #define tSHIFT_R 19 117 #define tDOTDOT 20 118 #define tSEMI 21 119 #define tLOG_EQ 22 120 #define tLOG_NOT_EQ 23 121 #define tLESS 24 122 #define tLESS_EQ 25 123 #define tGREATER 26 124 #define tGREATER_EQ 27 125 #define tBIT_AND 28 126 #define tBIT_OR 29 127 #define tLOG_AND 30 128 #define tLOG_OR 31 129 #define tSTRING 32 130 #define tQUESTION 33 131 #define tBIT_NOT 34 132 #define tWSPACE 35 133 #define tCOLON 36 134 #define tCOLONCOLON 37 135 136 #endif /* !_DDB_DB_LEX_H_ */ 137