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