From 91c673b37782d4cd90e5cf9a8e4491723e6c04bf Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Fri, 19 Jun 2020 14:44:54 -0700 Subject: fix: many small bug fixes with parser and lexer --- sys/cmd/rc/lex.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) (limited to 'sys/cmd/rc/lex.c') diff --git a/sys/cmd/rc/lex.c b/sys/cmd/rc/lex.c index 1415f5c..8b4cdec 100644 --- a/sys/cmd/rc/lex.c +++ b/sys/cmd/rc/lex.c @@ -35,7 +35,7 @@ static uchar nwordc[256] = }; int -wordchr(char c) +wordchr(int c) { return !nwordc[c] && c!=EOF; } @@ -111,9 +111,9 @@ lookahead(void) if(nextc != EOF) return nextc; - if(shell->cmd.eof) return EOF; + if(doprompt) prompt(); @@ -248,6 +248,8 @@ rcerror(char *fmt, ...) lastword = lastdol = 0; while (lastc != '\n' && lastc != EOF) advance(); + /* for debugging only */ + abort(); } /* word is only modified in the event of a lexed word */ @@ -267,10 +269,10 @@ lex(Tree **node) c = lookahead(); if(c=='('){ advance(); - return Alparen; + return Tlparen; } if(quotechr(c)) - return Acarot; + return Tcarot; } skipws(); @@ -281,37 +283,37 @@ lex(Tree **node) case '$': lastdol = 1; if(nextis('#')) - return Acount; + return Tcount; if (nextis('"')) - return Aquote; - return Adol; + return Tquote; + return Tdol; case '&': lastdol = 0; if(nextis('&')) - return Aandand; - return Aand; + return Tandand; + return Tand; case '!': - return Kbang; + return Tbang; case '@': - return Ksubsh; + return Tsubshell; case '~': - return Ktwiddle; + return Ttwiddle; case '|': lastdol = 0; if(nextis('|')){ skipnl(); - return Aoror; + return Toror; } (*node) = newtree(); - (*node)->type = Apipe; + (*node)->type = Tpipe; (*node)->redir.fd[0] = 0; (*node)->redir.fd[1] = 1; goto redir; case '>': (*node) = newtree(); - (*node)->type = Aredir; + (*node)->type = Tredir; if (nextis(c)) (*node)->redir.type = Rappend; else @@ -320,7 +322,7 @@ lex(Tree **node) goto redir; case '<': (*node) = newtree(); - (*node)->type = Aredir; + (*node)->type = Tredir; if(nextis(c)) (*node)->redir.type = Rhere; else if(nextis('>')) @@ -344,8 +346,8 @@ lex(Tree **node) } while('0'<=c && c<='9'); if(c == '=') { - if((*node)->type == Aredir) - (*node)->type = Adup; + if((*node)->type == Tredir) + (*node)->type = Tdup; c = advance(); if('0'<=c && c<='9') { (*node)->redir.type = Rdupfd; @@ -356,16 +358,16 @@ lex(Tree **node) c = advance(); } while('0'<=c && c<='9'); } else { - if((*node)->type == Apipe) + if((*node)->type == Tpipe) goto redirerr; (*node)->redir.type = Rclose; } } if (c != ']' - ||(*node)->type==Adup && ((*node)->redir.type==Rhere || (*node)->redir.type==Rappend)) + ||(*node)->type==Tdup && ((*node)->redir.type==Rhere || (*node)->redir.type==Rappend)) goto redirerr; } - if ((c = ((*node)->type)) == Apipe) + if ((c = ((*node)->type)) == Tpipe) skipnl(); return c; @@ -386,7 +388,7 @@ lex(Tree **node) *w = 0; *node = wordnode(buf); (*node)->quoted = 1; - return Aword; + return Tword; } if (!wordchr(c)) { lastdol = 0; @@ -405,7 +407,7 @@ lex(Tree **node) if ((c = kwlookup(buf)) == -1) { (*node) = wordnode(buf); - (*node)->type = c = Aword; + (*node)->type = c = Tword; (*node)->quoted = 0; lastword = 1; } -- cgit v1.2.1