Skip to content

Commit 5ddb830

Browse files
committed
Translated a few paragraphs of chapter 10
1 parent 3c85843 commit 5ddb830

File tree

1 file changed

+10
-21
lines changed

1 file changed

+10
-21
lines changed

chapter10.textile

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -307,17 +307,13 @@ stmts : none
307307
| stmts terms stmt
308308
</pre>
309309

310-
As mentioned earlier, `program` represents an entire program in the grammar.
311-
For all intents and purposes `compstmts` is equivilent to `program`.
310+
As mentioned earlier, in the grammar, `program` represents an entire program.
311+
For all intents and purposes `compstmts` is equivalent to `program`. `stmts` is
312+
almost equivalent to `compstmts`. In turn, `stmts` is a list of `stmt` nonterminals,
313+
delimited by `terms`.
312314

313-
前述の通り`program`は文法全体、即ちプログラム全体を表している。その
314-
`program`は`compstmts`と同じであり、`compstmts`は`stmts`とほぼ同じである。
315-
その`stmts`は`terms`区切りの`stmt`のリストである。つまりプログラム全体は
316-
`terms`区切りの`stmt`のリストである。
317-
318-
`terms`はもちろんterminatorsの略で、文を終端する記号、セミコロンだとか
319-
改行のことだ。`opt_terms`はOPTional `terms`(省略可能な`terms`)だろう。
320-
定義は次のようになっている。
315+
`terms` is (of course) an abbreviation for "terminators", either semicolons or newlines.
316+
`opt_terms` means "OPTional terms". The definitions are as follows:
321317

322318
▼ `opt_terms`
323319
<pre class="longlist">
@@ -331,9 +327,7 @@ term : ';'
331327
| '\n'
332328
</pre>
333329

334-
`terms`は`';'`か`'\n'`の後に任意の数だけ`';'`が続く並びなので、
335-
この規則だけから考えると二個以上の改行があるとまずいように
336-
思える。実際に試してみよう。
330+
The initial `;` or `\n` of a `terms` can be followed by any number of `;` only; based on that, you might start thinking that if there are 2 or more consecutive newlines, it could cause a problem. Let's try and see what actually happens.
337331

338332
<pre class="emlist">
339333
1 + 1 # 改行一つめ
@@ -342,21 +336,16 @@ term : ';'
342336
1 + 1
343337
</pre>
344338

345-
再び`ruby -c`を使う。
339+
Run that with `ruby -c`.
346340

347341
<pre class="screen">
348342
% ruby -c optterms.rb
349343
Syntax OK
350344
</pre>
351345

352-
おかしい。通ってしまった。実を言うと、連続した改行はスキャナのレベルで
353-
捨てられてしまってパーサには最初の一つしか渡らないようになっているのだ。
346+
Strange, it worked! What actually happens is: consecutive newlines are discarded by the scanner, which passes on only the first newline in a series.
354347

355-
ところで、`program`と`compstmt`は同じものだと言ったが、それならこの規則は
356-
何のために存在するのだろう。実はこれはアクションを実行するためだけにあ
357-
るのだ。例えば`program`ならプログラム全体について一度だけ必要な処理を実
358-
行するために用意されている。純粋に文法のことだけ考えるなら`program`は省
359-
略しても全く問題ない。
348+
By the way, although we said that `program` is the same as `compstmt`, if that was really true, you would question why `compstmt` exists at all. Actually, the distinction is there only for execution of semantic actions. `program` exists to execute any semantic actions which should be done once in the processing of an entire program. If it was only a question of parsing, `program` could be omitted with no problems at all.
360349

361350
これを一般化すると、規則には見ための解析のために必要なものと、アクショ
362351
ンを実行するために必要なものの二種類があるということになる。`stmts`のと

0 commit comments

Comments
 (0)