xref: /freebsd/sys/ddb/db_lex.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1dd3cb568SWarner Losh /*-
2796df753SPedro F. Giffuni  * SPDX-License-Identifier: MIT-CMU
3796df753SPedro F. Giffuni  *
45b81b6b3SRodney W. Grimes  * Mach Operating System
55b81b6b3SRodney W. Grimes  * Copyright (c) 1991,1990 Carnegie Mellon University
65b81b6b3SRodney W. Grimes  * All Rights Reserved.
75b81b6b3SRodney W. Grimes  *
85b81b6b3SRodney W. Grimes  * Permission to use, copy, modify and distribute this software and its
95b81b6b3SRodney W. Grimes  * documentation is hereby granted, provided that both the copyright
105b81b6b3SRodney W. Grimes  * notice and this permission notice appear in all copies of the
115b81b6b3SRodney W. Grimes  * software, derivative works or modified versions, and any portions
125b81b6b3SRodney W. Grimes  * thereof, and that both notices appear in supporting documentation.
135b81b6b3SRodney W. Grimes  *
145b81b6b3SRodney W. Grimes  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
155b81b6b3SRodney W. Grimes  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
165b81b6b3SRodney W. Grimes  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
175b81b6b3SRodney W. Grimes  *
185b81b6b3SRodney W. Grimes  * Carnegie Mellon requests users of this software to return to
195b81b6b3SRodney W. Grimes  *
205b81b6b3SRodney W. Grimes  *  Software Distribution Coordinator  or  Software.Distribution@CS.CMU.EDU
215b81b6b3SRodney W. Grimes  *  School of Computer Science
225b81b6b3SRodney W. Grimes  *  Carnegie Mellon University
235b81b6b3SRodney W. Grimes  *  Pittsburgh PA 15213-3890
245b81b6b3SRodney W. Grimes  *
255b81b6b3SRodney W. Grimes  * any improvements or extensions that they make and grant Carnegie the
265b81b6b3SRodney W. Grimes  * rights to redistribute these changes.
275b81b6b3SRodney W. Grimes  */
280edf66ecSRodney W. Grimes 
296437fb2cSGarrett Wollman #ifndef _DDB_DB_LEX_H_
304753168fSBruce Evans #define	_DDB_DB_LEX_H_
316437fb2cSGarrett Wollman 
325b81b6b3SRodney W. Grimes /*
335b81b6b3SRodney W. Grimes  *	Author: David B. Golub, Carnegie Mellon University
345b81b6b3SRodney W. Grimes  *	Date:	7/90
355b81b6b3SRodney W. Grimes  */
365b81b6b3SRodney W. Grimes /*
375b81b6b3SRodney W. Grimes  * Lexical analyzer.
385b81b6b3SRodney W. Grimes  */
39e0c5dd43SConrad Meyer 
40e0c5dd43SConrad Meyer /*
41e0c5dd43SConrad Meyer  * Options and flags can configure db_read_token() => db_lex() behavior.
42e0c5dd43SConrad Meyer  *
43e0c5dd43SConrad Meyer  * When a radix other than DRT_DEFAULT_RADIX is used, it overrides
44e0c5dd43SConrad Meyer  * auto-detection, as well as the user-specified db_radix, in db_lex() of
45e0c5dd43SConrad Meyer  * 'tNUMBER' tokens.
46e0c5dd43SConrad Meyer  */
47e0c5dd43SConrad Meyer enum {
48e0c5dd43SConrad Meyer 	/* Infer or use db_radix using the old logic. */
49e0c5dd43SConrad Meyer 	DRT_DEFAULT_RADIX = 0,
50e0c5dd43SConrad Meyer 	/* The following set an explicit base for tNUMBER lex. */
51e0c5dd43SConrad Meyer 	DRT_OCTAL,
52e0c5dd43SConrad Meyer 	DRT_DECIMAL,
53e0c5dd43SConrad Meyer 	DRT_HEXADECIMAL,
54e0c5dd43SConrad Meyer };
55e0c5dd43SConrad Meyer #define	DRT_RADIX_MASK	0x3
56e0c5dd43SConrad Meyer /*
57e0c5dd43SConrad Meyer  * Flag bit powers of two for db_read_token_flags.
58e0c5dd43SConrad Meyer  * The low 2 bits are reserved for radix selection.
59*25b3370cSConrad Meyer  *
60*25b3370cSConrad Meyer  * WSPACE: Yield explicit tWSPACE tokens when one or more whitespace characters
61*25b3370cSConrad Meyer  *         is consumed.
62*25b3370cSConrad Meyer  * HEX:    Allow tNUMBER tokens to start with 'A'-'F' without explicit "0x"
63*25b3370cSConrad Meyer  *         prefix.
64e0c5dd43SConrad Meyer  */
65e0c5dd43SConrad Meyer enum {
66e0c5dd43SConrad Meyer 	_DRT_WSPACE = 2,
67*25b3370cSConrad Meyer 	_DRT_HEX,
68e0c5dd43SConrad Meyer };
69e0c5dd43SConrad Meyer #ifndef BIT
70e0c5dd43SConrad Meyer #define	BIT(n)	(1ull << (n))
71e0c5dd43SConrad Meyer #endif
72e0c5dd43SConrad Meyer enum {
73e0c5dd43SConrad Meyer 	DRT_WSPACE = BIT(_DRT_WSPACE),
74*25b3370cSConrad Meyer 	DRT_HEX = BIT(_DRT_HEX),
75e0c5dd43SConrad Meyer };
76*25b3370cSConrad Meyer #define	DRT_VALID_FLAGS_MASK	((int)DRT_RADIX_MASK | \
77*25b3370cSConrad Meyer     DRT_WSPACE | \
78*25b3370cSConrad Meyer     DRT_HEX)
79e0c5dd43SConrad Meyer 
8014e10f99SAlfred Perlstein void	 db_flush_lex(void);
81c9b0cc3bSRobert Watson char	*db_get_line(void);
82c9b0cc3bSRobert Watson void	 db_inject_line(const char *command);
8314e10f99SAlfred Perlstein int	 db_read_line(void);
84e0c5dd43SConrad Meyer int	 db_read_token_flags(int);
8514e10f99SAlfred Perlstein void	 db_unread_token(int t);
865b81b6b3SRodney W. Grimes 
87e0c5dd43SConrad Meyer static inline int
db_read_token(void)88e0c5dd43SConrad Meyer db_read_token(void)
89e0c5dd43SConrad Meyer {
90e0c5dd43SConrad Meyer 	return (db_read_token_flags(0));
91e0c5dd43SConrad Meyer }
92e0c5dd43SConrad Meyer 
933da6ef3cSBruce Evans extern db_expr_t	db_tok_number;
945b81b6b3SRodney W. Grimes #define	TOK_STRING_SIZE		120
955b81b6b3SRodney W. Grimes extern char	db_tok_string[TOK_STRING_SIZE];
965b81b6b3SRodney W. Grimes 
975b81b6b3SRodney W. Grimes #define	tEOF		(-1)
985b81b6b3SRodney W. Grimes #define	tEOL		1
995b81b6b3SRodney W. Grimes #define	tNUMBER		2
1005b81b6b3SRodney W. Grimes #define	tIDENT		3
1015b81b6b3SRodney W. Grimes #define	tPLUS		4
1025b81b6b3SRodney W. Grimes #define	tMINUS		5
1035b81b6b3SRodney W. Grimes #define	tDOT		6
1045b81b6b3SRodney W. Grimes #define	tSTAR		7
1055b81b6b3SRodney W. Grimes #define	tSLASH		8
1065b81b6b3SRodney W. Grimes #define	tEQ		9
1075b81b6b3SRodney W. Grimes #define	tLPAREN		10
1085b81b6b3SRodney W. Grimes #define	tRPAREN		11
1095b81b6b3SRodney W. Grimes #define	tPCT		12
1105b81b6b3SRodney W. Grimes #define	tHASH		13
1115b81b6b3SRodney W. Grimes #define	tCOMMA		14
1125b81b6b3SRodney W. Grimes #define	tDITTO		15
1135b81b6b3SRodney W. Grimes #define	tDOLLAR		16
1145b81b6b3SRodney W. Grimes #define	tEXCL		17
1155b81b6b3SRodney W. Grimes #define	tSHIFT_L	18
1165b81b6b3SRodney W. Grimes #define	tSHIFT_R	19
1175b81b6b3SRodney W. Grimes #define	tDOTDOT		20
118c9b0cc3bSRobert Watson #define	tSEMI		21
119c69cee69SPedro F. Giffuni #define	tLOG_EQ		22
120c69cee69SPedro F. Giffuni #define	tLOG_NOT_EQ	23
121c69cee69SPedro F. Giffuni #define	tLESS		24
122c69cee69SPedro F. Giffuni #define	tLESS_EQ	25
123c69cee69SPedro F. Giffuni #define	tGREATER	26
124c69cee69SPedro F. Giffuni #define	tGREATER_EQ	27
125c69cee69SPedro F. Giffuni #define	tBIT_AND	28
126c69cee69SPedro F. Giffuni #define	tBIT_OR		29
127c69cee69SPedro F. Giffuni #define	tLOG_AND	30
128c69cee69SPedro F. Giffuni #define	tLOG_OR		31
129c69cee69SPedro F. Giffuni #define	tSTRING		32
130c69cee69SPedro F. Giffuni #define	tQUESTION	33
131c69cee69SPedro F. Giffuni #define	tBIT_NOT	34
132e0c5dd43SConrad Meyer #define	tWSPACE		35
133*25b3370cSConrad Meyer #define	tCOLON		36
134*25b3370cSConrad Meyer #define	tCOLONCOLON	37
1355b81b6b3SRodney W. Grimes 
1364753168fSBruce Evans #endif /* !_DDB_DB_LEX_H_ */
137