Sample Header Ad - 728x90

POSIX wording regarding Shell grammar

1 vote
0 answers
121 views
This page describing the Shell grammar has the following paragraph in the "Shell Grammar Rules" section: > 1. [Command Name] > >When the TOKEN is exactly a reserved word, the token identifier for that reserved word will result. Otherwise, the token WORD will be returned. Also, if the parser is in any state where only a reserved word could be the next correct token, proceed as above. This rule applies rather narrowly: when a compound list is terminated by some clear delimiter (such as the closing fi of an inner if_clause) then it would apply; where the compound list might continue (as in after a ;), rule 7a (and consequently the first sentence of this rule) would apply. **In many instances the two conditions are identical**, but this part of this rule does not give licence to treating a WORD as a reserved word unless it is in a place where a reserved word must appear. In the highlighted part (i.e. "In many instances the two conditions are identical"), what are the "two conditions"? What are the instances where they are "identical", and what are some instances where they are not "identical"? I think I understand the meaning behind this paragraph (combined with **rule 7a** from below): the parser will only "generate" a RESERVED WORD token if either: - the parser is in a state where it expects a new command and the next TOKEN is "exactly a RESERVED WORD", or - the parser is in a state where only a RESERVED WORD token should be appear (if the parser did not allow for this, a parser error would be generated) What I am failing to understand is the exact wording of the author. If I am not mistaken, the first two sentences of the quoted paragraph apply when the parser is in a state where it expects a new command. The third sentence applies when the parser is in a state that requires a RESERVED WORD token to appear. Is the "first condition": the parser is in a state where it expects a new command + the TOKEN is exactly a RESERVED WORD? And the second condition: "the parser is in a state that requires a RESERVED WORD token to appear? If so, I do not see any instance where the "two conditions are identical". I would greatly appreciate it if someone could explain what the author meant by using the quoted wording. Thank you!
Asked by user42768 (111 rep)
Nov 17, 2024, 04:30 PM
Last activity: Nov 18, 2024, 06:47 AM