Skip to content

Commit e0c1904

Browse files
authored
Merge pull request #30 from tesivo/master
Corrections
2 parents aad5dd1 + 62905d9 commit e0c1904

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

tutorial/en/1-Skeleton.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
In this chapter we will have an overview of the compiler's structure.
22

33
Before we start, I'd like to restress that it is **interperter** that we want
4-
to build. That means we can run a C source file just lik a script. It is
4+
to build. That means we can run a C source file just like a script. It is
55
chosen mainly for two reasons:
66

77
1. Interpreter differs from Compiler only in code generation phase, thus we'll
@@ -41,7 +41,7 @@ Modeling after c4, our compiler includes 4 main functions:
4141
1. `next()` for lexical analysis; get the next token; will ignore spaces tabs
4242
etc.
4343
2. `program()` main entrance for parser.
44-
3. `expression(level)`: parse expression; level will be explained in later
44+
3. `expression(level)`: parser expression; level will be explained in later
4545
chapter.
4646
4. `eval()`: the entrance for virtual machine; used to interpret target
4747
instructions.
@@ -57,6 +57,7 @@ The code is as following:
5757
#include <stdlib.h>
5858
#include <memory.h>
5959
#include <string.h>
60+
#define int long long // work with 64bit target
6061

6162
int token; // current token
6263
char *src, *old_src; // pointer to source code string;

tutorial/en/2-Virtual-Machine.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ Let's implement it in the `eval` function:
223223
void eval() {
224224
int op, *tmp;
225225
while (1) {
226+
op = *pc++; // get next operation code
226227
if (op == IMM) {ax = *pc++;} // load immediate value to ax
227228
else if (op == LC) {ax = *(char *)ax;} // load character to ax, address in ax
228229
else if (op == LI) {ax = *(int *)ax;} // load integer to ax, address in ax
@@ -302,7 +303,7 @@ We've commented out `RET` because we'll replace it with `LEV` later.
302303
In practice the compiler should deal with more: how to pass the arguments to
303304
a function? How to return the data from the function?
304305

305-
Our convention here about returning value is to store it into `AX` no mater
306+
Our convention here about returning value is to store it into `AX` no matter
306307
you're returning a value or a memory address. Then how about argument?
307308

308309
Different language has different convension, here is the standard for C:

tutorial/en/3-Lexer.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Let's first look at the structure of a compiler:
1818
```
1919

2020
The Compiler can be treated as a transformer that transform C source code into
21-
assembly. In this sense, lexer can parser are transformers as well: Lexer
21+
assembly. In this sense, lexer and parser are transformers as well: Lexer
2222
takes C source code as input and output token stream; Parser will consume the
2323
token stream and generate assembly code.
2424

@@ -519,7 +519,7 @@ information. In the main function, add the following:
519519
// types of variable/function
520520
enum { CHAR, INT, PTR };
521521
int *idmain; // the `main` function
522-
void main() {
522+
int main(int argc, char **argv) {
523523
...
524524

525525
src = "char else enum if int return sizeof while "
@@ -547,6 +547,7 @@ void main() {
547547

548548
...
549549
program();
550+
return eval();
550551
}
551552
```
552553

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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+
Luckly, 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

0 commit comments

Comments
 (0)