--- b.c.orig 2011-06-11 09:13:52.000000000 -0500 +++ b.c 2014-06-24 16:29:53.000000000 -0500 @@ -68,6 +68,7 @@ static int setcnt; static int poscnt; +static int subexprlvl; /* incremented in parenthesized subexpression */ char *patbeg; int patlen; @@ -657,13 +658,19 @@ case '$': rtok = relex(); return (unary(op2(CHAR, NIL, NIL))); + case ')': + np = op2(CHAR, NIL, itonp(')')); + rtok = relex(); + return (unary(np)); case '(': rtok = relex(); if (rtok == ')') { /* special pleading for () */ rtok = relex(); return unary(op2(CCL, NIL, (Node *) tostring(""))); } + subexprlvl++; np = regexp(); + subexprlvl--; if (rtok == ')') { rtok = relex(); return (unary(np)); @@ -681,6 +688,9 @@ switch (rtok) { case CHAR: case DOT: case ALL: case EMPTYRE: case CCL: case NCCL: case '$': case '(': return (concat(op2(CAT, np, primary()))); + case ')': + if (!subexprlvl) + return (concat(op2(CAT, np, primary()))); } return (np); }