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