diff options
author | Russ Cox <rsc@swtch.com> | 2020-05-04 18:34:19 -0400 |
---|---|---|
committer | Russ Cox <rsc@swtch.com> | 2020-05-04 23:41:15 -0400 |
commit | 47d4646eebac34c0b94951cfcf1b81ed2ca513e1 (patch) | |
tree | fff188620bba3491f209e6268fdb87b816c3b236 /font/shinonome/k16minbi.600e | |
parent | c1c1b5267fd5e14be531a4b22ed0124b35d427cb (diff) | |
download | plan9port-47d4646eebac34c0b94951cfcf1b81ed2ca513e1.tar.gz plan9port-47d4646eebac34c0b94951cfcf1b81ed2ca513e1.tar.bz2 plan9port-47d4646eebac34c0b94951cfcf1b81ed2ca513e1.zip |
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.
Diffstat (limited to 'font/shinonome/k16minbi.600e')
0 files changed, 0 insertions, 0 deletions