MOHAWK: Fix associativity of LBCode operators.

This commit is contained in:
Alyssa Milburn 2011-07-03 14:18:17 +02:00
parent dd7b1399f3
commit d7f50b925e

View file

@ -277,8 +277,7 @@ LBValue LBCode::runCode(byte terminator) {
void LBCode::parseStatement() { void LBCode::parseStatement() {
parseComparisons(); parseComparisons();
if (_currToken != kTokenAnd && _currToken != kTokenOr) while (_currToken == kTokenAnd || _currToken == kTokenOr) {
return;
byte op = _currToken; byte op = _currToken;
if (op == kTokenAnd) if (op == kTokenAnd)
debugN(" && "); debugN(" && ");
@ -299,6 +298,7 @@ void LBCode::parseStatement() {
debugN(" [--> %s]", result ? "true" : "false"); debugN(" [--> %s]", result ? "true" : "false");
_stack.push(result); _stack.push(result);
} }
}
void LBCode::parseComparisons() { void LBCode::parseComparisons() {
parseConcat(); parseConcat();
@ -365,9 +365,7 @@ void LBCode::parseComparisons() {
void LBCode::parseConcat() { void LBCode::parseConcat() {
parseArithmetic1(); parseArithmetic1();
if (_currToken != kTokenConcat) while (_currToken == kTokenConcat) {
return;
debugN(" & "); debugN(" & ");
nextToken(); nextToken();
parseArithmetic1(); parseArithmetic1();
@ -378,13 +376,12 @@ void LBCode::parseConcat() {
debugN(" [--> \"%s\"]", result.c_str()); debugN(" [--> \"%s\"]", result.c_str());
_stack.push(result); _stack.push(result);
} }
}
void LBCode::parseArithmetic1() { void LBCode::parseArithmetic1() {
parseArithmetic2(); parseArithmetic2();
if (_currToken != kTokenMinus && _currToken != kTokenPlus) while (_currToken == kTokenMinus || _currToken == kTokenPlus) {
return;
byte op = _currToken; byte op = _currToken;
if (op == kTokenMinus) if (op == kTokenMinus)
debugN(" - "); debugN(" - ");
@ -402,8 +399,10 @@ void LBCode::parseArithmetic1() {
result = val1.toInt() - val2.toInt(); result = val1.toInt() - val2.toInt();
else else
result = val1.toInt() + val2.toInt(); result = val1.toInt() + val2.toInt();
debugN(" [--> %d]", result.toInt());
_stack.push(result); _stack.push(result);
} }
}
void LBCode::parseArithmetic2() { void LBCode::parseArithmetic2() {
// FIXME: other math operators // FIXME: other math operators