Index: parse.c
===================================================================
--- parse.c	(revision 552)
+++ parse.c	(working copy)
@@ -5808,10 +5808,8 @@
                 continue;
 
             case TOKnot:                // could be !in
-printf("test1\n");
                 if (peekNext() == TOKin)
                 {
-printf("test2\n");
                     nextToken();
                     nextToken();
                     e2 = parseShiftExp();
@@ -5900,6 +5898,11 @@
 
     switch (op)
     {
+        case TOKxor:
+        case TOKor:
+        case TOKand:
+            e = parseOrExp(e);
+            break;
         case TOKequal:
         case TOKnotequal:
             nextToken();
@@ -5961,11 +5964,16 @@
         default:
             break;
     }
+    // Generate a nice error message if mixing bitwise and comparison operators
+    if ( token.value == TOKxor || token.value == TOKor
+        || token.value == TOKand )
+            error("Ambiguous bitwise comparison expression. "
+            "Did you forget parentheses?");        
     return e;
 }
 
-Expression *Parser::parseAndExp()
-{   Expression *e;
+Expression *Parser::parseAndExp(Expression *e)
+{
     Expression *e2;
     Loc loc = this->loc;
 
@@ -5982,43 +5990,63 @@
     }
     else
     {
-        e = parseCmpExp();
+        if (!e)
+            e = parseShiftExp();
         while (token.value == TOKand)
         {
             nextToken();
-            e2 = parseCmpExp();
+            e2 = parseShiftExp();
             e = new AndExp(loc,e,e2);
             loc = this->loc;
         }
+        // Generate a nice error message if mixing bitwise and comparison operators
+        bool isAmbiguous =
+        (token.value == TOKequal || token.value == TOKnotequal
+            || token.value == TOKis || token.value == TOKin
+            || token.value == TOKlt || token.value == TOKle
+            || token.value == TOKgt || token.value == TOKge
+            || token.value == TOKunord || token.value == TOKue
+            || token.value == TOKlg || token.value == TOKleg
+            || token.value == TOKul || token.value == TOKule
+            || token.value == TOKug || token.value == TOKuge );
+        Token *t;
+        if (token.value == TOKnot)
+        {
+            t = peek(&token);
+            isAmbiguous = (t->value == TOKin || t->value == TOKis);
+        }
+        if (isAmbiguous)
+            error("Ambiguous bitwise comparison expression. "
+            "Did you forget parentheses?");        
     }
     return e;
 }
 
-Expression *Parser::parseXorExp()
-{   Expression *e;
+Expression *Parser::parseXorExp(Expression *e)
+{
     Expression *e2;
     Loc loc = this->loc;
 
-    e = parseAndExp();
+    e = parseAndExp(e);
     while (token.value == TOKxor)
     {
         nextToken();
-        e2 = parseAndExp();
+        e2 = parseAndExp(NULL);
         e = new XorExp(loc, e, e2);
     }
     return e;
 }
 
-Expression *Parser::parseOrExp()
-{   Expression *e;
+Expression *Parser::parseOrExp(Expression *e)
+{
     Expression *e2;
     Loc loc = this->loc;
 
-    e = parseXorExp();
+    e = parseXorExp(e);
     while (token.value == TOKor)
     {
         nextToken();
-        e2 = parseXorExp();
+        e2 = parseXorExp(NULL);
         e = new OrExp(loc, e, e2);
     }
     return e;
@@ -6029,11 +6057,11 @@
     Expression *e2;
     Loc loc = this->loc;
 
-    e = parseOrExp();
+    e = parseCmpExp();
     while (token.value == TOKandand)
     {
         nextToken();
-        e2 = parseOrExp();
+        e2 = parseCmpExp();
         e = new AndAndExp(loc, e, e2);
     }
     return e;
Index: parse.h
===================================================================
--- parse.h	(revision 552)
+++ parse.h	(working copy)
@@ -134,9 +134,9 @@
     Expression *parseRelExp();
     Expression *parseEqualExp();
     Expression *parseCmpExp();
-    Expression *parseAndExp();
-    Expression *parseXorExp();
-    Expression *parseOrExp();
+    Expression *parseAndExp(Expression *e);
+    Expression *parseXorExp(Expression *e);
+    Expression *parseOrExp(Expression *e);
     Expression *parseAndAndExp();
     Expression *parseOrOrExp();
     Expression *parseCondExp();
