|
|
1.1 root 1: /*
2: * Source input, lexer and parser
3: */
4:
5: /* $Header: lex.h,v 3.1 88/11/03 09:13:40 egisin Exp $ */
6:
7: #define IDENT 64
8:
9: typedef struct source Source;
10: struct source {
11: char *str; /* input pointer */
12: int type; /* input type */
13: union {
14: char **strv; /* string [] */
15: FILE *file; /* file */
16: struct tbl *tblp; /* alias */
17: } u;
18: int line; /* line number */
19: char *file; /* input file name */
20: int echo; /* echo input to shlout */
21: Source *next; /* stacked source */
22: };
23:
24: /* Source.type values */
25: #define SEOF 0 /* input EOF */
26: #define STTY 1 /* terminal input */
27: #define SFILE 2 /* file input */
28: #define SSTRING 4 /* string */
29: #define SWSTR 3 /* string without \n */
30: #define SWORDS 5 /* string[] */
31: #define SWORDSEP 8 /* string[] seperator */
32: #define SALIAS 6 /* alias expansion */
33: #define SHIST 7 /* history expansion */
34:
35: Source *pushs ARGS((int stype)); /* push Source */
36: struct op *compile ARGS((Source *s)); /* compile tree */
37:
38: /*
39: * states while lexing word
40: */
41: #define SBASE 0 /* outside any lexical constructs */
42: #define SWORD 6 /* implicit quoting for substitute() */
43: #define SSQUOTE 1 /* inside '' */
44: #define SDQUOTE 2 /* inside "" */
45: #define SBRACE 3 /* inside ${} */
46: #define SPAREN 4 /* inside $() */
47: #define SBQUOTE 5 /* inside `` */
48:
49: Extern int multiline; /* \n changed to ; */
50:
51: typedef union {
52: char *cp;
53: char **wp;
54: int i;
55: struct op *o;
56: } YYSTYPE;
57:
58: #define IODEFAULT (-1) /* token for default IO unit */
59:
60: #define LWORD 256
61: #define LOGAND 257
62: #define LOGOR 258
63: #define BREAK 259
64: #define IF 260
65: #define THEN 261
66: #define ELSE 262
67: #define ELIF 263
68: #define FI 264
69: #define CASE 265
70: #define ESAC 266
71: #define FOR 267
72: #define WHILE 268
73: #define UNTIL 269
74: #define DO 270
75: #define DONE 271
76: #define IN 272
77: #define FUNCTION 273
78: #define TIME 274
79: #define REDIR 275
80: #define MPAREN 276 /* () */
81: #define YYERRCODE 300
82:
83: /* flags to yylex */
84: #define CONTIN BIT(0) /* skip new lines to complete command */
85: #define ONEWORD BIT(1) /* single word for substitute() */
86: #define ALIAS BIT(2) /* recognize alias */
87: #define KEYWORD BIT(3) /* recognize keywords */
88:
89: #define SYNTAXERR zzerr()
90: #define HERES 10 /* max << in line */
91:
92: Extern char line [LINE+1]; /* input line */
93: Extern Source *source; /* yyparse/yylex source */
94: Extern YYSTYPE yylval; /* result from yylex */
95: Extern int yynerrs;
96: Extern struct ioword *heres [HERES], **herep;
97: Extern int iounit;
98: Extern char ident [IDENT+1];
99:
100: extern int yylex ARGS((int flags));
101: extern void yyerror ARGS((Const char *msg));
102:
103: #define HISTORY 100 /* size of saved history */
104:
105: extern char *history [HISTORY]; /* saved commands */
106: extern char **histptr; /* last history item */
107: extern int histpush; /* number of pushed fc commands */
108:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.