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;
}
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;
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;
//
// 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)