3 ms·
> The POSIX shell grammar is ridiculously complicated, and would require the use of a parser-generator to reasonably implement. Wat? Admittedly Bourne shell s
by ajross 12y ago
> The POSIX shell grammar is ridiculously complicated, and would require the use of a parser-generator to reasonably implement.
Wat? Admittedly Bourne shell syntax is ad-hoc, glitchy to implement and difficult to specify. But it's absolutely not something that requires a parser generator. It was always and remains a string replacement language without deep structure.
- kps 12y agoBourne shell syntax is inspired by Algol 68¹, of which Bourne was a fan — the shell itself² was written in a highly idiosyncratic dialect of C, using the preprocessor to provide an Algol68ish syntax for control structures: WHILE i-- DO t=trapcom[i]; IF t==0 ORF *t THEN clrsig(i); FI trapflg[i]=0; OD The parser³ is straightforward recursive-descent in 400 lines including comments & blanks (the whole shell is about 4000 lines of code). ¹ http://en.wikipedia.org/wiki/ALGOL_68 http://en.wikipedia.org/wiki/ALGOL_68 ² http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/... ³ http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/sh/cmd.c http://minnie.tuhs.org/cgi-bin/utree.pl?file=V7/usr/src/cmd/...