Skip to content

Commit 352b9a3

Browse files
committed
some lesson 4 grammar fixes
1 parent 4a93869 commit 352b9a3

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

tutorial/en/4-Top-down-Parsing.md

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
In this chapter we will build a simple calculator using the top-down parsing
22
technique. This is the preparation before we start to implement the parser.
33

4-
I will introduce a small set of theories but not gurantee to be absolute
4+
I will introduce a small set of theories but will not gurantee to be absolutely
55
correct, please consult your textbook if you have any confusion.
66

77
## Top-down parsing
88

9-
Traditionally, we have top-down parsing and bottom-up parsing. Top-down method
10-
will start with a non-terminator and recursively check the source code to
9+
Traditionally, we have top-down parsing and bottom-up parsing. The top-down
10+
method will start with a non-terminator and recursively check the source code to
1111
replace the non-terminators with its alternatives until no non-terminator is
1212
left.
1313

1414
You see I used the top-down method for explaining "top-down" because you'll
15-
have to know what a "non-terminator" is to understand the above graph. But I
16-
havn't tell you what that is. We will tell in the next section. For now,
17-
consider "top-down" is try to tear down a big object into small pieces.
15+
have to know what a "non-terminator" is to understand the above paragraph. But I
16+
havn't told you what that is. We will explain in the next section. For now,
17+
consider "top-down" is trying to tear down a big object into small pieces.
1818

1919
On the other hand "bottom-up" parsing is trying to combine small objects into
2020
a big one. It is often used in automation tools that generate parsers.
@@ -39,17 +39,17 @@ arithmetic calulater in BNF will be:
3939
| Num
4040
```
4141

42-
The one enbraced by `<>` is called a `Non-terminator`. They got the name
43-
because we can replace them with the ones on the right hand of `::=`.
42+
The item enclosed by `<>` is called a `Non-terminator`. They got the name
43+
because we can replace them with the items on the right hand of `::=`.
4444
`|` means alternative that means you can replace `<term>` with any one of
4545
`<term> * <factor>`, `<term> / <factor>` or `<factor>`. Those do not appear on
4646
the left side of `::=` is called `Terminator` such as `+`, `(`, `Num`, etc.
47-
They often corresponds to the tokens we got from lexer.
47+
They often corresponds to the tokens we got from the lexer.
4848

4949
## Top-down Example for Simple Calculator
5050

51-
Parse tree is the inner structure we got after the parser consumes all the
52-
tokens and finish all the parsing. Let's take `3 * (4 + 2)` as an example to
51+
The parse tree is the inner structure we get after the parser consumes all the
52+
tokens and finishes all the parsing. Let's take `3 * (4 + 2)` as an example to
5353
show the connections between BNF grammer, parse tree and top-down parsing.
5454

5555
Top-down parsing starts from a starting non-terminator which is `<term>` in
@@ -71,8 +71,8 @@ non-terminator we encountered.
7171
```
7272

7373
You can see that each step we replace a non-terminator using one of its
74-
alternatives(top-down) Until all of the sub-items are replaced to
75-
terminators(bottom). Some non-terminators are used recursively such as
74+
alternatives (top-down) Until all of the sub-items are replaced by
75+
terminators (bottom). Some non-terminators are used recursively such as
7676
`<expr>`.
7777

7878
## Advantages of Top-down Parsing
@@ -110,7 +110,7 @@ As you can see, function `expr` will never exit! In the grammar,
110110
non-terminator `<expr>` is used recursively and appears immediately after
111111
`::=` which causes left-recursion.
112112

113-
Lucily, most left-recursive grammers(maybe all? I don't remember) can be
113+
Lucily, most left-recursive grammers (maybe all? I don't remember) can be
114114
properly transformed into non left-recursive equivalent ones. Our grammar for
115115
calculator can be converted into:
116116

@@ -254,7 +254,7 @@ int main(int argc, char *argv[])
254254
255255
You can play with your own calculator now. Or try to add some more functions
256256
based on what we've learned in the previous chapter. Such as variable support
257-
so that user can define variable to store values.
257+
so that a user can define variables to store values.
258258
259259
## Summary
260260

0 commit comments

Comments
 (0)