Home | History | Annotate | Line # | Download | only in ksh
lex.h revision 1.1
      1 /*
      2  * Source input, lexer and parser
      3  */
      4 
      5 /* $Id: lex.h,v 1.1 1996/09/21 23:35:15 jtc Exp $ */
      6 
      7 #define	IDENT	64
      8 
      9 typedef struct source Source;
     10 struct source {
     11 	const char *str;	/* input pointer */
     12 	int	type;		/* input type */
     13 	char const *start;	/* start of current buffer */
     14 	union {
     15 		char ugbuf[2];	/* buffer for ungetsc() (SREREAD) */
     16 		char **strv;	/* string [] */
     17 		struct shf *shf; /* shell file */
     18 		struct tbl *tblp; /* alias */
     19 		char *freeme;	/* also for SREREAD */
     20 	} u;
     21 	int	line;		/* line number */
     22 	int	errline;	/* line the error occured on (0 if not set) */
     23 	const char *file;	/* input file name */
     24 	int	flags;		/* SF_* */
     25 	Area	*areap;
     26 	XString	xs;		/* input buffer */
     27 	Source *next;		/* stacked source */
     28 };
     29 
     30 /* Source.type values */
     31 #define	SEOF		0	/* input EOF */
     32 #define	SFILE		1	/* file input */
     33 #define SSTDIN		2	/* read stdin */
     34 #define	SSTRING		3	/* string */
     35 #define	SWSTR		4	/* string without \n */
     36 #define	SWORDS		5	/* string[] */
     37 #define	SWORDSEP	6	/* string[] seperator */
     38 #define	SALIAS		7	/* alias expansion */
     39 #define SREREAD		8	/* read ahead to be re-scanned */
     40 
     41 /* Source.flags values */
     42 #define SF_ECHO		BIT(0)	/* echo input to shlout */
     43 #define SF_ALIAS	BIT(1)	/* faking space at end of alias */
     44 #define SF_ALIASEND	BIT(2)	/* faking space at end of alias */
     45 #define SF_TTY		BIT(3)	/* type == SSTDIN & it is a tty */
     46 
     47 /*
     48  * states while lexing word
     49  */
     50 #define	SBASE	0		/* outside any lexical constructs */
     51 #define	SWORD	1		/* implicit quoting for substitute() */
     52 #define	SDPAREN	2		/* inside (( )), implicit quoting */
     53 #define	SSQUOTE	3		/* inside '' */
     54 #define	SDQUOTE	4		/* inside "" */
     55 #define	SBRACE	5		/* inside ${} */
     56 #define	SPAREN	6		/* inside $() */
     57 #define	SBQUOTE	7		/* inside `` */
     58 #define	SDDPAREN 8		/* inside $(( )) */
     59 #define SHEREDELIM 9		/* parsing <<,<<- delimiter */
     60 #define SHEREDQUOTE 10		/* parsing " in <<,<<- delimiter */
     61 #define SPATTERN 11		/* parsing *(...|...) pattern (*+?@!) */
     62 #define STBRACE 12		/* parsing ${..[#%]..} */
     63 
     64 typedef union {
     65 	int	i;
     66 	char   *cp;
     67 	char  **wp;
     68 	struct op *o;
     69 	struct ioword *iop;
     70 } YYSTYPE;
     71 
     72 /* If something is added here, add it to tokentab[] in syn.c as well */
     73 #define	LWORD	256
     74 #define	LOGAND	257		/* && */
     75 #define	LOGOR	258		/* || */
     76 #define	BREAK	259		/* ;; */
     77 #define	IF	260
     78 #define	THEN	261
     79 #define	ELSE	262
     80 #define	ELIF	263
     81 #define	FI	264
     82 #define	CASE	265
     83 #define	ESAC	266
     84 #define	FOR	267
     85 #define SELECT	268
     86 #define	WHILE	269
     87 #define	UNTIL	270
     88 #define	DO	271
     89 #define	DONE	272
     90 #define	IN	273
     91 #define	FUNCTION 274
     92 #define	TIME	275
     93 #define	REDIR	276
     94 #define MDPAREN	277		/* (( )) */
     95 #define BANG	278		/* ! */
     96 #define DBRACKET 279		/* [[ .. ]] */
     97 #define COPROC	280		/* |& */
     98 #define	YYERRCODE 300
     99 
    100 /* flags to yylex */
    101 #define	CONTIN	BIT(0)		/* skip new lines to complete command */
    102 #define	ONEWORD	BIT(1)		/* single word for substitute() */
    103 #define	ALIAS	BIT(2)		/* recognize alias */
    104 #define	KEYWORD	BIT(3)		/* recognize keywords */
    105 #define LETEXPR	BIT(4)		/* get expression inside (( )) */
    106 #define VARASN	BIT(5)		/* check for var=word */
    107 #define ARRAYVAR BIT(6)		/* parse x[1 & 2] as one word */
    108 #define ESACONLY BIT(7)		/* only accept esac keyword */
    109 #define CMDWORD BIT(8)		/* parsing simple command (alias related) */
    110 #define HEREDELIM BIT(9)	/* parsing <<,<<- delimiter */
    111 
    112 #define	HERES	10		/* max << in line */
    113 
    114 EXTERN	Source *source;		/* yyparse/yylex source */
    115 EXTERN	YYSTYPE	yylval;		/* result from yylex */
    116 EXTERN	int	yynerrs;
    117 EXTERN	struct ioword *heres [HERES], **herep;
    118 EXTERN	char	ident [IDENT+1];
    119 
    120 #ifdef HISTORY
    121 # define HISTORYSIZE	128	/* size of saved history */
    122 
    123 EXTERN	char  **history;	/* saved commands */
    124 EXTERN	char  **histptr;	/* last history item */
    125 EXTERN	int	histsize;	/* history size */
    126 #endif /* HISTORY */
    127