Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0001046 [1003.1(2013)/Issue7+TC1] Shell and Utilities Objection Error 2016-04-23 16:09 2017-06-01 15:09
Reporter rillig View Status public  
Assigned To
Priority normal Resolution Withdrawn  
Status Closed  
Name Roland Illig
Organization
User Reference
Section 2.10. Shell Grammar
Page Number unsure
Line Number unsure
Interp Status ---
Final Accepted Text
Summary 0001046: Grammar production if_clause allows "if command then"
Description http://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 Action Check 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.
Tags No tags attached.
Attached Files

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

-  Notes
(0003168)
kre (reporter)
2016-04-23 17:02

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.
(0003169)
shware_systems (reporter)
2016-04-23 17:02
edited on: 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.

(0003170)
kre (reporter)
2016-04-23 17:50

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).
(0003171)
shware_systems (reporter)
2016-04-23 18:27

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.
(0003172)
rillig (reporter)
2016-04-23 19:59

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


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker