help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Why yacc_EOF is used as a list_terminator for for_command?


From: Chet Ramey
Subject: Re: Why yacc_EOF is used as a list_terminator for for_command?
Date: Wed, 12 May 2021 10:24:32 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:78.0) Gecko/20100101 Thunderbird/78.10.1

On 5/11/21 11:16 PM, Koichi Murase wrote:
2021年5月11日(火) 3:03 Peng Yu <pengyu.ut@gmail.com>:
Do you have a better idea? Where would you include it? Is it worth
changing the current implementation which works without problems
currently? It's useless to change the code that actually doesn't
change any behavior. It may just introduce a new bug.

My goal is not to change the current implementation. I am asking the
question from the perspective of how would one implement it from
scratch.

Do you mean you are planning to develop your own new shell? Or, you
suggest replacing the parsing engine of Bash with a completely
different one developed from scratch?

Bash's parser is unique among widely-used POSIX shells because it uses
bison/yacc. Everyone else uses a hand-rolled recursive descent parser.

One of the POSIX group's greatest achievements was to create a yacc-like
grammar for the shell, since, as Tom Duff put it, "Nobody really knows
what the Bourne shell's grammar is." And even that has lots of special
cases and context-dependent rules.


"Correct" means if you were to start from scratch and whether it is
the best of all the possible implementation choices. (Or maybe
"necessary" is a better word in this case.)

I'm not sure what the best word to capture your intent is, but "correct" is
not it.


How do you define "best"... It depends on the person. I can understand
what you want to say; indeed yacc_EOF is unneeded in `list_terminator`
when used in the definition of `for' statement, etc. So you may
distinguish two different types of line termination:

   list_terminator_middle: '\n' | ';'
   list_terminator_general: list_terminator_middle | yacc_EOF

On the other hand, the grammar as it exists today parses syntactically
correct `for' statements correctly and produces errors for invalid
statements. The increase in generality does not result in incorrectness.

If you can find an exception to those two points, please report it.


--
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU    chet@case.edu    http://tiswww.cwru.edu/~chet/



reply via email to

[Prev in Thread] Current Thread [Next in Thread]