[Top][All Lists]

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

Re: Shell Grammar man page

From: Mike Jonkmans
Subject: Re: Shell Grammar man page
Date: Fri, 26 Feb 2021 15:59:29 +0100

On Thu, Feb 25, 2021 at 06:28:34PM -0500, Chet Ramey wrote:
> On 2/25/21 10:13 AM, Mike Jonkmans wrote:

> > Starting with 'Statements' might be an option.
> Maybe. Or a POSIX-like description that says a command can be a
> simple command
> list
> pipeline
> compound command
> function definition
> coproc
> just like the sections in the SHELL GRAMMAR section.

The missing definition of command was one of my initial points.
So that would be nice.

> > > So where would you suggest changes? I'd argue that the use of `command' in
> > > the simple commands section is quite clear. I'd also argue that everyone
> > > understands what `the last command in a pipeline' means, or `commands in a
> > > list', and that those are more descriptive than `pipeline elements' or
> > > `list elements'.
> > 
> > I agree that the usage of 'command' is clear in these cases.
> > But these commands are different things.
> > The command in pipelines might be better described as compound-command.
> No. A simple command may be a pipeline element (and most often is, given
> how the shell is usually used). Compound commands are as described in the
> manual, basically equivalent to the shell_command production in the bash
> grammar.

Essential rules from parse.y (newlines and some equivalents left out):

  simple_command: WORD+
  pipeline: pipeline '|' pipeline
      | command
  command: simple_command | shell_command | function_def | coproc
  shell_command: for_command | group_command | ...
  function_def: WORD '(' ')' shell_command
  coproc: 'coproc' shell_command | 'coproc' simple_command

  simple_list: simple_list1 | simple_list1 ';'
  simple_list1: pipeline
      | simple_list1 '&&' simple_list1
          | simple_list1 ';' simple_list1
          | ...

  group_command: '{' compound_list '}'
  compound_list: pipeline                ## expanded from list0, list1
      | pipeline '&&' compound_list
      | pipeline ';' compound_list
      | pipeline '\n' compound_list
          | compound_list ';'
          | compound_list '\n'
          | ...

The correspondences between terms in the manual and parse.y are:

     manual       |         parse.y
 compound command | shell_command
 command          | command or simple_list or compound_list
 list             | simple_list or compound_list
 pipeline         | pipeline_command

> The compound command description is accurate. I think you're trying to make
> a compound comand more than it is.
Indeed. I mistakenly took functions and coprocs for compound commands. :(

In a later, separate, post, I will take the rules from parse.y
and transform these into an ECFG (with rules like: x: y+ [ nl | ';' ]* )
That should be shorter and look more like the descriptions in the manual.

Then maybe, if time (and wits) permits, I'll puzzle an ELL(1) parser into bash.
Just to see whether that can replace yacc/bison.
(see e.g. https://os.ghalkes.nl/LLnextgen/)

Regards, Mike Jonkmans

reply via email to

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