View Issue Details

IDProjectCategoryView StatusLast Update
00010461003.1(2013)/Issue7+TC1Shell and Utilitiespublic2017-06-01 15:09
Reporterrillig Assigned To 
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionWithdrawn 
NameRoland Illig
Organization
User Reference
Section2.10. Shell Grammar
Page Numberunsure
Line Numberunsure
Interp Status---
Final Accepted Text
Summary0001046: Grammar production if_clause allows "if command then"
Descriptionhttp://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_10_02

According to that grammar, the following text is valid:

  if echo then echo yes else echo no fi

This is because the ''if_clause'' refers to the ''compound_list'', which, in its simplest form, can be reduced to just a WORD token, using these productions:

  if_clause := "if" compound_list "then" compound_list "fi"
  compound_list := term
  term := and_or
  and_or := pipeline
  pipeline := pipe_sequence
  pipe_sequence := simple_command
  simple_command := cmd_name
  cmd_name := WORD

All shells that I know interpret this differently, taking the ''then echo yes else echo no fi'' as arguments to the ''echo'' command.
Desired ActionCheck whether the grammar in its current form really allows this interpretation.

If it does, restrict the grammar to disallow this, since it creates ambiguous programs.
TagsNo tags attached.

Relationships

related to 0001145 Closed 1003.1(2016/18)/Issue7+TC2 compound-list does not required a terminating semicolon even in compound commands, which is contradictory with implementations. 

Activities

kre

2016-04-23 17:02

reporter   bugnote:0003168

In
     if echo then echo yes else echo no fi

once "echo" (the fist one) has been parsed as a command name, none of the
following args is elegible to be a reserved word, until the command is
finished (which takes some other syntax character, ';' or \n or perhaps )
in appropriate circumstances.

Hence the interpretation you're suggesting cannot occur as none of "then"
"else" or "fi" in that example are the tokens with those names, they are
all just words.

This isn't because of the grammar as such, but because of the somewhat strange
way the lexical analyser is required to work.

shware_systems

2016-04-23 17:02

reporter   bugnote:0003169

Last edited: 2016-04-23 17:38

No, the grammar does not permit that by Rule 1 in that section. Keyword recognition, due to the if opening the context, has priority over assignment as a utility argument WORD, and has an implied separator_op of ';' preceding for the Then, Elif, and Else keyword TOKENs as a result terminating the cmd_suffix of the echo term. Shells treating the then... clause as arguments are buggy therefore.

kre

2016-04-23 17:50

reporter   bugnote:0003170

Rule 1 applies only to command names, and there is no such thing
as an implied separator_op.

Perhaps the text needs to be made clearer about this, but I am quite
certain that reserved words (with "in" as something of a special case)
are only ever intended to be detected as reserved words at the beginning
of a command (after some kind of command ending delimiter).

shware_systems

2016-04-23 18:27

reporter   bugnote:0003171

Yes, it could be stated better, but at the point cmd_suffix might start the Then as a continuation of the if_clause has priority in determining that the cmd_name alone is what satisfies simple_command being complete.

rillig

2016-04-23 19:59

reporter   bugnote:0003172

Thanks, kre, for the explanation. It is a tricky topic, but now that I have thought about it for several hours, the specification contains all the necessary details.

Issue History

Date Modified Username Field Change
2016-04-23 16:09 rillig New Issue
2016-04-23 16:09 rillig Name => Roland Illig
2016-04-23 16:09 rillig Section => 2.10. Shell Grammar
2016-04-23 16:09 rillig Page Number => unsure
2016-04-23 16:09 rillig Line Number => unsure
2016-04-23 17:02 kre Note Added: 0003168
2016-04-23 17:02 shware_systems Note Added: 0003169
2016-04-23 17:17 shware_systems Note Edited: 0003169
2016-04-23 17:38 shware_systems Note Edited: 0003169
2016-04-23 17:50 kre Note Added: 0003170
2016-04-23 18:27 shware_systems Note Added: 0003171
2016-04-23 19:59 rillig Note Added: 0003172
2016-04-25 08:55 geoffclare Project 2008-TC2 => 1003.1(2013)/Issue7+TC1
2017-06-01 15:09 geoffclare Interp Status => ---
2017-06-01 15:09 geoffclare Status New => Closed
2017-06-01 15:09 geoffclare Resolution Open => Withdrawn
2017-06-15 08:55 geoffclare Relationship added related to 0001145