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