You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
`terms` is (of course) an abbreviation for "terminators", either semicolons or newlines.
316
+
`opt_terms` means "OPTional terms". The definitions are as follows:
321
317
322
318
▼ `opt_terms`
323
319
<pre class="longlist">
@@ -331,9 +327,7 @@ term : ';'
331
327
| '\n'
332
328
</pre>
333
329
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.
337
331
338
332
<pre class="emlist">
339
333
1 + 1 # 改行一つめ
@@ -342,21 +336,16 @@ term : ';'
342
336
1 + 1
343
337
</pre>
344
338
345
-
再び`ruby -c`を使う。
339
+
Run that with `ruby -c`.
346
340
347
341
<pre class="screen">
348
342
% ruby -c optterms.rb
349
343
Syntax OK
350
344
</pre>
351
345
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.
354
347
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.
0 commit comments