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