1*4887Schin /***********************************************************************
2*4887Schin *                                                                      *
3*4887Schin *               This software is part of the ast package               *
4*4887Schin *           Copyright (c) 1982-2007 AT&T Knowledge Ventures            *
5*4887Schin *                      and is licensed under the                       *
6*4887Schin *                  Common Public License, Version 1.0                  *
7*4887Schin *                      by AT&T Knowledge Ventures                      *
8*4887Schin *                                                                      *
9*4887Schin *                A copy of the License is available at                 *
10*4887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*4887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*4887Schin *                                                                      *
13*4887Schin *              Information and Software Systems Research               *
14*4887Schin *                            AT&T Research                             *
15*4887Schin *                           Florham Park NJ                            *
16*4887Schin *                                                                      *
17*4887Schin *                  David Korn <dgk@research.att.com>                   *
18*4887Schin *                                                                      *
19*4887Schin ***********************************************************************/
20*4887Schin #pragma prototyped
21*4887Schin #ifndef NOTSYM
22*4887Schin /*
23*4887Schin  *	UNIX shell
24*4887Schin  *	Written by David Korn
25*4887Schin  *	These are the definitions for the lexical analyzer
26*4887Schin  */
27*4887Schin 
28*4887Schin #include	<cdt.h>
29*4887Schin #include	"FEATURE/options"
30*4887Schin #include	"shnodes.h"
31*4887Schin #include	"shtable.h"
32*4887Schin #include	"lexstates.h"
33*4887Schin 
34*4887Schin struct shlex_t
35*4887Schin {
36*4887Schin 	Shell_t		*sh;		/* pointer to the interpreter */
37*4887Schin 	struct argnod	*arg;		/* current word */
38*4887Schin 	struct ionod	*heredoc;	/* pending here document list */
39*4887Schin 	int		token;		/* current token number */
40*4887Schin 	int		lastline;	/* last line number */
41*4887Schin 	int		lasttok;	/* previous token number */
42*4887Schin 	int		digits;		/* numerical value with word token */
43*4887Schin 	char		aliasok;	/* on when alias is legal */
44*4887Schin 	char		assignok;	/* on when name=value is legal */
45*4887Schin 	int		inlineno;	/* saved value of sh.inlineno */
46*4887Schin 	int		firstline;	/* saved value of sh.st.firstline */
47*4887Schin 	int		comsub;		/* parsing command substitution */
48*4887Schin #if SHOPT_KIA
49*4887Schin 	Sfio_t		*kiafile;	/* kia output file */
50*4887Schin 	Sfio_t		*kiatmp;	/* kia reference file */
51*4887Schin 	unsigned long	script;		/* script entity number */
52*4887Schin 	unsigned long	fscript;	/* script file entity number */
53*4887Schin 	unsigned long	current;	/* current entity number */
54*4887Schin 	unsigned long	unknown;	/* <unknown> entity number */
55*4887Schin 	off_t		kiabegin;	/* offset of first entry */
56*4887Schin 	char		*scriptname;	/* name of script file */
57*4887Schin 	Dt_t		*entity_tree;	/* for entity ids */
58*4887Schin #endif /* SHOPT_KIA */
59*4887Schin };
60*4887Schin 
61*4887Schin /* symbols for parsing */
62*4887Schin #define NL		'\n'
63*4887Schin #define NOTSYM		'!'
64*4887Schin #define SYMRES		0400		/* reserved word symbols */
65*4887Schin #define DOSYM		(SYMRES|01)
66*4887Schin #define FISYM		(SYMRES|02)
67*4887Schin #define ELIFSYM		(SYMRES|03)
68*4887Schin #define ELSESYM		(SYMRES|04)
69*4887Schin #define INSYM		(SYMRES|05)
70*4887Schin #define THENSYM		(SYMRES|06)
71*4887Schin #define DONESYM		(SYMRES|07)
72*4887Schin #define ESACSYM		(SYMRES|010)
73*4887Schin #define IFSYM		(SYMRES|011)
74*4887Schin #define FORSYM		(SYMRES|012)
75*4887Schin #define WHILESYM	(SYMRES|013)
76*4887Schin #define UNTILSYM	(SYMRES|014)
77*4887Schin #define CASESYM		(SYMRES|015)
78*4887Schin #define FUNCTSYM	(SYMRES|016)
79*4887Schin #define SELECTSYM	(SYMRES|017)
80*4887Schin #define TIMESYM		(SYMRES|020)
81*4887Schin #define NSPACESYM	(SYMRES|021)
82*4887Schin 
83*4887Schin #define SYMREP		01000		/* symbols for doubled characters */
84*4887Schin #define BREAKCASESYM	(SYMREP|';')
85*4887Schin #define ANDFSYM		(SYMREP|'&')
86*4887Schin #define ORFSYM		(SYMREP|'|')
87*4887Schin #define IOAPPSYM	(SYMREP|'>')
88*4887Schin #define IODOCSYM	(SYMREP|'<')
89*4887Schin #define EXPRSYM		(SYMREP|'(')
90*4887Schin #define BTESTSYM 	(SYMREP|'[')
91*4887Schin #define ETESTSYM	(SYMREP|']')
92*4887Schin 
93*4887Schin #define SYMMASK		0170000
94*4887Schin #define SYMPIPE		010000	/* trailing '|' */
95*4887Schin #define SYMLPAR		020000	/* trailing LPAREN */
96*4887Schin #define SYMAMP		040000	/* trailing '&' */
97*4887Schin #define SYMGT		0100000	/* trailing '>' */
98*4887Schin #define SYMSEMI		0110000	/* trailing ';' */
99*4887Schin #define SYMSHARP	0120000	/* trailing '#' */
100*4887Schin #define IOSEEKSYM	(SYMSHARP|'<')
101*4887Schin #define IOMOV0SYM	(SYMAMP|'<')
102*4887Schin #define IOMOV1SYM	(SYMAMP|'>')
103*4887Schin #define FALLTHRUSYM	(SYMAMP|';')
104*4887Schin #define COOPSYM		(SYMAMP|'|')
105*4887Schin #define IORDWRSYM	(SYMGT|'<')
106*4887Schin #define IOCLOBSYM	(SYMPIPE|'>')
107*4887Schin #define IPROCSYM	(SYMLPAR|'<')
108*4887Schin #define OPROCSYM	(SYMLPAR|'>')
109*4887Schin #define EOFSYM		04000	/* end-of-file */
110*4887Schin #define TESTUNOP	04001
111*4887Schin #define TESTBINOP	04002
112*4887Schin #define LABLSYM		04003
113*4887Schin #define IOVNAME		04004
114*4887Schin 
115*4887Schin /* additional parser flag, others in <shell.h> */
116*4887Schin #define SH_EMPTY	04
117*4887Schin #define SH_NOIO		010
118*4887Schin #define	SH_ASSIGN	020
119*4887Schin #define	SH_FUNDEF	040
120*4887Schin #define SH_ARRAY	0100
121*4887Schin #define SH_SEMI		0200	/* semi-colon after NL ok */
122*4887Schin 
123*4887Schin #define SH_COMPASSIGN	010	/* allow compound assignments only */
124*4887Schin 
125*4887Schin typedef struct  _shlex_
126*4887Schin {
127*4887Schin 	struct shlex_t		_shlex;
128*4887Schin #ifdef  _SHLEX_PRIVATE
129*4887Schin 	_SHLEX_PRIVATE
130*4887Schin #endif
131*4887Schin } Lex_t;
132*4887Schin 
133*4887Schin #define	shlex			(((Lex_t*)(sh.lex_context))->_shlex)
134*4887Schin extern const char		e_unexpected[];
135*4887Schin extern const char		e_unmatched[];
136*4887Schin extern const char		e_endoffile[];
137*4887Schin extern const char		e_newline[];
138*4887Schin 
139*4887Schin /* odd chars */
140*4887Schin #define LBRACE	'{'
141*4887Schin #define RBRACE	'}'
142*4887Schin #define LPAREN	'('
143*4887Schin #define RPAREN	')'
144*4887Schin #define LBRACT	'['
145*4887Schin #define RBRACT	']'
146*4887Schin 
147*4887Schin extern int		sh_lex();
148*4887Schin extern Lex_t		*sh_lexopen(Lex_t*, Shell_t*, int);
149*4887Schin extern void 		sh_lexskip(int,int,int);
150*4887Schin extern void 		sh_syntax(void);
151*4887Schin 
152*4887Schin #endif /* !NOTSYM */
153