-/* $OpenBSD: syn.c,v 1.33 2015/09/18 07:28:24 nicm Exp $ */
+/* $OpenBSD: syn.c,v 1.34 2015/10/06 21:21:39 nicm Exp $ */
/*
* shell parser (C version)
static int reject; /* token(cf) gets symbol again */
static int symbol; /* yylex value */
-#define REJECT (reject = 1)
-#define ACCEPT (reject = 0)
#define token(cf) \
- ((reject) ? (ACCEPT, symbol) : (symbol = yylex(cf)))
+ ((reject) ? (reject = false, symbol) : (symbol = yylex(cf)))
#define tpeek(cf) \
- ((reject) ? (symbol) : (REJECT, symbol = yylex(cf)))
+ ((reject) ? (symbol) : (reject = true, symbol = yylex(cf)))
static void
yyparse(void)
{
int c;
- ACCEPT;
+ reject = false;
outtree = c_list(source->type == SSTRING);
c = tpeek(0);
else
tl = tl->right = block(TPIPE, tl->right, p, NOWORDS);
}
- REJECT;
+ reject = true;
}
return (t);
}
syntaxerr(NULL);
t = block(c == LOGAND? TAND: TOR, t, p, NOWORDS);
}
- REJECT;
+ reject = true;
}
return (t);
}
if (!have_sep)
break;
}
- REJECT;
+ reject = true;
return t;
}
if (tpeek(cf) != REDIR)
return NULL;
- ACCEPT;
+ reject = false;
iop = yylval.iop;
ishere = (iop->flag&IOTYPE) == IOHERE;
musthave(LWORD, ishere ? HEREDELIM : 0);
syniocf = KEYWORD|ALIAS;
switch (c = token(cf|KEYWORD|ALIAS|VARASN)) {
default:
- REJECT;
+ reject = true;
afree(iops, ATEMP);
XPfree(args);
XPfree(vars);
case LWORD:
case REDIR:
- REJECT;
+ reject = true;
syniocf &= ~(KEYWORD|ALIAS);
t = newtp(TCOM);
t->lineno = source->line;
break;
case LWORD:
- ACCEPT;
+ reject = false;
/* the iopn == 0 and XPsize(vars) == 0 are
* dubious but at&t ksh acts this way
*/
*/
afree(t, ATEMP);
if (XPsize(args) == 0 && XPsize(vars) == 0) {
- ACCEPT;
+ reject = false;
goto Subshell;
}
/* Must be a function */
if (iopn != 0 || XPsize(args) != 1 ||
XPsize(vars) != 0)
syntaxerr(NULL);
- ACCEPT;
+ reject = false;
/*(*/
musthave(')', 0);
t = function_body(XPptrv(args)[0], false);
/* Leave KEYWORD in syniocf (allow if (( 1 )) then ...) */
t = newtp(TCOM);
t->lineno = source->line;
- ACCEPT;
+ reject = false;
XPput(args, wdcopy(let_cmd, ATEMP));
musthave(LWORD,LETEXPR);
XPput(args, yylval.cp);
case DBRACKET: /* [[ .. ]] */
/* Leave KEYWORD in syniocf (allow if [[ -n 1 ]] then ...) */
t = newtp(TDBRACKET);
- ACCEPT;
+ reject = false;
{
Test_env te;
return (t);
default:
- REJECT;
+ reject = true;
}
return NULL;
}
t = newtp(TPAT);
c = token(CONTIN|KEYWORD); /* no ALIAS here */
if (c != '(')
- REJECT;
+ reject = true;
do {
musthave(LWORD, 0);
XPput(ptns, yylval.cp);
} while ((c = token(0)) == '|');
- REJECT;
+ reject = true;
XPput(ptns, NULL);
t->vars = (char **) XPclose(ptns);
musthave(')', 0);
*/
if (ksh_func) {
musthave('{', CONTIN|KEYWORD|ALIAS); /* } */
- REJECT;
+ reject = true;
}
old_func_parse = e->flags & EF_FUNC_PARSE;
/* Posix does not do alias expansion here... */
if ((c = token(CONTIN|KEYWORD|ALIAS)) != IN) {
if (c != ';') /* non-POSIX, but at&t ksh accepts a ; here */
- REJECT;
+ reject = true;
return NULL;
}
while ((c = token(0)) == LWORD)
if (!what)
what = "unexpected";
- REJECT;
+ reject = true;
c = token(0);
Again:
switch (c) {
} else /* meta == TM_END */
ret = uqword && strcmp(yylval.cp, db_close) == 0;
if (ret) {
- ACCEPT;
+ reject = false;
if (meta != TM_END) {
if (!save)
save = wdcopy(dbtest_tokens[(int) meta], ATEMP);
if (c != LWORD)
return NULL;
- ACCEPT;
+ reject = false;
XPput(*te->pos.av, yylval.cp);
return null;
te->flags |= TEF_ERROR;
if (offset < 0) {
- REJECT;
+ reject = true;
/* Kludgy to say the least... */
symbol = LWORD;
yylval.cp = *(XPptrv(*te->pos.av) + XPsize(*te->pos.av) +