xref: /original-bsd/old/as.tahoe/asexpr.h (revision e1aad660)
1*e1aad660Sbostic /*
2*e1aad660Sbostic  *	Copyright (c) 1982 Regents of the University of California
3*e1aad660Sbostic  *	@(#)asexpr.h 4.4 6/9/83
4*e1aad660Sbostic  */
5*e1aad660Sbostic /*
6*e1aad660Sbostic  *	Definitions to parse tokens
7*e1aad660Sbostic  */
8*e1aad660Sbostic 
9*e1aad660Sbostic #define ERROR(string)		yyerror(string); goto errorfix
10*e1aad660Sbostic 
11*e1aad660Sbostic #define peekahead (*tokptr)
12*e1aad660Sbostic 
13*e1aad660Sbostic #define shift 			val = yylex()
14*e1aad660Sbostic #define advance 	shift
15*e1aad660Sbostic 
16*e1aad660Sbostic #define shiftover(token)	if (val != token) { \
17*e1aad660Sbostic 					shiftoerror(token); \
18*e1aad660Sbostic 					goto errorfix; \
19*e1aad660Sbostic 				} \
20*e1aad660Sbostic 				shift
21*e1aad660Sbostic 
22*e1aad660Sbostic #define advanceover 	shiftover
23*e1aad660Sbostic 
24*e1aad660Sbostic /*
25*e1aad660Sbostic  *	To speed up the expression processing, we class the input tokens
26*e1aad660Sbostic  *	into various sets.
27*e1aad660Sbostic  *
28*e1aad660Sbostic  *	We don't call the recursive descent expression analyzer if we can
29*e1aad660Sbostic  *	determine by looking at the next token after the first token in
30*e1aad660Sbostic  *	an expression that the expression is simple (name, integer or floating
31*e1aad660Sbostic  *	point value).  Expressions with operators are parsed using the recursive
32*e1aad660Sbostic  *	descent method.
33*e1aad660Sbostic  */
34*e1aad660Sbostic 
35*e1aad660Sbostic /*
36*e1aad660Sbostic  *	Functional forwards for expression utility routines
37*e1aad660Sbostic  */
38*e1aad660Sbostic struct	exp	*combine();
39*e1aad660Sbostic struct	exp	*boolterm();
40*e1aad660Sbostic struct	exp	*term();
41*e1aad660Sbostic struct	exp	*factor();
42*e1aad660Sbostic struct	exp	*yukkyexpr();
43*e1aad660Sbostic 
44*e1aad660Sbostic /*
45*e1aad660Sbostic  *	The set definitions
46*e1aad660Sbostic  */
47*e1aad660Sbostic 
48*e1aad660Sbostic extern	char	tokensets[(LASTTOKEN) - (FIRSTTOKEN) + 1];
49*e1aad660Sbostic 
50*e1aad660Sbostic #define	LINSTBEGIN	01	/*SEMI, NL, NAME*/
51*e1aad660Sbostic #define	EBEGOPS		02	/*LP, MINUS, TILDE*/
52*e1aad660Sbostic #define	YUKKYEXPRBEG	04	/*NAME, INSTn, INST0, REG, BFINT*/
53*e1aad660Sbostic #define	SAFEEXPRBEG	010	/*INT, FLTNUM*/
54*e1aad660Sbostic #define	ADDOPS		020	/*PLUS, MINUS*/
55*e1aad660Sbostic #define	BOOLOPS		040	/*IOR, XOR, AND*/
56*e1aad660Sbostic #define	MULOPS		0100	/*LSH, RSH, MUL, DIV, TILDE*/
57*e1aad660Sbostic 
58*e1aad660Sbostic #define	INTOKSET(val, set)	(tokensets[(val)] & (set) )
59*e1aad660Sbostic 
60*e1aad660Sbostic inttoktype	exprparse();
61*e1aad660Sbostic inttoktype	funnyreg();
62*e1aad660Sbostic inttoktype	yylex();
63*e1aad660Sbostic 
64*e1aad660Sbostic #define expr(xp, val) { \
65*e1aad660Sbostic 	if ( (!INTOKSET(val, EBEGOPS)) && (!INTOKSET(peekahead, ADDOPS+BOOLOPS+MULOPS))) { \
66*e1aad660Sbostic 		if (INTOKSET(val, YUKKYEXPRBEG)) xp = yukkyexpr(val, yylval); \
67*e1aad660Sbostic 		else xp = (struct exp *) yylval; \
68*e1aad660Sbostic 		shift; \
69*e1aad660Sbostic 	} else { \
70*e1aad660Sbostic 		val = exprparse(val, ptrloc1xp); \
71*e1aad660Sbostic 		xp = loc1xp; \
72*e1aad660Sbostic 	} \
73*e1aad660Sbostic     }
74*e1aad660Sbostic 
75*e1aad660Sbostic /*
76*e1aad660Sbostic  *	Registers can be either of the form r0...pc, or
77*e1aad660Sbostic  *	of the form % <expression>
78*e1aad660Sbostic  *	NOTE:	Reizers documentation on the assembler says that it
79*e1aad660Sbostic  *	can be of the form r0 + <expression>.. That's not true.
80*e1aad660Sbostic  *
81*e1aad660Sbostic  *	NOTE:	Reizer's yacc grammar would seem to allow an expression
82*e1aad660Sbostic  *	to be: (This is undocumented)
83*e1aad660Sbostic  *		a)	a register
84*e1aad660Sbostic  *		b)	an Instruction (INSTn or INST0)
85*e1aad660Sbostic  */
86*e1aad660Sbostic 
87*e1aad660Sbostic #define findreg(regno) \
88*e1aad660Sbostic 	if (val == REG) { \
89*e1aad660Sbostic 		regno = yylval; \
90*e1aad660Sbostic 		shift; \
91*e1aad660Sbostic 	} else \
92*e1aad660Sbostic 	if (val == REGOP) { \
93*e1aad660Sbostic 		shift;	/*over the REGOP*/ \
94*e1aad660Sbostic 		val = funnyreg(val, ptrregno); \
95*e1aad660Sbostic 	} \
96*e1aad660Sbostic 	else { ERROR ("register expected"); }
97