Skip to content

Commit c632331

Browse files
committed
Corrections to grammar/spelling, translated a couple more paragraphs
1 parent d1763cc commit c632331

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

chapter10.textile

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ h3. Parser construction
1414
The parser is defined in the `yacc` source file `parse.y`, which `yacc` uses to
1515
produce a working parser, `parse.c`.
1616

17-
Although one would expect `lex.c` to contain the scanner this is not the case.
17+
Although one would expect `lex.c` to contain the scanner, this is not the case.
1818
This file is created by `gperf`, taking the file `keywords` as input, and
1919
defines the reserved word hashtable. This tool-generated `lex.c` is `#include`d
2020
in (the also tool-generated) `parse.c`. The details of this process is somewhat
2121
difficult to explain at this time, so we shall return to this later.
2222

23-
Figure 1 shows the parser construction process. For the benifit of those readers
23+
Figure 1 shows the parser construction process. For the benefit of those readers
2424
using Windows who may not be aware, the `mv` (move) command creates a new copy
2525
of a file and removes the original. `cc` is, of course, the C compiler and `cpp`
2626
the C pre-processor.
@@ -59,8 +59,8 @@ Previously we briefly mentioned the rules and user code sections. With this
5959
chapter we begin to study the parser in some detail and so turn our attention to
6060
these sections.
6161

62-
There is a considerable number of support functions defined in the user code
63-
section, however roughly speaking they can be divided into the six parts
62+
There are a considerable number of support functions defined in the user code
63+
section, but roughly speaking, they can be divided into the six parts
6464
previously mentioned. The following table shows where each of parts are
6565
explained in this book.
6666

@@ -103,7 +103,7 @@ symbol names were required.
103103

104104
h3. Important symbols
105105

106-
`parse.y` contains both grammar rules and actions, however for now I would like
106+
`parse.y` contains both grammar rules and actions, however, for now I would like
107107
to concentrate on the grammar rules alone. The script sample/exyacc.rb can be
108108
used to extract the grammar rules from this file. Aside from this, running `yacc
109109
-v` will create a logfile `y.output` which also contains the grammar rules,
@@ -130,7 +130,7 @@ only included the most important parts in this chapter.
130130

131131
Which symbols, then, are the most important? Symbols such as `program`, `expr`,
132132
`stmt`,`primary`, `arg` etc. represent the more general grammatical elements of
133-
a programming language and it is to these which we shall focus our attention.
133+
a programming language and it is on these which we shall focus our attention.
134134
The following table outlines these general elements and the symbol names used
135135
to represent them.
136136

@@ -157,15 +157,15 @@ expressions. A syntax tree internal node.|
157157

158158
C function definitions and Java class definitions are examples of statements in
159159
other languages. An expression can be a procedure call, an arithmetic expression
160-
etc. while a primary usually refers to a string literal or number. Some languages
160+
etc., while a primary usually refers to a string literal or number. Some languages
161161
do not contain all of these symbol types, however they generally contain some
162162
kind of hierarchy of symbols such as `program`→`stmt`→`expr`→`primary`.
163163

164-
It is often the case that symbol types lower in this heirarchy can be promoted
164+
It is often the case that symbol types lower in this hierarchy can be promoted
165165
to higher levels and vice versa. For example, in C function calls are expressions
166166
yet can be may also be statements.
167167

168-
Conversely, when surrounded in parenthesis expressions become primaries.
168+
Conversely, when surrounded in parentheses, expressions become primaries.
169169

170170
Scoping rules differ considerably between programming languages. Consider
171171
substitution. In C, the value of expressions can be used in substitutions
@@ -176,7 +176,7 @@ expressions. Ruby follows Lisp's design in this regard.
176176

177177
h3. Program structure
178178

179-
Now let's turn our attention to the grammer rules of `ruby`. Firstly,
179+
Now let's turn our attention to the grammar 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
182182
the ruby grammar unfold and the existence of the `program stmt expr primary`
@@ -283,7 +283,7 @@ output.
283283
Syntax OK
284284
</pre>
285285

286-
Although it might look surprising at first, yes you really can do this in Ruby!
286+
Although it might look surprising at first, yes, you really can do this in Ruby!
287287

288288
The details of this are covered when we look at semantic analysis (in Chaper 12
289289
"Syntax tree construction") however it is important to note there are exceptions
@@ -351,9 +351,7 @@ To generalize this point, the grammar rules can be divided into 2 groups: those
351351

352352
h3. `stmt`
353353

354-
Next is `stmt`. *** We'll look into it a bit at a time.
355-
次に文、`stmt`だ。`stmt`の規則はわりと量があるので、少しずつ見ていく
356-
ことにする。
354+
Next is `stmt`. This one is rather involved, so we'll look into it a bit at a time.
357355

358356
▼ `stmt`(1)
359357
<pre class="longlist">
@@ -371,11 +369,11 @@ stmt : kALIAS fitem fitem
371369
| klEND '{' compstmt '}'
372370
</pre>
373371

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 -- 後置系構文だと想像が付く。
372+
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 postposition modifiers, as you can imagine.
375373

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.
374+
`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`, or `return`/`break` followed by a postposition modifier, such as an `if` clause. For a detailed definition of what it means to "have a value", see chapter 12, "Syntax Tree Construction". In the same way, `primary_value` is a `primary` which has a value.
377375

378-
Just as they say, `klBEGIN` and `klEND` represent `BEGIN` and `END`.
376+
Just as the names say, `klBEGIN` and `klEND` represent `BEGIN` and `END`.
379377

380378
▼ `stmt`(2)
381379
<pre class="longlist">
@@ -390,17 +388,15 @@ Just as they say, `klBEGIN` and `klEND` represent `BEGIN` and `END`.
390388
</pre>
391389

392390
この規則は全部くくって見るのが正しい。
393-
共通点は右辺に`command_call`が来る代入であることだ。
394-
`command_call`は引数括弧を省略したメソッド呼び出しである。
395-
新しく出てきた記号は以下に表を置いておくので対照しながら確かめてほしい。
396-
397-
|`lhs`|代入の左辺(Left Hand Side)|
398-
|`mlhs`|多重代入の左辺(Multiple Left Hand Side)|
399-
|`var_lhs`|代入の左辺、ただし変数系のみ(VARiable Left Hand Side)|
400-
|`tOP_ASGN`|`+=`や`*=`など組み合わせ代入記号(OPerator ASsiGN)|
401-
|`aref_args`|`[]`メソッド呼び出しの引数に使える表現(Array REFerence)|
402-
|`tIDENTIFIER`|ローカル変数に使える識別子|
403-
|`tCONSTANT`|定数に使える識別子(一文字目が大文字)|
391+
The common point is that they all have `command_call` on the right-hand side. `command_call` represents a method call with the parentheses omitted. The new symbols which are introduced here are explained in the following table. I hope you'll refer to the table as you check over each grammar rule.
392+
393+
|`lhs`|assignment left hand side|
394+
|`mlhs`|assignment multiple left hand side|
395+
|`var_lhs`|assignment left hand side, which must be a variable|
396+
|`tOP_ASGN`|compound assignment operator like `+=` or `*=` (OPerator ASsiGN)|
397+
|`aref_args`|argument to a `[]` method call (Array REFerence)|
398+
|`tIDENTIFIER`|local variable identifier|
399+
|`tCONSTANT`|constant identifier (with leading uppercase letter)|
404400
|`tCOLON2`|`::`|
405401
|`backref`|`$1 $2 $3...`|
406402

@@ -519,7 +515,7 @@ arg : lhs '=' arg
519515
| primary
520516
</pre>
521517

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

@@ -565,7 +561,7 @@ arg: lhs '=' arg /* 1 */
565561

566562
h3. `primary`
567563

568-
`primary`は規則が多いので最初から分割して示す。
564+
Because `primary` has a lot of grammar rules, we'll split them up and show them in parts.
569565

570566
▼ `primary`(1)
571567
<pre class="longlist">

0 commit comments

Comments
 (0)