1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 17:35:35 +02:00

bug 156137 - Expression Evaluator does not handle %

This commit is contained in:
Andrew Niefer 2006-09-05 02:03:35 +00:00
parent 354a0a70da
commit 5c49412ff9
2 changed files with 18 additions and 4 deletions

View file

@ -2414,4 +2414,15 @@ public class Scanner2Test extends BaseScanner2Test
initializeScanner(buffer.toString(), ParserLanguage.CPP);
fullyTokenize();
}
public void testBug156137() throws Exception {
StringBuffer buffer = new StringBuffer();
buffer.append("#if (3 % 2 == 1) \n");
buffer.append("C \n");
buffer.append("#endif \n");
initializeScanner(buffer.toString());
validateIdentifier("C");
validateEOF();
}
}

View file

@ -382,7 +382,7 @@ abstract class BaseScanner implements IScanner {
private long multiplicativeExpression() throws EvalException {
long r1 = unaryExpression();
for (int t = LA(); t == tMULT || t == tDIV; t = LA()) {
for (int t = LA(); t == tMULT || t == tDIV || t == tMOD; t = LA()) {
int position = pos; // for IProblem /0 below, need position
// before
// consume()
@ -390,9 +390,12 @@ abstract class BaseScanner implements IScanner {
long r2 = unaryExpression();
if (t == tMULT)
r1 = r1 * r2;
else if (r2 != 0)// t == tDIV;
r1 = r1 / r2;
else {
else if (r2 != 0) {
if (t == tDIV)
r1 = r1 / r2;
else
r1 = r1 % r2; //tMOD
} else {
handleProblem(IProblem.SCANNER_DIVIDE_BY_ZERO, position);
throw new EvalException("Divide by 0 encountered"); //$NON-NLS-1$
}