Skip to content

Commit eccda44

Browse files
committed
some more lesson 6 grammar fixes
1 parent 1176c39 commit eccda44

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

tutorial/en/6-Functions.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
We've already seen how variable definitions are parsed in our interpreter. Now
2-
it's time for function definitions. (note it is definition, not declaration,
3-
thus our interpreter don't support recursion across functions.)
2+
it's time for function definitions (note it is definition, not declaration,
3+
thus our interpreter doesn't support recursion across functions).
44

55
## EBNF Grammar
66

7-
Let's start be refreshing our memories about EBNF grammar introduced in last
7+
Let's start by refreshing our memory of the EBNF grammar introduced in last
88
chapter, we've already implement `program`, `global_declaration` and
99
`enum_decl`. We'll deal with part of `variable_decl`, `function_decl`,
10-
`parameter_decl` and `body_decl`. The rest will be covered in next chapter.
10+
`parameter_decl` and `body_decl`. The rest will be covered in the next chapter.
1111

1212
```
1313
variable_decl ::= type {'*'} id { ',' {'*'} id } ';'
@@ -43,7 +43,7 @@ if (token == '(') {
4343
...
4444
```
4545
46-
The type for current identifier (i.e. function name) had already been set
46+
The type for the current identifier (i.e. function name) had already been set
4747
correctly. The above chunk of code set the type (i.e. `Fun`) and the
4848
address in `text segment` for the function. Here comes `parameter_decl` and
4949
`body_decl`.
@@ -84,10 +84,10 @@ following (please refer to the VM of chapter 2):
8484
```
8585

8686
The key point here is no matter if it is a parameter (e.g. `param_a`) or local
87-
variable (e.g. `local_1`), they are all store on **stack**. Thus they are
88-
referred to by pointer `new_bp` and relative shfitment, while global variables
87+
variable (e.g. `local_1`), they are all stored on the **stack**. Thus they are
88+
referred to by the pointer `new_bp` and relative offsets, while global variables
8989
which are stored in `text segment` are refered to by direct address. So we
90-
need to know the number of parameters and the shiftment of each.
90+
need to know the number of parameters and the offset of each.
9191

9292
## Skeleton for Parsing Function
9393

@@ -118,7 +118,7 @@ void function_declaration() {
118118
```
119119

120120
Note that we are supposed to consume the last `}` character in ①. But we don't
121-
because `variable_decl` and `function_decl` are parsed together(because of the
121+
because `variable_decl` and `function_decl` are parsed together (because of the
122122
same prefix in EBNF grammar) inside `global_declaration`. `variable_decl` ends
123123
with `;` while `function_decl` ends with `}`. If `}` is consumed, the `while`
124124
loop in `global_declaration` won't be able to know that a `function_decl`
@@ -296,7 +296,7 @@ The code of this chapter isn't long, most of the part are used to parse
296296
variables and much of them are duplicated. The parsing for parameter and local
297297
variables are almost the same, but the stored information are different.
298298

299-
Of course, you may want to review the VM chapter(chapter 2) to get better
299+
Of course, you may want to review the VM chapter (chapter 2) to get better
300300
understanding of the expected output for function, so as to understand why
301301
would we want to gather such information. This is what we called
302302
"domain knowledge".

0 commit comments

Comments
 (0)