Commit Graph

16 Commits

Author SHA1 Message Date
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
Dan Cross
fa325e9b42 Trivial changes: whitespace and modes.
Remote whitespace at the ends of lines.
Remove blank lines from the ends of files.
Change modes on source files so that they
are not executable.

Signed-off-by: Dan Cross <cross@gajendra.net>
2020-01-10 14:54:30 +00:00
Russ Cox
a3b799d9f0 rc: silence lion roar
R=rsc
http://codereview.appspot.com/4835048
2011-08-02 16:21:33 -04:00
Russ Cox
94e1f2a438 rc: add subscript sequences (Erik Quanstrom) 2008-07-20 04:15:41 -04:00
rsc
fbc629a995 keep path and PATH in sync 2007-03-28 16:04:37 +00:00
rsc
bd1b0cc17e fix phantom rc crashes 2007-03-26 14:24:44 +00:00
rsc
c8f538425f sync with plan 9 2007-03-26 12:02:41 +00:00
rsc
4ae2f414e2 make sure errors cause non-zero exit status 2005-08-11 16:44:18 +00:00
rsc
0e4068e8c4 fixes from bengt for sun 2005-07-26 10:19:23 +00:00
rsc
7ce3f20d73 stupid sun 2005-07-13 03:54:01 +00:00
rsc
e3ffbf3b84 set $PLAN9 if necessary 2005-05-19 17:13:24 +00:00
rsc
4ee543e58c try harder to put background jobs in background; do not print in response to SIGPIPE 2005-03-18 19:03:25 +00:00
rsc
26a5fd5725 set pid=-1 explicitly 2005-02-11 16:58:06 +00:00
rsc
c8b6342d3c Many small edits. 2005-01-13 04:49:19 +00:00
rsc
a9eaaa03e0 maintain $path and $PATH simultaneously 2005-01-12 16:59:50 +00:00
rsc
f08fdedcee Plan 9's rc.
not a clear win over byron's,
but at least it has the right syntax.
2003-11-23 18:04:08 +00:00