1602Sbill /* 2*19826Sdist * Copyright (c) 1982 Regents of the University of California. 3*19826Sdist * All rights reserved. The Berkeley software License Agreement 4*19826Sdist * specifies the terms and conditions for redistribution. 5*19826Sdist * 6*19826Sdist * @(#)asexpr.h 5.1 (Berkeley) 04/30/85 75830Srrh */ 8*19826Sdist 95830Srrh /* 10602Sbill * Definitions to parse tokens 11602Sbill */ 12602Sbill 13602Sbill #define ERROR(string) yyerror(string); goto errorfix 14602Sbill 15602Sbill #define peekahead (*tokptr) 16602Sbill 17602Sbill #define shift val = yylex() 18602Sbill #define advance shift 19602Sbill 20602Sbill #define shiftover(token) if (val != token) { \ 2112946Srrh shiftoerror(token); \ 22602Sbill goto errorfix; \ 23602Sbill } \ 24602Sbill shift 25602Sbill 26602Sbill #define advanceover shiftover 27602Sbill 28602Sbill /* 29602Sbill * To speed up the expression processing, we class the input tokens 30602Sbill * into various sets. 31602Sbill * 32602Sbill * We don't call the recursive descent expression analyzer if we can 33602Sbill * determine by looking at the next token after the first token in 34602Sbill * an expression that the expression is simple (name, integer or floating 35602Sbill * point value). Expressions with operators are parsed using the recursive 36602Sbill * descent method. 37602Sbill */ 38602Sbill 39602Sbill /* 40602Sbill * Functional forwards for expression utility routines 41602Sbill */ 42602Sbill struct exp *combine(); 43602Sbill struct exp *boolterm(); 44602Sbill struct exp *term(); 45602Sbill struct exp *factor(); 46602Sbill struct exp *yukkyexpr(); 47602Sbill 48602Sbill /* 49602Sbill * The set definitions 50602Sbill */ 51602Sbill 52602Sbill extern char tokensets[(LASTTOKEN) - (FIRSTTOKEN) + 1]; 53602Sbill 54635Shenry #define LINSTBEGIN 01 /*SEMI, NL, NAME*/ 55602Sbill #define EBEGOPS 02 /*LP, MINUS, TILDE*/ 56635Shenry #define YUKKYEXPRBEG 04 /*NAME, INSTn, INST0, REG, BFINT*/ 57602Sbill #define SAFEEXPRBEG 010 /*INT, FLTNUM*/ 58635Shenry #define ADDOPS 020 /*PLUS, MINUS*/ 59602Sbill #define BOOLOPS 040 /*IOR, XOR, AND*/ 60635Shenry #define MULOPS 0100 /*LSH, RSH, MUL, DIV, TILDE*/ 61602Sbill 62602Sbill #define INTOKSET(val, set) (tokensets[(val)] & (set) ) 63602Sbill 645830Srrh inttoktype exprparse(); 655830Srrh inttoktype funnyreg(); 665830Srrh inttoktype yylex(); 675830Srrh 68602Sbill #define expr(xp, val) { \ 69602Sbill if ( (!INTOKSET(val, EBEGOPS)) && (!INTOKSET(peekahead, ADDOPS+BOOLOPS+MULOPS))) { \ 70602Sbill if (INTOKSET(val, YUKKYEXPRBEG)) xp = yukkyexpr(val, yylval); \ 71602Sbill else xp = (struct exp *) yylval; \ 72602Sbill shift; \ 73602Sbill } else { \ 74602Sbill val = exprparse(val, ptrloc1xp); \ 75602Sbill xp = loc1xp; \ 76602Sbill } \ 77602Sbill } 78602Sbill 79602Sbill /* 80602Sbill * Registers can be either of the form r0...pc, or 81602Sbill * of the form % <expression> 82602Sbill * NOTE: Reizers documentation on the assembler says that it 83602Sbill * can be of the form r0 + <expression>.. That's not true. 84602Sbill * 85602Sbill * NOTE: Reizer's yacc grammar would seem to allow an expression 86602Sbill * to be: (This is undocumented) 87602Sbill * a) a register 88602Sbill * b) an Instruction (INSTn or INST0) 89602Sbill */ 90602Sbill 91602Sbill #define findreg(regno) \ 92602Sbill if (val == REG) { \ 93602Sbill regno = yylval; \ 94602Sbill shift; \ 95602Sbill } else \ 96602Sbill if (val == REGOP) { \ 97602Sbill shift; /*over the REGOP*/ \ 98602Sbill val = funnyreg(val, ptrregno); \ 99602Sbill } \ 100602Sbill else { ERROR ("register expected"); } 101