2021年2月16日(火) 16:28 Andreas Schwab <sch...@linux-m68k.org>: > See 2.4 Reserved Words. > > This recognition shall only occur when none of the characters is > quoted and when the word is used as:
I think that section just describes the necessary condition that the word is recognized as the reserved keyword: "This recognition shall *only* occur...". It doesn't explain whether the reserved keyword can be really used to construct the AST following the shell grammar. For example, this alone doesn't explain why $ if :; then echo A; fi if :; then echo A; fi (i.e., the combination "fi if") is a syntax error. Hmm, it seems we need to combine the Yacc-BNF notation at the end of Sec. 2.10 to understand this? For example, $ case x in (x) if :; then echo; fi esac can be derived as case_clause -> Case WORD linebreak in linebreak case_list Esac -> Case 'x' ε in ε case_list Esac -> Case 'x' ε in ε case_item_ns Esac -> Case 'x' ε in ε '(' pattern ')' compound_list Esac -> Case 'x' ε in ε '(' 'x' ')' linebreak term Esac -> Case 'x' ε in ε '(' 'x' ')' ε and_or Esac -> Case 'x' ε in ε '(' 'x' ')' ε pipeline Esac -> Case 'x' ε in ε '(' 'x' ')' ε pipe_sequence Esac -> Case 'x' ε in ε '(' 'x' ')' ε command Esac -> Case 'x' ε in ε '(' 'x' ')' ε compound_command Esac -> Case 'x' ε in ε '(' 'x' ')' ε if_clause Esac -> ... where ε is an empty string. OK, now I understood this behavior is actually required by the POSIX standard. Can we find any textual explanation on this rule? Or maybe this behavior is intuitive enough for those who understand the shell grammar so that they don't see the necessity of an additional explanation... Thank you for the comment! -- Koichi