plan9port/src
Russ Cox 47d4646eeb 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.
2020-05-04 23:41:15 -04:00
..
cmd rc: add recursive descent parser 2020-05-04 23:41:15 -04:00
lib9 malloc: remove locking 2020-01-16 16:54:19 +00:00
lib9p Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
lib9pclient Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libacme Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libauth Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libauthsrv Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libavl venti: import changes from plan 9 2011-06-02 09:33:56 -04:00
libbin add portdate 2004-12-26 23:23:57 +00:00
libbio Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libcomplete add portdate 2004-12-26 23:23:57 +00:00
libdisk Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libdiskfs Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libdraw libdraw: send hangup to process when window is lost 2020-01-14 18:05:51 -05:00
libflate make flate crc32 work when ulong is 64 bits 2010-02-07 16:51:28 -08:00
libframe Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libgeometry Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libhtml Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libhttpd Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libip Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libmach libmach: Fix type errors in FreeBSD.c 2020-01-15 16:51:14 +00:00
libmemdraw Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libmemlayer separate out 2006-06-25 18:58:06 +00:00
libmp Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libmux Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libndb Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libplumb Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libregexp Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libsec Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libString Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libsunrpc Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
libthread libthread: fix ARM build by renaming file 2020-02-11 06:58:26 -05:00
libventi Trivial changes: whitespace and modes. 2020-01-10 14:54:30 +00:00
make2mk make -> mk 2003-11-23 18:10:54 +00:00
mk2make make -> mk 2003-11-23 18:10:54 +00:00
mkcommon remove rule - breaks mac 2005-05-02 03:11:29 +00:00
mkdirs add tracing cd prints 2005-11-26 15:39:32 +00:00
mkenv src: mv ../buildEnvironmentVariables mkhdr 2020-01-09 20:08:10 -05:00
mkfile mkfile, mkmk.sh: update for new asm-free getcallerpc 2020-01-09 19:57:56 -05:00
mkhdr src: mv ../buildEnvironmentVariables mkhdr 2020-01-09 20:08:10 -05:00
mklib build: use ar s flag to avoid ranlib 2007-11-05 11:27:14 -05:00
mkmany good bye SHORTLIB 2005-01-04 22:09:40 +00:00
mkmk.sh mkfile, mkmk.sh: update for new asm-free getcallerpc 2020-01-09 19:57:56 -05:00
mkone good bye SHORTLIB 2005-01-04 22:09:40 +00:00
mksyslib build: use ar s flag to avoid ranlib 2007-11-05 11:27:14 -05:00