xref: /csrg-svn/old/as.vax/asexpr.h (revision 5830)
1602Sbill /*
2*5830Srrh  *	Copyright (c) 1982 Regents of the University of California
3*5830Srrh  *	@(#)asexpr.h 4.3 02/14/82
4*5830Srrh  */
5*5830Srrh /*
6602Sbill  *	Definitions to parse tokens
7602Sbill  */
8602Sbill 
9602Sbill #define ERROR(string)		yyerror(string); goto errorfix
10602Sbill 
11602Sbill #define peekahead (*tokptr)
12602Sbill 
13602Sbill #define shift 			val = yylex()
14602Sbill #define advance 	shift
15602Sbill 
16602Sbill #define shiftover(token)	if (val != token) { \
17602Sbill 					yyerror("token expected"); \
18602Sbill 					goto errorfix; \
19602Sbill 				} \
20602Sbill 				shift
21602Sbill 
22602Sbill #define advanceover 	shiftover
23602Sbill 
24602Sbill /*
25602Sbill  *	To speed up the expression processing, we class the input tokens
26602Sbill  *	into various sets.
27602Sbill  *
28602Sbill  *	We don't call the recursive descent expression analyzer if we can
29602Sbill  *	determine by looking at the next token after the first token in
30602Sbill  *	an expression that the expression is simple (name, integer or floating
31602Sbill  *	point value).  Expressions with operators are parsed using the recursive
32602Sbill  *	descent method.
33602Sbill  */
34602Sbill 
35602Sbill /*
36602Sbill  *	Functional forwards for expression utility routines
37602Sbill  */
38602Sbill struct	exp	*combine();
39602Sbill struct	exp	*boolterm();
40602Sbill struct	exp	*term();
41602Sbill struct	exp	*factor();
42602Sbill struct	exp	*yukkyexpr();
43602Sbill 
44602Sbill /*
45602Sbill  *	The set definitions
46602Sbill  */
47602Sbill 
48602Sbill extern	char	tokensets[(LASTTOKEN) - (FIRSTTOKEN) + 1];
49602Sbill 
50635Shenry #define	LINSTBEGIN	01	/*SEMI, NL, NAME*/
51602Sbill #define	EBEGOPS		02	/*LP, MINUS, TILDE*/
52635Shenry #define	YUKKYEXPRBEG	04	/*NAME, INSTn, INST0, REG, BFINT*/
53602Sbill #define	SAFEEXPRBEG	010	/*INT, FLTNUM*/
54635Shenry #define	ADDOPS		020	/*PLUS, MINUS*/
55602Sbill #define	BOOLOPS		040	/*IOR, XOR, AND*/
56635Shenry #define	MULOPS		0100	/*LSH, RSH, MUL, DIV, TILDE*/
57602Sbill 
58602Sbill #define	INTOKSET(val, set)	(tokensets[(val)] & (set) )
59602Sbill 
60*5830Srrh inttoktype	exprparse();
61*5830Srrh inttoktype	funnyreg();
62*5830Srrh inttoktype	yylex();
63*5830Srrh 
64602Sbill #define expr(xp, val) { \
65602Sbill 	if ( (!INTOKSET(val, EBEGOPS)) && (!INTOKSET(peekahead, ADDOPS+BOOLOPS+MULOPS))) { \
66602Sbill 		if (INTOKSET(val, YUKKYEXPRBEG)) xp = yukkyexpr(val, yylval); \
67602Sbill 		else xp = (struct exp *) yylval; \
68602Sbill 		shift; \
69602Sbill 	} else { \
70602Sbill 		val = exprparse(val, ptrloc1xp); \
71602Sbill 		xp = loc1xp; \
72602Sbill 	} \
73602Sbill     }
74602Sbill 
75602Sbill /*
76602Sbill  *	Registers can be either of the form r0...pc, or
77602Sbill  *	of the form % <expression>
78602Sbill  *	NOTE:	Reizers documentation on the assembler says that it
79602Sbill  *	can be of the form r0 + <expression>.. That's not true.
80602Sbill  *
81602Sbill  *	NOTE:	Reizer's yacc grammar would seem to allow an expression
82602Sbill  *	to be: (This is undocumented)
83602Sbill  *		a)	a register
84602Sbill  *		b)	an Instruction (INSTn or INST0)
85602Sbill  */
86602Sbill 
87602Sbill #define findreg(regno) \
88602Sbill 	if (val == REG) { \
89602Sbill 		regno = yylval; \
90602Sbill 		shift; \
91602Sbill 	} else \
92602Sbill 	if (val == REGOP) { \
93602Sbill 		shift;	/*over the REGOP*/ \
94602Sbill 		val = funnyreg(val, ptrregno); \
95602Sbill 	} \
96602Sbill 	else { ERROR ("register expected"); }
97