insert implicit -a after primary before !

This commit is contained in:
Evan Gates 2015-02-20 17:51:04 -08:00 committed by sin
parent 639a74a537
commit 6abce61877

17
find.c
View File

@ -768,6 +768,7 @@ parse(int argc, char **argv)
char **arg; char **arg;
size_t ntok = 0; size_t ntok = 0;
int print = 1; int print = 1;
Tok and = { .u.oinfo = find_op("-a"), .type = AND };
/* convert argv to infix expression of Tok, inserting in *tok */ /* convert argv to infix expression of Tok, inserting in *tok */
for (arg = argv, tok = infix; *arg; arg++, tok++) { for (arg = argv, tok = infix; *arg; arg++, tok++) {
@ -786,9 +787,7 @@ parse(int argc, char **argv)
print = 0; print = 0;
if (lasttype == PRIM || lasttype == RPAR) { if (lasttype == PRIM || lasttype == RPAR) {
tok->u.oinfo = find_op("-a"); /* ew? */ *tok++ = and;
tok->type = AND;
tok++;
ntok++; ntok++;
} }
if (pri->getarg) { if (pri->getarg) {
@ -802,6 +801,10 @@ parse(int argc, char **argv)
} else if ((op = find_op(*arg))) { /* token is an operator */ } else if ((op = find_op(*arg))) { /* token is an operator */
if (lasttype == LPAR && op->type == RPAR) if (lasttype == LPAR && op->type == RPAR)
eprintf("empty parens\n"); eprintf("empty parens\n");
if (lasttype == PRIM && op->type == NOT) { /* need another implicit -a */
*tok++ = and;
ntok++;
}
tok->type = op->type; tok->type = op->type;
tok->u.oinfo = op; tok->u.oinfo = op;
@ -866,11 +869,9 @@ parse(int argc, char **argv)
out->type = PRIM; out->type = PRIM;
out++; out++;
} }
if (print == 2) { if (print == 2)
out->u.oinfo = find_op("-a"); *out++ = and;
out->type = AND;
out++;
}
out->type = END; out->type = END;
/* rpn now holds all operators and arguments in reverse polish notation /* rpn now holds all operators and arguments in reverse polish notation