1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1982-2013 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 <dgkorn@gmail.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 	char		typed;		/* possible type definition on PATH */
53 	int		inlineno;	/* saved value of sh.inlineno */
54 	int		firstline;	/* saved value of sh.st.firstline */
55 	int		assignlevel;	/* nesting level for assignment */
56 	short		fundepth;	/* nesting level for functions */
57 #if SHOPT_KIA
58 	Sfio_t		*kiafile;	/* kia output file */
59 	Sfio_t		*kiatmp;	/* kia reference file */
60 	unsigned long	script;		/* script entity number */
61 	unsigned long	fscript;	/* script file entity number */
62 	unsigned long	current;	/* current entity number */
63 	unsigned long	unknown;	/* <unknown> entity number */
64 	off_t		kiabegin;	/* offset of first entry */
65 	char		*scriptname;	/* name of script file */
66 	Dt_t		*entity_tree;	/* for entity ids */
67 #endif /* SHOPT_KIA */
68 #ifdef  _SHLEX_PRIVATE
69 	_SHLEX_PRIVATE
70 #endif
71 } Lex_t;
72 
73 /* symbols for parsing */
74 #define NL		'\n'
75 #define NOTSYM		'!'
76 #define SYMRES		0400		/* reserved word symbols */
77 #define DOSYM		(SYMRES|01)
78 #define FISYM		(SYMRES|02)
79 #define ELIFSYM		(SYMRES|03)
80 #define ELSESYM		(SYMRES|04)
81 #define INSYM		(SYMRES|05)
82 #define THENSYM		(SYMRES|06)
83 #define DONESYM		(SYMRES|07)
84 #define ESACSYM		(SYMRES|010)
85 #define IFSYM		(SYMRES|011)
86 #define FORSYM		(SYMRES|012)
87 #define WHILESYM	(SYMRES|013)
88 #define UNTILSYM	(SYMRES|014)
89 #define CASESYM		(SYMRES|015)
90 #define FUNCTSYM	(SYMRES|016)
91 #define SELECTSYM	(SYMRES|017)
92 #define TIMESYM		(SYMRES|020)
93 #define NSPACESYM	(SYMRES|021)
94 
95 #define SYMREP		01000		/* symbols for doubled characters */
96 #define BREAKCASESYM	(SYMREP|';')
97 #define ANDFSYM		(SYMREP|'&')
98 #define ORFSYM		(SYMREP|'|')
99 #define IOAPPSYM	(SYMREP|'>')
100 #define IODOCSYM	(SYMREP|'<')
101 #define EXPRSYM		(SYMREP|'(')
102 #define BTESTSYM 	(SYMREP|'[')
103 #define ETESTSYM	(SYMREP|']')
104 
105 #define SYMMASK		0170000
106 #define SYMPIPE		010000	/* trailing '|' */
107 #define SYMLPAR		020000	/* trailing LPAREN */
108 #define SYMAMP		040000	/* trailing '&' */
109 #define SYMGT		0100000	/* trailing '>' */
110 #define SYMSEMI		0110000	/* trailing ';' */
111 #define SYMSHARP	0120000	/* trailing '#' */
112 #define IOSEEKSYM	(SYMSHARP|'<')
113 #define IOMOV0SYM	(SYMAMP|'<')
114 #define IOMOV1SYM	(SYMAMP|'>')
115 #define FALLTHRUSYM	(SYMAMP|';')
116 #define COOPSYM		(SYMAMP|'|')
117 #define IORDWRSYM	(SYMGT|'<')
118 #define IORDWRSYMT	(SYMSEMI|'<')
119 #define IOCLOBSYM	(SYMPIPE|'>')
120 #define PIPESYM2	(SYMPIPE|'&')
121 #define IPROCSYM	(SYMLPAR|'<')
122 #define OPROCSYM	(SYMLPAR|'>')
123 #define EOFSYM		04000	/* end-of-file */
124 #define TESTUNOP	04001
125 #define TESTBINOP	04002
126 #define LABLSYM		04003
127 #define IOVNAME		04004
128 
129 /* additional parser flag, others in <shell.h> */
130 #define SH_EMPTY	04
131 #define SH_NOIO		010
132 #define	SH_ASSIGN	020
133 #define	SH_FUNDEF	040
134 #define SH_ARRAY	0100
135 #define SH_SEMI		0200	/* semi-colon after NL ok */
136 
137 #define SH_COMPASSIGN	010	/* allow compound assignments only */
138 
139 extern const char		e_unexpected[];
140 extern const char		e_unmatched[];
141 extern const char		e_endoffile[];
142 extern const char		e_newline[];
143 
144 /* odd chars */
145 #define LBRACE	'{'
146 #define RBRACE	'}'
147 #define LPAREN	'('
148 #define RPAREN	')'
149 #define LBRACT	'['
150 #define RBRACT	']'
151 
152 extern int		sh_lex(Lex_t*);
153 extern Shnode_t		*sh_dolparen(Lex_t*);
154 extern Lex_t		*sh_lexopen(Lex_t*, Shell_t*, int);
155 extern void 		sh_lexskip(Lex_t*,int,int,int);
156 extern void 		sh_syntax(Lex_t*);
157 #if SHOPT_KIA
158     extern int                  kiaclose(Lex_t *);
159     extern unsigned long        kiaentity(Lex_t*, const char*,int,int,int,int,unsigned long,int,int,const char*);
160 #endif /* SHOPT_KIA */
161 
162 
163 #endif /* !NOTSYM */
164