]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/ddb/db_lex.h
ddb(4): Enhance lexer functionality for specialized commands
[FreeBSD/FreeBSD.git] / sys / ddb / db_lex.h
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  * $FreeBSD$
29  */
30
31 #ifndef _DDB_DB_LEX_H_
32 #define _DDB_DB_LEX_H_
33
34 /*
35  *      Author: David B. Golub, Carnegie Mellon University
36  *      Date:   7/90
37  */
38 /*
39  * Lexical analyzer.
40  */
41
42 /*
43  * Options and flags can configure db_read_token() => db_lex() behavior.
44  *
45  * When a radix other than DRT_DEFAULT_RADIX is used, it overrides
46  * auto-detection, as well as the user-specified db_radix, in db_lex() of
47  * 'tNUMBER' tokens.
48  */
49 enum {
50         /* Infer or use db_radix using the old logic. */
51         DRT_DEFAULT_RADIX = 0,
52         /* The following set an explicit base for tNUMBER lex. */
53         DRT_OCTAL,
54         DRT_DECIMAL,
55         DRT_HEXADECIMAL,
56 };
57 #define DRT_RADIX_MASK  0x3
58 /*
59  * Flag bit powers of two for db_read_token_flags.
60  * The low 2 bits are reserved for radix selection.
61  */
62 enum {
63         _DRT_WSPACE = 2,
64 };
65 #ifndef BIT
66 #define BIT(n)  (1ull << (n))
67 #endif
68 enum {
69         DRT_WSPACE = BIT(_DRT_WSPACE),
70 };
71 #define DRT_VALID_FLAGS_MASK    ((int)DRT_RADIX_MASK | DRT_WSPACE)
72
73 void     db_flush_lex(void);
74 char    *db_get_line(void);
75 void     db_inject_line(const char *command);
76 int      db_read_line(void);
77 int      db_read_token_flags(int);
78 void     db_unread_token(int t);
79
80 static inline int
81 db_read_token(void)
82 {
83         return (db_read_token_flags(0));
84 }
85
86 extern db_expr_t        db_tok_number;
87 #define TOK_STRING_SIZE         120
88 extern char     db_tok_string[TOK_STRING_SIZE];
89
90 #define tEOF            (-1)
91 #define tEOL            1
92 #define tNUMBER         2
93 #define tIDENT          3
94 #define tPLUS           4
95 #define tMINUS          5
96 #define tDOT            6
97 #define tSTAR           7
98 #define tSLASH          8
99 #define tEQ             9
100 #define tLPAREN         10
101 #define tRPAREN         11
102 #define tPCT            12
103 #define tHASH           13
104 #define tCOMMA          14
105 #define tDITTO          15
106 #define tDOLLAR         16
107 #define tEXCL           17
108 #define tSHIFT_L        18
109 #define tSHIFT_R        19
110 #define tDOTDOT         20
111 #define tSEMI           21
112 #define tLOG_EQ         22
113 #define tLOG_NOT_EQ     23
114 #define tLESS           24
115 #define tLESS_EQ        25
116 #define tGREATER        26
117 #define tGREATER_EQ     27
118 #define tBIT_AND        28
119 #define tBIT_OR         29
120 #define tLOG_AND        30
121 #define tLOG_OR         31
122 #define tSTRING         32
123 #define tQUESTION       33
124 #define tBIT_NOT        34
125 #define tWSPACE         35
126
127 #endif /* !_DDB_DB_LEX_H_ */