bool PPUnaryExpression(PPScanner scan) { bool not = false; PPToken ppt = scan.peek(); while (ppt.getKind() == PPToken.eNot) { scan.next(); not = !not; ppt = scan.peek(); } return not ^ PPPrimaryExpression(scan); }
bool PPPrimaryExpression(PPScanner scan) { bool e = false; PPToken ppt = scan.next(); if (ppt.getKind() == PPToken.eTrue) { e = true; } else if (ppt.getKind() == PPToken.eFalse) { e = false; } else if (ppt.getKind() == PPToken.eLPar) { e = PPOrExpression(scan); ppt = scan.next(); if (ppt.getKind() != PPToken.eRPar) { Error("Corrupt preprocessor directive (')' expected), found: " + ppt.toString()); } } else if (ppt.getKind() == PPToken.eIdent) { e = ccs.Contains(ppt.getValue()); } else { Error("Corrupt preprocessor directive, unknown start of PPPrimaryExpression: " + ppt.toString()); } return e; }
// preprocessor expression parser start bool PPOrExpression(PPScanner scan) { bool e1, e2; e1 = PPAndExpression(scan); while (scan.peek().getKind() == PPToken.eOr) { scan.next(); e2 = PPAndExpression(scan); e1 = e1 || e2; } return e1; }
bool PPEqualityExpression(PPScanner scan) { bool e1, e2; e1 = PPUnaryExpression(scan); int tk = scan.peek().getKind(); while (tk == PPToken.eEQ || tk == PPToken.eNE) { scan.next(); e2 = PPUnaryExpression(scan); if (tk == PPToken.eEQ) { e1 = e1 == e2; } else { // tk == PPToken.eNE e1 = e1 != e2; } tk = scan.peek().getKind(); } return e1; }
bool PPAndExpression(PPScanner scan) { bool e1, e2; e1 = PPEqualityExpression(scan); while (scan.peek().getKind() == PPToken.eAnd) { scan.next(); e2 = PPEqualityExpression(scan); e1 = e1 && e2; } return e1; }
// preprocessor expression parser end // ccs.Contains(RemPPDirective(symbol)) bool IsCCS(string symbol) { // skip "#" "if", "#" "elif" PPScanner scan = new PPScanner(symbol); PPToken ppt = scan.next(); if (ppt.getKind() != PPToken.eHash) { Error("Corrupt preprocessor directive, # expected, but found: " + ppt.toString()); } ppt = scan.next(); if (ppt.getKind() != PPToken.eIdent) { Error("Corrupt preprocessor directive, identifier expected, but found: " + ppt.toString()); } return PPOrExpression(scan); }