help-bash
[Top][All Lists]
Advanced

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

Re: Question about compound_list in bash grammar


From: crimson flame
Subject: Re: Question about compound_list in bash grammar
Date: Thu, 10 Dec 2020 08:59:36 +0530

Thank you so much for answering this!
So there is a context sensitive aspect here to recognize a reserved word.
Hence the back and forth between the lexer and the parser.

Thanks,
Sisir

On Thu, Dec 10, 2020 at 1:33 AM Chet Ramey <chet.ramey@case.edu> wrote:

> On 12/9/20 1:18 PM, crimson flame wrote:
> > Hi,
> > Why does the following command not work on bash CLI?
> >
> > *for i in {1..5}; do echo $i done*
>
> Because `done' has to follow an operator to be recognized as a reserved
> word. It's perfectly valid to have something like
>
> for i in {1..5}; do echo $i done done done done ; done
>
> That's not done completely in the grammar: the grammar works with the
> tokens the lexical analyzer provides. The lexical analyzer keeps track
> of the previous tokens it recognizes and returns DONE (the reserved
> word) only if the previous token allows it.
>
> Two of those previous tokens happen to be `;' and newline, but you can
> also end the compound_list with, say, `&'.
>
> --
> ``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]