• R/O
  • SSH
  • HTTPS

yash: Commit


Commit MetaInfo

Revision3886 (tree)
Time2018-09-23 11:45:43
Authormagicant

Log Message

doc/fgrammar: Rewrite formal syntax

Change Summary

Incremental Difference

--- yash/branches/token_based_parser/doc/fgrammar.txt (revision 3885)
+++ yash/branches/token_based_parser/doc/fgrammar.txt (revision 3886)
@@ -4,102 +4,34 @@
44 //:title: Yash manual - Formal definition of command syntax
55 :description: This page gives the formal definition of yash command syntax.
66
7-This chapter defines the syntax of shell commands as a parsing expression
8-grammar.
7+This chapter defines the syntax of the shell command language.
98
10-The set of terminals of the grammar is the set of characters that can
11-be handled on the environment in which the shell is run (a.k.a. execution
12-character set), with the exception that the set does not contain the null
13-character (`'\0'`).
9+[NOTE]
10+Some of the syntactic features described below are not supported in the
11+link:posix.html[POSIXly-correct mode].
1412
15-Below is a list of nonterminals of the grammar with corresponding parsing
16-expressions.
17-The list does not include rules for parsing contents and ends of
18-link:redir.html#here[here documents].
19-In the link:posix.html[POSIXly-correct mode], the grammar varies from the list
20-below to disable non-POSIX functionalities.
13+[[token]]
14+== Tokenization
2115
22-[[d-complete-command]]CompleteCommand::
23-<<d-sequence,Sequence>> <<d-eof,EOF>>
16+The characters of the input source code are first delimited into tokens.
17+Tokens are delimited so that the earlier token spans as long as possible.
18+A sequence of one or more unquoted blank characters delimits a token.
2419
25-[[d-sequence]]Sequence::
26-<<d-n,N>>* <<d-list,List>>*
20+The following tokens are the operator tokens:
2721
28-[[d-list]]List::
29-<<d-pipeline,Pipeline>> ((+&&+ / +||+) <<d-n,N>>* Pipeline)*
30-<<d-list-separator,ListSeparator>>
22+`&` `&&` `(` `)` `;` `;;` `|` `||`
23+`<` `<<` `<&` `<(` `<<-` `<<<` `<>`
24+`>` `>>` `>&` `>(` `>>|` `>|` (newline)
3125
32-[[d-pipeline]]Pipeline::
33-<<d-bang,Bang>>? <<d-command,Command>> (+|+ <<d-n,N>>* Command)*
26+[NOTE]
27+Unlike other programming languages, the newline operator is a token rather
28+than a white space.
3429
35-[[d-command]]Command::
36-<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>* / +
37-!<<d-r,R>> <<d-function-definition,FunctionDefinition>> / +
38-!R <<d-simple-command,SimpleCommand>>
30+Characters that are not blank nor part of an operator compose a word token.
31+Words are parsed by the following parsing expression grammar:
3932
40-[[d-compound-command]]CompoundCommand::
41-<<d-subshell,Subshell>> / +
42-<<d-grouping,Grouping>> / +
43-<<d-if-command,IfCommand>> / +
44-<<d-for-command,ForCommand>> / +
45-<<d-while-command,WhileCommand>> / +
46-<<d-case-command,CaseCommand>> / +
47-<<d-function-command,FunctionCommand>>
48-
49-[[d-subshell]]Subshell::
50-+(+ <<d-sequence,Sequence>> +)+ <<d-s,S>>*
51-
52-[[d-grouping]]Grouping::
53-<<d-left-brace,LeftBrace>> <<d-sequence,Sequence>>
54-<<d-right-brace,RightBrace>>
55-
56-[[d-if-command]]IfCommand::
57-<<d-if,If>> <<d-sequence,Sequence>> <<d-then,Then>> Sequence
58-(<<d-elif,Elif>> Sequence <<d-then,Then>> Sequence)*
59-(<<d-else,Else>> Sequence)? <<d-fi,Fi>>
60-
61-[[d-for-command]]ForCommand::
62-<<d-for,For>> <<d-name,Name>> <<d-s,S>>* <<d-separator,Separator>>?
63-(<<d-in,In>> <<d-word,Word>>* <<d-separator,Separator>>)?
64-<<d-do,Do>> <<d-sequence,Sequence>> <<d-done,Done>>
65-
66-[[d-while-command]]WhileCommand::
67-(<<d-while,While>> / <<d-until,Until>>)
68-<<d-sequence,Sequence>> <<d-do,Do>> Sequence <<d-done,Done>>
69-
70-[[d-case-command]]CaseCommand::
71-<<d-case,Case>> <<d-word,Word>> <<d-n,N>>* <<d-in,In>> N*
72-<<d-case-item,CaseItem>>* <<d-esac,Esac>>
73-
74-[[d-case-item]]CaseItem::
75-!<<d-esac,Esac>> (+(+ <<d-s,S>>*)? <<d-word,Word>> (+|+ S* Word)* +)+
76-<<d-sequence,Sequence>> (+;;+ / &amp;Esac)
77-
78-[[d-function-command]]FunctionCommand::
79-<<d-function,Function>> <<d-word,Word>> (+(+ <<d-s,S>>* +)+)? <<d-n,N>>*
80-<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
81-
82-[[d-function-definition]]FunctionDefinition::
83-<<d-name,Name>> <<d-s,S>>* +(+ S* +)+ <<d-n,N>>*
84-<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
85-
86-[[d-simple-command]]SimpleCommand::
87-&(<<d-word,Word>> / <<d-redirection,Redirection>>)
88-(<<d-assignment,Assignment>> / Redirection)* (Word / Redirection)*
89-
90-[[d-assignment]]Assignment::
91-<<d-name,Name>> +=+ <<d-word,Word>> / +
92-Name +=(+ <<d-n,N>>* (Word N*)* +)+
93-
94-[[d-name]]Name::
95-!\[[:digit:]] [[:alnum:] +_+]+
96-
97-[[d-portable-name]]PortableName::
98-![++0++-++9++] [++0++-++9++ ++ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_++]+
99-
10033 [[d-word]]Word::
10134 (<<d-word-element,WordElement>> / !<<d-special-char,SpecialChar>> .)+
102-<<d-s,S>>*
10335
10436 [[d-word-element]]WordElement::
10537 +\+ . / +
@@ -110,10 +42,10 @@
11042 <<d-command-substitution,CommandSubstitution>>
11143
11244 [[d-quote-element]]QuoteElement::
113-+\+ ([+$&#96;"&#92;+] / <<d-nl,NL>>) / +
45++\+ ([+$&#96;"&#92;+] / <newline>) / +
11446 <<d-parameter,Parameter>> / +
11547 <<d-arithmetic,Arithmetic>> / +
116-<<d-command-substitution,CommandSubstitution>> / +
48+<<d-command-substitution-quoted,CommandSubstitutionQuoted>> / +
11749 ![+&#96;"&#92;+] .
11850
11951 [[d-parameter]]Parameter::
@@ -121,15 +53,18 @@
12153 +$+ <<d-portable-name,PortableName>> / +
12254 +$+ <<d-parameter-body,ParameterBody>>
12355
56+[[d-portable-name]]PortableName::
57+![++0++-++9++] [++0++-++9++ ++ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_++]+
58+
12459 [[d-parameter-body]]ParameterBody::
12560 +{+ <<d-parameter-number,ParameterNumber>>?
126-(<<d-parameter-name,ParameterName>> / ParameterBody /
127-<<d-parameter,Parameter>>)
61+(<<d-parameter-name,ParameterName>> / ParameterBody / +$+ ParameterBody /
62+<<d-arithmetic,Arithmetic>> / <<d-command-substitution,CommandSubstitution>>)
12863 <<d-parameter-index,ParameterIndex>>? <<d-parameter-match,ParameterMatch>>?
12964 +}+
13065
13166 [[d-parameter-number]]ParameterNumber::
132-`#` ![`+=:/%`] !([`-?#`] `}`)
67+`#` ![`}+=:/%`] !([`-?#`] !`}`)
13368
13469 [[d-parameter-name]]ParameterName::
13570 [+@*#?-$!+] / +
@@ -167,114 +102,193 @@
167102 ![+`()+] .
168103
169104 [[d-command-substitution]]CommandSubstitution::
170-+$(+ <<d-sequence,Sequence>> +)+ / +
105++$(+ <<d-complete-program,CompleteProgram>> +)+ / +
171106 +&#96;+ <<d-command-substitution-body,CommandSubstitutionBody>>* +&#96;+
172107
108+[[d-command-substitution-quoted]]CommandSubstitutionQuoted::
109++$(+ <<d-complete-program,CompleteProgram>> +)+ / +
110++&#96;+ <<d-command-substitution-body-quoted,CommandSubstitutionBodyQuoted>>*
111++&#96;+
112+
173113 [[d-command-substitution-body]]CommandSubstitutionBody::
174114 +\+ [+$&#96;\+] / +
175115 !++&#96;++ .
176116
177-[[d-redirection]]Redirection::
178-<<d-redirection-fd,RedirectionFD>>
179-<<d-redirection-operator,RedirectionOperator>> <<d-s,S>>* <<d-word,Word>> / +
180-RedirectionFD +<(+ <<d-sequence,Sequence>> +)+ / +
181-RedirectionFD +>(+ Sequence +)+
117+[[d-command-substitution-body-quoted]]CommandSubstitutionBodyQuoted::
118++\+ [+$&#96;\`+] / +
119+!++&#96;++ .
182120
183-[[d-redirection-fd]]RedirectionFD::
184-\[[:digit:]]*
121+[[d-special-char]]SpecialChar::
122+[+|&amp;;&lt;&gt;()&#96;&#92;"'+ [:blank:]] / <newline>
185123
186-[[d-redirection-operator]]RedirectionOperator::
187-`<` / `<>` / `>` / `>|` / `>>` / `>>|` / `<&` / `>&` / `<<` / `<<-` / `<<<`
124+The set of terminals of the grammar is the set of characters that can
125+be handled on the environment in which the shell is run (a.k.a. execution
126+character set), with the exception that the set does not contain the null
127+character (`'\0'`).
188128
189-[[d-list-separator]]ListSeparator::
190-<<d-separator,Separator>> / +
191-+&amp;+ <<d-n,N>>* / +
192-&++)++ / +
193-&++;;++
129+Strictly speaking, the definition above is not a complete parsing expression
130+grammar because the rule for <<d-command-substitution,CommandSubstitution>>
131+(<<d-command-substitution-quoted,Quoted>>) depends on
132+<<d-complete-program,CompleteProgram>> which is a non-terminal of the syntax.
194133
195-[[d-separator]]Separator::
196-+;+ <<d-n,N>>* / +
197-<<d-n,N>>+ / +
198-<<d-eof,EOF>>
134+[[classification]]
135+=== Token classification
199136
200-[[d-n]]N::
201-<<d-s,S>>* <<d-nl,NL>>
137+After a word token is delimited, the token may be further classified as an
138+IO_NUMBER token, reserved word, name word, assignment word, or just normal
139+word.
140+Classification other than the normal word is applied only when applicable in
141+the context in which the word appears.
142+See link:syntax.html#tokens[Tokens and keywords] for the list of the reserved
143+words (keywords) and the context in which a word may be recognized as a
144+reserved word.
202145
203-[[d-s]]S::
204-\[[:blank:]] / +
205-<<d-comment,Comment>>
146+A token is an IO_NUMBER token iff it is composed of digit characters only and
147+immediately followed by +<+ or +>+.
206148
149+An assignment token is a token that starts with a name followed by +=+:
150+
151+[[d-assignment-word]]AssignmentWord::
152+<<d-assignment-prefix,AssignmentPrefix>> <<d-word,Word>>
153+
154+[[d-assignment-prefix]]AssignmentPrefix::
155+<<d-name,Name>> +=+
156+
157+[[d-name]]Name::
158+!\[[:digit:]] \[[:alnum:] +_+]+
159+
160+[[comments]]
161+=== Comments
162+
163+A comment begins with `#` and continues up to (but not including) the next
164+newline character.
165+Comments are treated like a blank character and do not become part of a token.
166+The initial `#` of a comment must appear as if it would otherwise be the first
167+character of a word token; Other ++#++s are just treated as part of a word
168+token.
169+
207170 [[d-comment]]Comment::
208-+#+ (!<<d-nl,NL>> .)*
171+`#` (!<newline> .)*
209172
210-[[d-r]]R::
211-<<d-bang,Bang>> / <<d-left-brace,LeftBrace>> / <<d-right-brace,RightBrace>> /
212-<<d-case,Case>> / <<d-do,Do>> / <<d-done,Done>> / <<d-elif,Elif>> /
213-<<d-else,Else>> / <<d-esac,Esac>> / <<d-fi,Fi>> / <<d-for,For>> /
214-<<d-if,If>> / <<d-in,In>> / <<d-then,Then>> / <<d-until,Until>> /
215-<<d-while,While>>
173+[[syntax]]
174+== Syntax
216175
217-[[d-bang]]Bang::
218-+!+ <<d-d,D>>
176+After tokens have been delimited, the sequence of the tokens is parsed
177+according to the context-free grammar defined below, where `*`, `+`, and `?`
178+should be interpreted in the same manner as standard regular expression:
219179
220-[[d-left-brace]]LeftBrace::
221-+{+ <<d-d,D>>
180+[[d-complete-program]]CompleteProgram::
181+<<d-nl,NL>>* | <<d-compound-list,CompoundList>>
222182
223-[[d-right-brace]]RightBrace::
224-+}+ <<d-d,D>>
183+[[d-compound-list]]CompoundList::
184+<<d-nl,NL>>* <<d-and-or-list,AndOrList>>
185+({zwsp}(+;+ | +&+ | NL) <<d-complete-program,CompleteProgram>>)?
225186
226-[[d-case]]Case::
227-+case+ <<d-d,D>>
187+[[d-and-or-list]]AndOrList::
188+<<d-pipeline,Pipeline>> &#40;(+&&+ | +||+) <<d-nl,NL>>* Pipeline)*
228189
229-[[d-do]]Do::
230-+do+ <<d-d,D>>
190+[[d-pipeline]]Pipeline::
191++!+? <<d-command,Command>> (+|+ <<d-nl,NL>>* Command)*
231192
232-[[d-done]]Done::
233-+done+ <<d-d,D>>
193+[[d-command]]Command::
194+<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>* | +
195+<<d-function-definition,FunctionDefinition>> | +
196+<<d-simple-command,SimpleCommand>>
234197
235-[[d-elif]]Elif::
236-+elif+ <<d-d,D>>
198+[[d-compound-command]]CompoundCommand::
199+<<d-subshell,Subshell>> | +
200+<<d-grouping,Grouping>> | +
201+<<d-if-command,IfCommand>> | +
202+<<d-for-command,ForCommand>> | +
203+<<d-while-command,WhileCommand>> | +
204+<<d-case-command,CaseCommand>> | +
205+<<d-function-command,FunctionCommand>>
237206
238-[[d-else]]Else::
239-+else+ <<d-d,D>>
207+[[d-subshell]]Subshell::
208++(+ <<d-compound-list,CompoundList>> +)+
240209
241-[[d-esac]]Esac::
242-+esac+ <<d-d,D>>
210+[[d-grouping]]Grouping::
211++{+ <<d-compound-list,CompoundList>> +}+
243212
244-[[d-fi]]Fi::
245-+fi+ <<d-d,D>>
213+[[d-if-command]]IfCommand::
214++if+ <<d-compound-list,CompoundList>> +then+ CompoundList
215+(+elif+ CompoundList +then+ CompoundList)*
216+(+else+ CompoundList)? +fi+
246217
247-[[d-for]]For::
248-+for+ <<d-d,D>>
218+[[d-for-command]]ForCommand::
219++for+ <<d-name,Name>>
220+({zwsp}(<<d-nl,NL>>* +in+ <<d-word,Word>>*)? (+;+ | NL) NL*)?
221++do+ <<d-compound-list,CompoundList>> +done+
249222
250-[[d-function]]Function::
251-+function+ <<d-d,D>>
223+[[d-while-command]]WhileCommand::
224+(+while+ | +until+) <<d-compound-list,CompoundList>> +do+ CompoundList +done+
252225
253-[[d-if]]If::
254-+if+ <<d-d,D>>
226+[[d-case-command]]CaseCommand::
227++case+ <<d-word,Word>> <<d-nl,NL>>* +in+ NL* <<d-case-list,CaseList>>? +esac+
255228
256-[[d-in]]In::
257-+in+ <<d-d,D>>
229+[[d-case-list]]CaseList::
230+<<d-case-item,CaseItem>> (+;;+ <<d-nl,NL>>* CaseList)?
258231
259-[[d-then]]Then::
260-+then+ <<d-d,D>>
232+[[d-case-item]]CaseItem::
233++(+? <<d-word,Word>> (+|+ Word)* +)+ <<d-complete-program,CompleteProgram>>
261234
262-[[d-until]]Until::
263-+until+ <<d-d,D>>
235+[[d-function-command]]FunctionCommand::
236++function+ <<d-word,Word>> (+(+ +)+)? <<d-nl,NL>>*
237+<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
264238
265-[[d-while]]While::
266-+while+ <<d-d,D>>
239+[[d-function-definition]]FunctionDefinition::
240+<<d-name,Name>> +(+ +)+ <<d-nl,NL>>*
241+<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
267242
268-[[d-d]]D::
269-!<<d-word,Word>> <<d-s,S>>*
243+[[d-simple-command]]SimpleCommand::
244+(<<d-assignment,Assignment>> | <<d-redirection,Redirection>>) SimpleCommand?
245+| +
246+<<d-word,Word>> (Word | <<d-redirection,Redirection>>)*
270247
271-[[d-special-char]]SpecialChar::
272-[+|&amp;;&lt;&gt;()&#96;&#92;"'+ [:blank:]] / <<d-nl,NL>>
248+[[d-assignment]]Assignment::
249+<<d-assignment-word,AssignmentWord>> | +
250+<<d-assignment-prefix,AssignmentPrefix>>++(++
251+<<d-nl,NL>>* (<<d-word,Word>> NL*)* +)+
273252
253+[[d-redirection]]Redirection::
254+IO_NUMBER? <<d-redirection-operator,RedirectionOperator>> <<d-word,Word>> | +
255+IO_NUMBER? +<(+ <<d-complete-program,CompleteProgram>> +)+ | +
256+IO_NUMBER? +>(+ CompleteProgram +)+
257+
258+[[d-redirection-operator]]RedirectionOperator::
259+`<` | `<>` | `>` | `>|` | `>>` | `>>|` | `<&` | `>&` | `<<` | `<<-` | `<<<`
260+
274261 [[d-nl]]NL::
275262 <newline>
276263
277-[[d-eof]]EOF::
278-!.
264+In the rule for <<d-simple-command,SimpleCommand>>, a <<d-word,Word>> token is
265+accepted only when the token cannot be parsed as the first token of an
266+<<d-assignment,Assignment>>.
279267
268+In the rule for <<d-assignment,Assignment>>, the +(+ token must immediately
269+follow the <<d-assignment-prefix,AssignmentPrefix>> token, without any blank
270+characters in between.
271+
272+link:redir.html#here[Here-document] contents do not appear as part of the
273+grammar above.
274+They are parsed just after the newline (<<d-nl,NL>>) token that follows the
275+corresponding redirection operator.
276+
277+[[alias]]
278+=== Alias substitution
279+
280+Word tokens are subject to link:syntax.html#aliases[alias substitution].
281+
282+- If a word is going to be parsed as a <<d-word,Word>> of a
283+ <<d-simple-command,SimpleCommand>>, the word is subjected to alias
284+ substitution of any kind (normal and global aliases).
285+- If a word is the next token after the result of an alias substitution and
286+ the substitution string ends with a blank character, then the word is also
287+ subjected to alias substitution of any kind.
288+- Other words are subjected to global alias substitution unless the shell is
289+ in the link:posix.html[POSIXly-correct mode].
290+
291+Tokens that are classified as reserved words are not subject to alias
292+substitution.
293+
280294 // vim: set filetype=asciidoc textwidth=78 expandtab:
--- yash/branches/token_based_parser/doc/ja/fgrammar.txt (revision 3885)
+++ yash/branches/token_based_parser/doc/ja/fgrammar.txt (revision 3886)
@@ -4,93 +4,29 @@
44 //:title: Yash マニュアル - 構文の形式的定義
55 :description: Yash のコマンドの構文規則の形式的な定義
66
7-ここに yash の文法の形式的定義を示します。Yash の文法は解析表現文法で定義されます。
7+ここにプログラミング言語としてのシェルの構文定義を示します。
88
9-Yash の文法における終端記号の集合は、yash を実行する環境が扱える任意の文字の集合 (実行文字集合) です (ただしナル文字 `'\0'` を除く)。
9+[NOTE]
10+以下に示す構文の一部はlink:posix.html[POSIX 準拠モード]では使用できません。
1011
11-以下は、yash の文法を構成する非終端記号とそれに対応する終端記号の一覧です。ただしここに挙げる文法の定義にはlink:redir.html#here[ヒアドキュメント]の内容とその終わりを表す行の解析のための規則は含まれていません。また link:posix.html[POSIX 準拠モード]では構文が若干変わりますが、ここには示しません。
12+[[token]]
13+== トークン分割
1214
13-[[d-complete-command]]CompleteCommand::
14-<<d-sequence,Sequence>> <<d-eof,EOF>>
15+入力ソースコードの文字列はまずトークンに分割されます。トークンはソースコード内のより先に現れるトークンができるだけ長くなるように分割します。一つ以上の空白 (blank) 文字の連なりはトークンを分割します。
1516
16-[[d-sequence]]Sequence::
17-<<d-n,N>>* <<d-list,List>>*
17+Yash に存在する演算子トークンは以下の通りです:
1818
19-[[d-list]]List::
20-<<d-pipeline,Pipeline>> ((+&&+ / +||+) <<d-n,N>>* Pipeline)*
21-<<d-list-separator,ListSeparator>>
19+`&` `&&` `(` `)` `;` `;;` `|` `||`
20+`<` `<<` `<&` `<(` `<<-` `<<<` `<>`
21+`>` `>>` `>&` `>(` `>>|` `>|` (改行)
2222
23-[[d-pipeline]]Pipeline::
24-<<d-bang,Bang>>? <<d-command,Command>> (+|+ <<d-n,N>>* Command)*
23+[NOTE]
24+他の一般的なプログラミング言語とは異なり、改行演算子は空白ではなくトークンとして扱われます。
2525
26-[[d-command]]Command::
27-<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>* / +
28-!<<d-r,R>> <<d-function-definition,FunctionDefinition>> / +
29-!R <<d-simple-command,SimpleCommand>>
26+空白ではなく演算子トークンの一部でもない文字は単語 (word) トークンとなります。単語は以下の解析表現文法によって解析されます。
3027
31-[[d-compound-command]]CompoundCommand::
32-<<d-subshell,Subshell>> / +
33-<<d-grouping,Grouping>> / +
34-<<d-if-command,IfCommand>> / +
35-<<d-for-command,ForCommand>> / +
36-<<d-while-command,WhileCommand>> / +
37-<<d-case-command,CaseCommand>> / +
38-<<d-function-command,FunctionCommand>>
39-
40-[[d-subshell]]Subshell::
41-+(+ <<d-sequence,Sequence>> +)+ <<d-s,S>>*
42-
43-[[d-grouping]]Grouping::
44-<<d-left-brace,LeftBrace>> <<d-sequence,Sequence>>
45-<<d-right-brace,RightBrace>>
46-
47-[[d-if-command]]IfCommand::
48-<<d-if,If>> <<d-sequence,Sequence>> <<d-then,Then>> Sequence
49-(<<d-elif,Elif>> Sequence <<d-then,Then>> Sequence)*
50-(<<d-else,Else>> Sequence)? <<d-fi,Fi>>
51-
52-[[d-for-command]]ForCommand::
53-<<d-for,For>> <<d-name,Name>> <<d-s,S>>* <<d-separator,Separator>>?
54-(<<d-in,In>> <<d-word,Word>>* <<d-separator,Separator>>)?
55-<<d-do,Do>> <<d-sequence,Sequence>> <<d-done,Done>>
56-
57-[[d-while-command]]WhileCommand::
58-(<<d-while,While>> / <<d-until,Until>>)
59-<<d-sequence,Sequence>> <<d-do,Do>> Sequence <<d-done,Done>>
60-
61-[[d-case-command]]CaseCommand::
62-<<d-case,Case>> <<d-word,Word>> <<d-n,N>>* <<d-in,In>> N*
63-<<d-case-item,CaseItem>>* <<d-esac,Esac>>
64-
65-[[d-case-item]]CaseItem::
66-!<<d-esac,Esac>> (+(+ <<d-s,S>>*)? <<d-word,Word>> (+|+ S* Word)* +)+
67-<<d-sequence,Sequence>> (+;;+ / &amp;Esac)
68-
69-[[d-function-command]]FunctionCommand::
70-<<d-function,Function>> <<d-word,Word>> (+(+ <<d-s,S>>* +)+)? <<d-n,N>>*
71-<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
72-
73-[[d-function-definition]]FunctionDefinition::
74-<<d-name,Name>> <<d-s,S>>* +(+ S* +)+ <<d-n,N>>*
75-<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
76-
77-[[d-simple-command]]SimpleCommand::
78-&(<<d-word,Word>> / <<d-redirection,Redirection>>)
79-(<<d-assignment,Assignment>> / Redirection)* (Word / Redirection)*
80-
81-[[d-assignment]]Assignment::
82-<<d-name,Name>> +=+ <<d-word,Word>> / +
83-Name +=(+ <<d-n,N>>* (Word N*)* +)+
84-
85-[[d-name]]Name::
86-!\[[:digit:]] [[:alnum:] +_+]+
87-
88-[[d-portable-name]]PortableName::
89-![++0++-++9++] [++0++-++9++ ++ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_++]+
90-
9128 [[d-word]]Word::
9229 (<<d-word-element,WordElement>> / !<<d-special-char,SpecialChar>> .)+
93-<<d-s,S>>*
9430
9531 [[d-word-element]]WordElement::
9632 +\+ . / +
@@ -101,10 +37,10 @@
10137 <<d-command-substitution,CommandSubstitution>>
10238
10339 [[d-quote-element]]QuoteElement::
104-+\+ ([+$&#96;"&#92;+] / <<d-nl,NL>>) / +
40++\+ ([+$&#96;"&#92;+] / <改行>) / +
10541 <<d-parameter,Parameter>> / +
10642 <<d-arithmetic,Arithmetic>> / +
107-<<d-command-substitution,CommandSubstitution>> / +
43+<<d-command-substitution-quoted,CommandSubstitutionQuoted>> / +
10844 ![+&#96;"&#92;+] .
10945
11046 [[d-parameter]]Parameter::
@@ -112,15 +48,18 @@
11248 +$+ <<d-portable-name,PortableName>> / +
11349 +$+ <<d-parameter-body,ParameterBody>>
11450
51+[[d-portable-name]]PortableName::
52+![++0++-++9++] [++0++-++9++ ++ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_++]+
53+
11554 [[d-parameter-body]]ParameterBody::
11655 +{+ <<d-parameter-number,ParameterNumber>>?
117-(<<d-parameter-name,ParameterName>> / ParameterBody /
118-<<d-parameter,Parameter>>)
56+(<<d-parameter-name,ParameterName>> / ParameterBody / +$+ ParameterBody /
57+<<d-arithmetic,Arithmetic>> / <<d-command-substitution,CommandSubstitution>>)
11958 <<d-parameter-index,ParameterIndex>>? <<d-parameter-match,ParameterMatch>>?
12059 +}+
12160
12261 [[d-parameter-number]]ParameterNumber::
123-`#` ![`+=:/%`] !([`-?#`] `}`)
62+`#` ![`}+=:/%`] !([`-?#`] !`}`)
12463
12564 [[d-parameter-name]]ParameterName::
12665 [+@*#?-$!+] / +
@@ -158,114 +97,159 @@
15897 ![+`()+] .
15998
16099 [[d-command-substitution]]CommandSubstitution::
161-+$(+ <<d-sequence,Sequence>> +)+ / +
100++$(+ <<d-complete-program,CompleteProgram>> +)+ / +
162101 +&#96;+ <<d-command-substitution-body,CommandSubstitutionBody>>* +&#96;+
163102
103+[[d-command-substitution-quoted]]CommandSubstitutionQuoted::
104++$(+ <<d-complete-program,CompleteProgram>> +)+ / +
105++&#96;+ <<d-command-substitution-body-quoted,CommandSubstitutionBodyQuoted>>*
106++&#96;+
107+
164108 [[d-command-substitution-body]]CommandSubstitutionBody::
165109 +\+ [+$&#96;\+] / +
166110 !++&#96;++ .
167111
168-[[d-redirection]]Redirection::
169-<<d-redirection-fd,RedirectionFD>>
170-<<d-redirection-operator,RedirectionOperator>> <<d-s,S>>* <<d-word,Word>> / +
171-RedirectionFD +<(+ <<d-sequence,Sequence>> +)+ / +
172-RedirectionFD +>(+ Sequence +)+
112+[[d-command-substitution-body-quoted]]CommandSubstitutionBodyQuoted::
113++\+ [+$&#96;\`+] / +
114+!++&#96;++ .
173115
174-[[d-redirection-fd]]RedirectionFD::
175-\[[:digit:]]*
116+[[d-special-char]]SpecialChar::
117+[+|&amp;;&lt;&gt;()&#96;&#92;"'+ [:blank:]] / <改行>
176118
177-[[d-redirection-operator]]RedirectionOperator::
178-`<` / `<>` / `>` / `>|` / `>>` / `>>|` / `<&` / `>&` / `<<` / `<<-` / `<<<`
119+この文法における終端記号の集合は、yash を実行する環境が扱える任意の文字の集合 (実行文字集合) です (ただしナル文字 `'\0'` を除く)。
179120
180-[[d-list-separator]]ListSeparator::
181-<<d-separator,Separator>> / +
182-+&amp;+ <<d-n,N>>* / +
183-&++)++ / +
184-&++;;++
121+厳密には、上記の文法定義は完全な解析表現文法ではありません。<<d-command-substitution,CommandSubstitution>> (<<d-command-substitution-quoted,Quoted>>) のルールが構文定義の非終端記号である <<d-complete-program,CompleteProgram>> に依存しているためです。
185122
186-[[d-separator]]Separator::
187-+;+ <<d-n,N>>* / +
188-<<d-n,N>>+ / +
189-<<d-eof,EOF>>
123+[[classification]]
124+=== トークン分類
190125
191-[[d-n]]N::
192-<<d-s,S>>* <<d-nl,NL>>
126+単語トークンが生成された後、単語はさらに IO_NUMBER トークン・予約語・名前・代入・通常の単語のどれかに分類されます。通常の単語以外の分類は、その単語が現れる文脈においてその分類のトークンが現れ得る場合のみ採用されます。予約語の一覧と予約語が認識される文脈の要件は、link:syntax.html#tokens[トークンの解析と予約語]を参照してください。
193127
194-[[d-s]]S::
195-\[[:blank:]] / +
196-<<d-comment,Comment>>
128+トークンが数字のみから構成されていて直後に +<+ または +>+ が続くとき、それは IO_NUMBER トークンとなります。
197129
130+代入 (assignment) トークンは名前 (name) とそれに続く +=+ で始まるトークンです:
131+
132+[[d-assignment-word]]AssignmentWord::
133+<<d-assignment-prefix,AssignmentPrefix>> <<d-word,Word>>
134+
135+[[d-assignment-prefix]]AssignmentPrefix::
136+<<d-name,Name>> +=+
137+
138+[[d-name]]Name::
139+!\[[:digit:]] \[[:alnum:] +_+]+
140+
141+[[comments]]
142+=== コメント
143+
144+コメントは `#` で始まり、次の改行文字の直前まで続きます。コメントは空白と同様に扱われ、トークンの一部にはなりません。コメントを開始する `#` は、トークンの始まりの位置にあるときのみ有効です。それ以外の位置にある `#` は単に単語トークンの一部と見做されます。
145+
198146 [[d-comment]]Comment::
199-+#+ (!<<d-nl,NL>> .)*
147+`#` (!<改行> .)*
200148
201-[[d-r]]R::
202-<<d-bang,Bang>> / <<d-left-brace,LeftBrace>> / <<d-right-brace,RightBrace>> /
203-<<d-case,Case>> / <<d-do,Do>> / <<d-done,Done>> / <<d-elif,Elif>> /
204-<<d-else,Else>> / <<d-esac,Esac>> / <<d-fi,Fi>> / <<d-for,For>> /
205-<<d-if,If>> / <<d-in,In>> / <<d-then,Then>> / <<d-until,Until>> /
206-<<d-while,While>>
149+[[syntax]]
150+== 構文
207151
208-[[d-bang]]Bang::
209-+!+ <<d-d,D>>
152+トークンが分割された後、その結果であるトークンの並びは以下に示す文脈自由文法によって解析されます。(以下、`*` と `+` と `?` は正規表現と同様の意味を持ちます)
210153
211-[[d-left-brace]]LeftBrace::
212-+{+ <<d-d,D>>
154+[[d-complete-program]]CompleteProgram::
155+<<d-nl,NL>>* | <<d-compound-list,CompoundList>>
213156
214-[[d-right-brace]]RightBrace::
215-+}+ <<d-d,D>>
157+[[d-compound-list]]CompoundList::
158+<<d-nl,NL>>* <<d-and-or-list,AndOrList>>
159+({zwsp}(+;+ | +&+ | NL) <<d-complete-program,CompleteProgram>>)?
216160
217-[[d-case]]Case::
218-+case+ <<d-d,D>>
161+[[d-and-or-list]]AndOrList::
162+<<d-pipeline,Pipeline>> &#40;(+&&+ | +||+) <<d-nl,NL>>* Pipeline)*
219163
220-[[d-do]]Do::
221-+do+ <<d-d,D>>
164+[[d-pipeline]]Pipeline::
165++!+? <<d-command,Command>> (+|+ <<d-nl,NL>>* Command)*
222166
223-[[d-done]]Done::
224-+done+ <<d-d,D>>
167+[[d-command]]Command::
168+<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>* | +
169+<<d-function-definition,FunctionDefinition>> | +
170+<<d-simple-command,SimpleCommand>>
225171
226-[[d-elif]]Elif::
227-+elif+ <<d-d,D>>
172+[[d-compound-command]]CompoundCommand::
173+<<d-subshell,Subshell>> | +
174+<<d-grouping,Grouping>> | +
175+<<d-if-command,IfCommand>> | +
176+<<d-for-command,ForCommand>> | +
177+<<d-while-command,WhileCommand>> | +
178+<<d-case-command,CaseCommand>> | +
179+<<d-function-command,FunctionCommand>>
228180
229-[[d-else]]Else::
230-+else+ <<d-d,D>>
181+[[d-subshell]]Subshell::
182++(+ <<d-compound-list,CompoundList>> +)+
231183
232-[[d-esac]]Esac::
233-+esac+ <<d-d,D>>
184+[[d-grouping]]Grouping::
185++{+ <<d-compound-list,CompoundList>> +}+
234186
235-[[d-fi]]Fi::
236-+fi+ <<d-d,D>>
187+[[d-if-command]]IfCommand::
188++if+ <<d-compound-list,CompoundList>> +then+ CompoundList
189+(+elif+ CompoundList +then+ CompoundList)*
190+(+else+ CompoundList)? +fi+
237191
238-[[d-for]]For::
239-+for+ <<d-d,D>>
192+[[d-for-command]]ForCommand::
193++for+ <<d-name,Name>>
194+({zwsp}(<<d-nl,NL>>* +in+ <<d-word,Word>>*)? (+;+ | NL) NL*)?
195++do+ <<d-compound-list,CompoundList>> +done+
240196
241-[[d-function]]Function::
242-+function+ <<d-d,D>>
197+[[d-while-command]]WhileCommand::
198+(+while+ | +until+) <<d-compound-list,CompoundList>> +do+ CompoundList +done+
243199
244-[[d-if]]If::
245-+if+ <<d-d,D>>
200+[[d-case-command]]CaseCommand::
201++case+ <<d-word,Word>> <<d-nl,NL>>* +in+ NL* <<d-case-list,CaseList>>? +esac+
246202
247-[[d-in]]In::
248-+in+ <<d-d,D>>
203+[[d-case-list]]CaseList::
204+<<d-case-item,CaseItem>> (+;;+ <<d-nl,NL>>* CaseList)?
249205
250-[[d-then]]Then::
251-+then+ <<d-d,D>>
206+[[d-case-item]]CaseItem::
207++(+? <<d-word,Word>> (+|+ Word)* +)+ <<d-complete-program,CompleteProgram>>
252208
253-[[d-until]]Until::
254-+until+ <<d-d,D>>
209+[[d-function-command]]FunctionCommand::
210++function+ <<d-word,Word>> (+(+ +)+)? <<d-nl,NL>>*
211+<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
255212
256-[[d-while]]While::
257-+while+ <<d-d,D>>
213+[[d-function-definition]]FunctionDefinition::
214+<<d-name,Name>> +(+ +)+ <<d-nl,NL>>*
215+<<d-compound-command,CompoundCommand>> <<d-redirection,Redirection>>*
258216
259-[[d-d]]D::
260-!<<d-word,Word>> <<d-s,S>>*
217+[[d-simple-command]]SimpleCommand::
218+(<<d-assignment,Assignment>> | <<d-redirection,Redirection>>) SimpleCommand?
219+| +
220+<<d-word,Word>> (Word | <<d-redirection,Redirection>>)*
261221
262-[[d-special-char]]SpecialChar::
263-[+|&amp;;&lt;&gt;()&#96;&#92;"'+ [:blank:]] / <<d-nl,NL>>
222+[[d-assignment]]Assignment::
223+<<d-assignment-word,AssignmentWord>> | +
224+<<d-assignment-prefix,AssignmentPrefix>>++(++
225+<<d-nl,NL>>* (<<d-word,Word>> NL*)* +)+
264226
227+[[d-redirection]]Redirection::
228+IO_NUMBER? <<d-redirection-operator,RedirectionOperator>> <<d-word,Word>> | +
229+IO_NUMBER? +<(+ <<d-complete-program,CompleteProgram>> +)+ | +
230+IO_NUMBER? +>(+ CompleteProgram +)+
231+
232+[[d-redirection-operator]]RedirectionOperator::
233+`<` | `<>` | `>` | `>|` | `>>` | `>>|` | `<&` | `>&` | `<<` | `<<-` | `<<<`
234+
265235 [[d-nl]]NL::
266-<newline>
236+<改行>
267237
268-[[d-eof]]EOF::
269-!.
238+ルール <<d-simple-command,SimpleCommand>> では、<<d-word,Word>> トークンはそれが <<d-assignment,Assignment>> の始まりとは解釈できない場合にのみ採用されます。
270239
240+ルール <<d-assignment,Assignment>> では、<<d-assignment-prefix,AssignmentPrefix>> と ++(++ の間に空白を置くことはできません。
241+
242+上記の文法定義にはlink:redir.html#here[ヒアドキュメント]の内容とその終わりを表す行の解析のための規則は含まれていません。それらは対応するリダイレクト演算子の後にある最初の改行 (<<d-nl,NL>>) トークンが解析された直後に解析されます。
243+
244+[[alias]]
245+=== エイリアス置換
246+
247+単語はlink:syntax.html#aliases[エイリアス置換]の対象となります。
248+
249+- 単語が <<d-simple-command,SimpleCommand>> の <<d-word,Word>> として解析されようとした時に、通常のエイリアス及びグローバルエイリアスを対象として置換が試みられます。
250+- 置換結果が空白文字 (blank) で終わるエイリアス置換の次に単語トークンがある場合、その単語も通常のエイリアス及びグローバルエイリアスを対象として置換が試みられます。
251+- その他の単語は、グローバルエイリアスのみを対象として置換が試みられます。(link:posix.html[POSIX 準拠モード]を除く)
252+
253+予約語に分類されたトークンはエイリアス置換の対象からは除外されます。
254+
271255 // vim: set filetype=asciidoc expandtab:
Show on old repository browser