X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=rmac;a=blobdiff_plain;f=expr.c;h=dc0e22bf90b88485ee2872d3dccdc7d35ac4313d;hp=4525754efe1f5296278dd670ea1d918e6995c0de;hb=HEAD;hpb=c77f5e305ec19e7d445bdd138187ca7458ba5a16 diff --git a/expr.c b/expr.c index 4525754..e597257 100644 --- a/expr.c +++ b/expr.c @@ -93,24 +93,97 @@ void InitExpression(void) symbolNum = 0; } +extern int correctMathRules; +int xor(void); +int and(void); +int rel(void); +int shift(void); +int sum(void); +int product(void); + // -// Binary operators (all the same precedence) +// Binary operators (all the same precedence, +// except if -4 is passed to the command line) // +#define precedence(HIERARCHY_HIGHER, HIERARCHY_CURRENT) \ +do \ +{ \ + if (HIERARCHY_HIGHER() != OK) \ + return ERROR; \ + while (tokenClass[*tok] == HIERARCHY_CURRENT) \ + { \ + TOKEN t = *tok++; \ + if (HIERARCHY_HIGHER() != OK) \ + return ERROR; \ + *evalTokenBuffer.u32++ = t; \ + } \ +}while (0) + int expr0(void) { - if (expr1() != OK) - return ERROR; - - while (tokenClass[*tok] >= MULT) + if ( correctMathRules == 0 ) { - TOKEN t = *tok++; - if (expr1() != OK) return ERROR; - *evalTokenBuffer.u32++ = t; + while (tokenClass[*tok] >= MULT) + { + TOKEN t = *tok++; + + if (expr1() != OK) + return ERROR; + + *evalTokenBuffer.u32++ = t; + } } + else + { + // The order of C precedence (lower to higher): + // bitwise XOR ^ + // bitwise OR | + // bitwise AND & + // relational = < <= >= > != + // shifts << >> + // sum + - + // product * / + precedence(xor, OR); + } + return OK; +} + +int xor(void) +{ + precedence(and, XOR); + return OK; +} + +int and(void) +{ + precedence(rel, AND); + return OK; +} + +int rel(void) +{ + precedence(shift, REL); + return OK; +} + +int shift(void) +{ + precedence(sum, SHIFT); + return OK; +} +int sum(void) +{ + precedence(product, ADD); + return OK; +} + +int product(void) +{ + precedence(expr1, MULT); return OK; } @@ -189,7 +262,7 @@ int expr1(void) goto allright; } - return error("cannot open: \"%s\"", string[tok[1]]); + return error("cannot open: \"%s\"", string[*tok]); } allright: @@ -290,16 +363,6 @@ int expr2(void) if (sy == NULL) sy = NewSymbol(p, LABEL, j); - // Check register bank usage - if (sy->sattre & EQUATEDREG) - { - if ((regbank == BANK_0) && (sy->sattre & BANK_1) && !altbankok) - warn("equated symbol \'%s\' cannot be used in register bank 0", sy->sname); - - if ((regbank == BANK_1) && (sy->sattre & BANK_0) && !altbankok) - warn("equated symbol \'%s\' cannot be used in register bank 1", sy->sname); - } - *evalTokenBuffer.u32++ = SYMBOL; *evalTokenBuffer.u32++ = symbolNum; symbolPtr[symbolNum] = sy; @@ -463,18 +526,6 @@ int expr(TOKEN * otk, uint64_t * a_value, WORD * a_attr, SYM ** a_esym) if ((symbol->sattre & UNDEF_EQUR) && !riscImmTokenSeen) { error("undefined register equate '%s'", symbol->sname); -//if we return right away, it returns some spurious errors... -// return ERROR; - } - - // Check register bank usage - if (symbol->sattre & EQUATEDREG) - { - if ((regbank == BANK_0) && (symbol->sattre & BANK_1) && !altbankok) - warn("equated symbol '%s' cannot be used in register bank 0", symbol->sname); - - if ((regbank == BANK_1) && (symbol->sattre & BANK_0) && !altbankok) - warn("equated symbol '%s' cannot be used in register bank 1", symbol->sname); } *evalTokenBuffer.u32++ = SYMBOL; @@ -534,7 +585,7 @@ be converted from a linked list into an array). // // Evaluate expression. // If the expression involves only ONE external symbol, the expression is -// UNDEFINED, but it's value includes everything but the symbol value, and +// UNDEFINED, but its value includes everything but the symbol value, and // 'a_esym' is set to the external symbol. // int evexpr(TOKEN * _tk, uint64_t * a_value, WORD * a_attr, SYM ** a_esym)