Blob
- Date:
- Message:
- rc: add recursive descent parser The old yacc-based parser is available with the -Y flag, which will probably be removed at some point. The new -D flag dumps a parse tree of the input, without executing it. This allows comparing the output of rc -D and rc -DY on different scripts to see that the two parsers behave the same. The rc paper ends by saying: It is remarkable that in the four most recent editions of the UNIX system programmer’s manual the Bourne shell grammar described in the manual page does not admit the command who|wc. This is surely an oversight, but it suggests something darker: nobody really knows what the Bourne shell’s grammar is. Even examination of the source code is little help. The parser is implemented by recursive descent, but the routines corresponding to the syntactic categories all have a flag argument that subtly changes their operation depending on the context. Rc’s parser is implemented using yacc, so I can say precisely what the grammar is. The new recursive descent parser here has no such flags. It is a straightforward translation of the yacc. The new parser will make it easier to handle free carats in more generality as well as potentially allow the use of unquoted = as a word character. Going through this exercise has highlighted a few dark corners here as well. For example, I was surprised to find that x >f | y >f x | y are different commands (the latter redirects y's output). It is similarly surprising that a=b x | y sets a during the execution of y. It is also a bit counter-intuitive x | y | z x | if(c) y | z are not both 3-phase pipelines. These are certainly not things we should change, but they are not entirely obvious from the man page description, undercutting the quoted claim a bit. On the other hand, who | wc is clearly accepted by the grammar in the manual page, and the new parser still handles that test case.
- Actions:
- History | Blame | Raw File
1 void Abort(void);2 void Closedir(int);3 int Creat(char*);4 int Dup(int, int);5 int Dup1(int);6 int Eintr(void);7 int Executable(char*);8 void Execute(word*, word*);9 void Exit(char*);10 int ForkExecute(char*, char**, int, int, int);11 int Globsize(char*);12 int Isatty(int);13 void Memcpy(char*, char*, long);14 void Noerror(void);15 int Opendir(char*);16 long Read(int, char*, long);17 int Readdir(int, char*, int);18 long Seek(int, long, long);19 void Trapinit(void);20 void Unlink(char*);21 void Updenv(void);22 void Vinit(void);23 int Waitfor(int, int);24 long Write(int, char*, long);25 void addwaitpid(int);26 int advance(void);27 int back(int);28 void cleanhere(char*);29 void codefree(code*);30 int compile(tree*);31 char * list2str(word*);32 int count(word*);33 void deglob(char*);34 void delwaitpid(int);35 void dotrap(void);36 void freenodes(void);37 void freewords(word*);38 void globlist(void);39 int havewaitpid(int);40 int idchr(int);41 void inttoascii(char*, long);42 void kinit(void);43 int mapfd(int);44 int match(char*, char*, int);45 int matchfn(char*, char*);46 char** mkargv(word*);47 void clearwaitpids(void);48 void panic(char*, int);49 void pathinit(void);50 void poplist(void);51 void popword(void);52 void pprompt(void);53 void pushlist(void);54 void pushredir(int, int, int);55 void pushword(char*);56 void readhere(void);57 word* searchpath(char*);58 void setstatus(char*);59 void setvar(char*, word*);60 void skipnl(void);61 void start(code*, int, var*);62 int truestatus(void);63 void usage(char*);64 int wordchr(int);65 void yyerror(char*);66 int yylex(void);67 int yyparse(void);68 int parse(void);