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