Commit | Line | Data |
---|---|---|
f70ab843 | 1 | /* |
bcf1365c DF |
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) %G% | |
f70ab843 | 7 | */ |
bcf1365c | 8 | |
ac675cfd BJ |
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) { \ | |
825ccb47 | 21 | shiftoerror(token); \ |
ac675cfd BJ |
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 | ||
451260e7 | 54 | #define LINSTBEGIN 01 /*SEMI, NL, NAME*/ |
ac675cfd | 55 | #define EBEGOPS 02 /*LP, MINUS, TILDE*/ |
451260e7 | 56 | #define YUKKYEXPRBEG 04 /*NAME, INSTn, INST0, REG, BFINT*/ |
ac675cfd | 57 | #define SAFEEXPRBEG 010 /*INT, FLTNUM*/ |
451260e7 | 58 | #define ADDOPS 020 /*PLUS, MINUS*/ |
ac675cfd | 59 | #define BOOLOPS 040 /*IOR, XOR, AND*/ |
451260e7 | 60 | #define MULOPS 0100 /*LSH, RSH, MUL, DIV, TILDE*/ |
ac675cfd BJ |
61 | |
62 | #define INTOKSET(val, set) (tokensets[(val)] & (set) ) | |
63 | ||
f70ab843 RH |
64 | inttoktype exprparse(); |
65 | inttoktype funnyreg(); | |
66 | inttoktype yylex(); | |
67 | ||
ac675cfd BJ |
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"); } |