14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*8462SApril.Chin@Sun.COM *          Copyright (c) 1982-2008 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
7*8462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                  David Korn <dgk@research.att.com>                   *
184887Schin *                                                                      *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin #ifndef NOTSYM
224887Schin /*
234887Schin  *	UNIX shell
244887Schin  *	Written by David Korn
254887Schin  *	These are the definitions for the lexical analyzer
264887Schin  */
274887Schin 
284887Schin #include	<cdt.h>
294887Schin #include	"FEATURE/options"
304887Schin #include	"shnodes.h"
314887Schin #include	"shtable.h"
324887Schin #include	"lexstates.h"
334887Schin 
34*8462SApril.Chin@Sun.COM 
35*8462SApril.Chin@Sun.COM typedef struct  _shlex_
364887Schin {
374887Schin 	Shell_t		*sh;		/* pointer to the interpreter */
384887Schin 	struct argnod	*arg;		/* current word */
394887Schin 	struct ionod	*heredoc;	/* pending here document list */
404887Schin 	int		token;		/* current token number */
414887Schin 	int		lastline;	/* last line number */
424887Schin 	int		lasttok;	/* previous token number */
434887Schin 	int		digits;		/* numerical value with word token */
444887Schin 	char		aliasok;	/* on when alias is legal */
454887Schin 	char		assignok;	/* on when name=value is legal */
46*8462SApril.Chin@Sun.COM 	char		inexec;		/* on when processing exec */
47*8462SApril.Chin@Sun.COM 	char		intypeset;	/* on when processing typeset */
48*8462SApril.Chin@Sun.COM 	char		comp_assign;	/* in compound assignment */
49*8462SApril.Chin@Sun.COM 	char		comsub;		/* parsing command substitution */
504887Schin 	int		inlineno;	/* saved value of sh.inlineno */
514887Schin 	int		firstline;	/* saved value of sh.st.firstline */
524887Schin #if SHOPT_KIA
534887Schin 	Sfio_t		*kiafile;	/* kia output file */
544887Schin 	Sfio_t		*kiatmp;	/* kia reference file */
554887Schin 	unsigned long	script;		/* script entity number */
564887Schin 	unsigned long	fscript;	/* script file entity number */
574887Schin 	unsigned long	current;	/* current entity number */
584887Schin 	unsigned long	unknown;	/* <unknown> entity number */
594887Schin 	off_t		kiabegin;	/* offset of first entry */
604887Schin 	char		*scriptname;	/* name of script file */
614887Schin 	Dt_t		*entity_tree;	/* for entity ids */
624887Schin #endif /* SHOPT_KIA */
63*8462SApril.Chin@Sun.COM #ifdef  _SHLEX_PRIVATE
64*8462SApril.Chin@Sun.COM 	_SHLEX_PRIVATE
65*8462SApril.Chin@Sun.COM #endif
66*8462SApril.Chin@Sun.COM } Lex_t;
674887Schin 
684887Schin /* symbols for parsing */
694887Schin #define NL		'\n'
704887Schin #define NOTSYM		'!'
714887Schin #define SYMRES		0400		/* reserved word symbols */
724887Schin #define DOSYM		(SYMRES|01)
734887Schin #define FISYM		(SYMRES|02)
744887Schin #define ELIFSYM		(SYMRES|03)
754887Schin #define ELSESYM		(SYMRES|04)
764887Schin #define INSYM		(SYMRES|05)
774887Schin #define THENSYM		(SYMRES|06)
784887Schin #define DONESYM		(SYMRES|07)
794887Schin #define ESACSYM		(SYMRES|010)
804887Schin #define IFSYM		(SYMRES|011)
814887Schin #define FORSYM		(SYMRES|012)
824887Schin #define WHILESYM	(SYMRES|013)
834887Schin #define UNTILSYM	(SYMRES|014)
844887Schin #define CASESYM		(SYMRES|015)
854887Schin #define FUNCTSYM	(SYMRES|016)
864887Schin #define SELECTSYM	(SYMRES|017)
874887Schin #define TIMESYM		(SYMRES|020)
884887Schin #define NSPACESYM	(SYMRES|021)
894887Schin 
904887Schin #define SYMREP		01000		/* symbols for doubled characters */
914887Schin #define BREAKCASESYM	(SYMREP|';')
924887Schin #define ANDFSYM		(SYMREP|'&')
934887Schin #define ORFSYM		(SYMREP|'|')
944887Schin #define IOAPPSYM	(SYMREP|'>')
954887Schin #define IODOCSYM	(SYMREP|'<')
964887Schin #define EXPRSYM		(SYMREP|'(')
974887Schin #define BTESTSYM 	(SYMREP|'[')
984887Schin #define ETESTSYM	(SYMREP|']')
994887Schin 
1004887Schin #define SYMMASK		0170000
1014887Schin #define SYMPIPE		010000	/* trailing '|' */
1024887Schin #define SYMLPAR		020000	/* trailing LPAREN */
1034887Schin #define SYMAMP		040000	/* trailing '&' */
1044887Schin #define SYMGT		0100000	/* trailing '>' */
1054887Schin #define SYMSEMI		0110000	/* trailing ';' */
1064887Schin #define SYMSHARP	0120000	/* trailing '#' */
1074887Schin #define IOSEEKSYM	(SYMSHARP|'<')
1084887Schin #define IOMOV0SYM	(SYMAMP|'<')
1094887Schin #define IOMOV1SYM	(SYMAMP|'>')
1104887Schin #define FALLTHRUSYM	(SYMAMP|';')
1114887Schin #define COOPSYM		(SYMAMP|'|')
1124887Schin #define IORDWRSYM	(SYMGT|'<')
1134887Schin #define IOCLOBSYM	(SYMPIPE|'>')
1144887Schin #define IPROCSYM	(SYMLPAR|'<')
1154887Schin #define OPROCSYM	(SYMLPAR|'>')
1164887Schin #define EOFSYM		04000	/* end-of-file */
1174887Schin #define TESTUNOP	04001
1184887Schin #define TESTBINOP	04002
1194887Schin #define LABLSYM		04003
1204887Schin #define IOVNAME		04004
1214887Schin 
1224887Schin /* additional parser flag, others in <shell.h> */
1234887Schin #define SH_EMPTY	04
1244887Schin #define SH_NOIO		010
1254887Schin #define	SH_ASSIGN	020
1264887Schin #define	SH_FUNDEF	040
1274887Schin #define SH_ARRAY	0100
1284887Schin #define SH_SEMI		0200	/* semi-colon after NL ok */
1294887Schin 
1304887Schin #define SH_COMPASSIGN	010	/* allow compound assignments only */
1314887Schin 
132*8462SApril.Chin@Sun.COM #if 0
1334887Schin typedef struct  _shlex_
1344887Schin {
1354887Schin 	struct shlex_t		_shlex;
1364887Schin #ifdef  _SHLEX_PRIVATE
1374887Schin 	_SHLEX_PRIVATE
1384887Schin #endif
1394887Schin } Lex_t;
1404887Schin 
1414887Schin #define	shlex			(((Lex_t*)(sh.lex_context))->_shlex)
142*8462SApril.Chin@Sun.COM #endif
1434887Schin extern const char		e_unexpected[];
1444887Schin extern const char		e_unmatched[];
1454887Schin extern const char		e_endoffile[];
1464887Schin extern const char		e_newline[];
1474887Schin 
1484887Schin /* odd chars */
1494887Schin #define LBRACE	'{'
1504887Schin #define RBRACE	'}'
1514887Schin #define LPAREN	'('
1524887Schin #define RPAREN	')'
1534887Schin #define LBRACT	'['
1544887Schin #define RBRACT	']'
1554887Schin 
156*8462SApril.Chin@Sun.COM extern int		sh_lex(Lex_t*);
157*8462SApril.Chin@Sun.COM extern Shnode_t		*sh_dolparen(Lex_t*);
1584887Schin extern Lex_t		*sh_lexopen(Lex_t*, Shell_t*, int);
159*8462SApril.Chin@Sun.COM extern void 		sh_lexskip(Lex_t*,int,int,int);
160*8462SApril.Chin@Sun.COM extern void 		sh_syntax(Lex_t*);
161*8462SApril.Chin@Sun.COM #if SHOPT_KIA
162*8462SApril.Chin@Sun.COM     extern int                  kiaclose(Lex_t *);
163*8462SApril.Chin@Sun.COM     extern unsigned long        kiaentity(Lex_t*, const char*,int,int,int,int,unsigned long,int,int,const char*);
164*8462SApril.Chin@Sun.COM #endif /* SHOPT_KIA */
165*8462SApril.Chin@Sun.COM 
1664887Schin 
1674887Schin #endif /* !NOTSYM */
168