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