Skip to content

Commit 208775b

Browse files
committed
Translated a bit more of chapter 10. Fixed some spelling errors
1 parent 5ddb830 commit 208775b

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

chapter10.textile

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ the C pre-processor.
2727

2828
!images/ch_parser_build.png(Parser construction process)!
2929

30-
h3. Disecting `parse.y`
30+
h3. Dissecting `parse.y`
3131

3232
Let's now look at `parse.y` in a bit more detail. The following figure presents
3333
a rough outline of the contents of `parse.y`.
@@ -147,12 +147,12 @@ to represent them.
147147
|Function definition|`defun definition function fndef`|
148148
|Declarations|`declaration decl`|
149149

150-
In general, programming lanaguages tend to have the following symbol heiarchy.
150+
In general, programming languages tend to have the following symbol hierarchy.
151151

152152
|Program element|Properties|
153153
|Statement|Can not be combined with other symbols. A syntax tree trunk.|
154154
|Expression|Can be combined with itself or be part of other
155-
expressions. A syntax tree interal node.|
155+
expressions. A syntax tree internal node.|
156156
|Primary|An element which can not be further decomposed. A syntax tree leaf node.|
157157

158158
C function definitions and Java class definitions are examples of statements in
@@ -179,8 +179,8 @@ h3. Program structure
179179
Now let's turn our attention to the grammer rules of `ruby`. Firstly,
180180
`yacc` will begin by examining the first rule defined in `parse.y`, and as
181181
we can see from the following table, this is `program`. From here we can see
182-
the ruby grammar unfold and the existance of the `program stmt expr primary`
183-
heierarchy mentioned earlier. However there is an extra rule here for `arg`.
182+
the ruby grammar unfold and the existence of the `program stmt expr primary`
183+
hierarchy mentioned earlier. However there is an extra rule here for `arg`.
184184
Let's now take a look at this.
185185

186186
▼ `ruby` grammar (outline)
@@ -330,9 +330,9 @@ term : ';'
330330
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.
331331

332332
<pre class="emlist">
333-
1 + 1 # 改行一つめ
334-
# 改行二つめ
335-
# 改行三つめ
333+
1 + 1 # first newline
334+
# second newline
335+
# third newline
336336
1 + 1
337337
</pre>
338338

@@ -343,17 +343,15 @@ Run that with `ruby -c`.
343343
Syntax OK
344344
</pre>
345345

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.
346+
Strange, it worked! What actually happens is this: consecutive newlines are simply discarded by the scanner, which returns only the first newline in a series.
347347

348348
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.
349349

350-
これを一般化すると、規則には見ための解析のために必要なものと、アクショ
351-
ンを実行するために必要なものの二種類があるということになる。`stmts`のと
352-
ころにある`none`もアクションのために必要な規則の一つで、空リストに対して
353-
(`NODE*`型の)`NULL`ポインタを返すために用意されている。
350+
To generalize this point, the grammar rules can be divided into 2 groups: those which are needed for parsing the program structure, and those which are needed for execution of semantic actions. The `none` rule which was mentioned earlier when talking about `stmts` is another one which exists for executing actions -- it's used to return a `NULL` pointer for an empty list of type `NODE*`.
354351

355352
h3. `stmt`
356353

354+
Next is `stmt`. *** We'll look into it a bit at a time.
357355
次に文、`stmt`だ。`stmt`の規則はわりと量があるので、少しずつ見ていく
358356
ことにする。
359357

@@ -373,18 +371,11 @@ stmt : kALIAS fitem fitem
373371
| klEND '{' compstmt '}'
374372
</pre>
375373

376-
なんとなくわかる。最初にいくつかあるのは`alias`だし、
377-
次が`undef`、その後にいくつか並ぶ「なんたら`_MOD`」は
378-
modifier(修飾子)のことだろうから、後置系構文だと想像が付く。
374+
Looking at that, somehow things start to make sense. The first few have `alias`, then `undef`, then the next few are all something followed by `_MOD` -- those should be statements with modifiers -- 後置系構文だと想像が付く。
379375

380-
`expr_value`や`primary_value`はアクションのために用意されている規則である。
381-
例えば`expr_value`なら値(value)を持つ`expr`であることを示す。値
382-
を持たない`expr`とは`return`や`break`、あるいはそういうものを含む`if`文
383-
などのことだ。「値を持つ」の詳しい定義は
384-
第12章『構文木の構築』で見る。
385-
`primary_value`も同じく「値を持つ」`primary`である。
376+
`expr_value` and `primary_value` are grammar rules which exist to execute semantic actions. For example, `expr_value` represents an `expr` which has a value. Expressions which don't have values are `return` and `break`, as well as `if`-modifier statements, etc., which contain either `return` or `break`. For a detailed definition of what it means to "have a value", see chapter 12 『構文木の構築』. In the same way, `primary_value` is a `primary` which has a value.
386377

387-
`klBEGIN``klEND`は説明した通り`BEGIN``END`のこと。
378+
Just as they say, `klBEGIN` and `klEND` represent `BEGIN` and `END`.
388379

389380
▼ `stmt`(2)
390381
<pre class="longlist">
@@ -464,7 +455,7 @@ expr kAND expr
464455
expr kOR expr
465456
</pre>
466457

467-
`kAND`は「`and`」で`kOR`は「`or`」。この二つは制御構造としての役割があ
458+
`kAND` is `and`, and `kOR` is `or`. この二つは制御構造としての役割があ
468459
るので、`command_call`以上に「大きい」構文単位に入れなければならない。
469460
そして`command_call`は`expr`にある。だから最低でも`expr`にしてやらない
470461
とうまくいかない。例えば次のような使いかたが存在するのだが……
@@ -528,7 +519,7 @@ arg : lhs '=' arg
528519
| primary
529520
</pre>
530521

531-
規則の数は多いが、文法の複雑さは規則の数には比例しない。単に場合分けが
522+
Although there are many rules here, the complexity of the grammar is not in proportion to the number of rules. 単に場合分けが
532523
多いだけの文法は`yacc`にとっては非常に扱いやすく、むしろ規則の深さである
533524
とか再帰のほうが複雑さに影響する。
534525

0 commit comments

Comments
 (0)