From cccd60f37a31113a42372672670ce2a2bc529684 Mon Sep 17 00:00:00 2001 From: Shevek Date: Thu, 11 Sep 2014 12:20:05 -0700 Subject: Handle conditionals in preprocessor statements. --- src/main/java/org/anarres/cpp/Preprocessor.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'src/main/java/org/anarres/cpp/Preprocessor.java') diff --git a/src/main/java/org/anarres/cpp/Preprocessor.java b/src/main/java/org/anarres/cpp/Preprocessor.java index 0d14b53..192ac45 100644 --- a/src/main/java/org/anarres/cpp/Preprocessor.java +++ b/src/main/java/org/anarres/cpp/Preprocessor.java @@ -1514,7 +1514,7 @@ public class Preprocessor implements Closeable { tok = expr_token(); if (tok.getType() != ')') { expr_untoken(tok); - error(tok, "missing ) in expression"); + error(tok, "Missing ) in expression. Got " + tok.getText()); return 0; } break; @@ -1628,8 +1628,17 @@ public class Preprocessor implements Closeable { lhs = (lhs != 0) || (rhs != 0) ? 1 : 0; break; - case '?': - /* XXX Handle this? */ + case '?': { + tok = expr_token(); + if (tok.getType() != ':') { + expr_untoken(tok); + error(tok, "Missing : in conditional expression. Got " + tok.getText()); + return 0; + } + long falseResult = expr(0); + lhs = (lhs != 0) ? rhs : falseResult; + } + break; default: error(op, -- cgit v1.2.3