Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Proto.kr
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,40 @@
결과는 0이에요.
수는 정수예요.
수를 1부터 끝까지 세면서 {
수를 제곱해서 결과를 더해서 결과에 넣어요.
결과는 수를 제곱해서 결과를 더한 값이에요.
}
결과를 반환해요.
}

정수를 반환하는 main() {
결과는 정수예요.

3과 4를 더해서 결과에 넣어요.
결과에 (결과 * 5)를 넣어요. // plain arithmetic, no call
결과는 3과 4를 더한 값이에요.
결과는 (결과 * 5)예요. // plain arithmetic, no call
"%ld\n"과 결과를 printf해요. // (3 + 4) * 5 = 35
"%ld\n"과 ((결과 << 1) ^ 3)을 printf해요. // C operators: (35 << 1) ^ 3 = 69

7과 3을 비교해서 결과에 넣어요.
결과는 7과 3을 비교한 값이에요.
"%ld\n"과 결과를 printf해요. // 1

고정된 끝은 10이에요.
끝을 합해서 결과에 넣어요.
결과는 끝을 합한 값이에요.
"%ld\n"과 결과를 printf해요. // 1² + … + 9² = 285

// even numbers from 1 to 끝 (excluded)
개수는 0이에요.
수는 정수예요.
수를 1부터 끝까지 세면서 {
만약 수 % 2 == 0이면 {
개수와 1을 더해서 개수에 넣어요.
개수는 개수와 1을 더한 값이에요.
}
}
"%ld\n"과 개수를 printf해요. // 2, 4, 6, 8: 4

// first power of 2 above 100
숫자는 1이에요.
숫자 < 100인 동안 {
숫자에 (숫자 * 2)를 넣어요.
숫자는 (숫자 * 2)예요.
}
"%ld\n"과 숫자를 printf해요. // 128

Expand All @@ -82,7 +82,7 @@

// floating-point numbers
평균은 소수예요.
1.5와 -2.25를 평균해서 평균에 넣어요.
평균은 1.5와 -2.25를 평균한 값이에요.
"%f\n"과 평균을 printf해요. // (1.5 - 2.25) / 2 = -0.375

0을 반환해요.
Expand Down
8 changes: 4 additions & 4 deletions README.ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ELF 목적 파일을 만듭니다. 중앙대학교(CAU) 컴파일러 수업에
두 정수 가와 나를 받아 나누고 정수를 반환 {
나머지는 정수예요.
(나 == 0)이 아닌 동안 {
나머지에 (가 % 나)를 넣어요.
가에 나를 넣어요.
나에 나머지를 넣어요.
나머지는 (가 % 나)예요.
가는 나예요.
나는 나머지예요.
}
가를 반환해요.
}
Expand All @@ -27,7 +27,7 @@ ELF 목적 파일을 만듭니다. 중앙대학교(CAU) 컴파일러 수업에

- **함수는 동사입니다.** 호출을 중첩하지 않고 문장처럼 이어서 씁니다:
`3과 4를 더해서 제곱해서 반환해요`
- **인자에는 조사가 붙습니다.** 예: `나머지에 (가 % 나)를 넣어요`
- **인자에는 조사가 붙습니다.** 예: `48과 18을 나눈 값이에요`
- **문장은 해요체로 끝납니다.** 예: `42를 반환해요.`
- **libc 함수는 라틴 문자 이름에 `하다`를 붙여 호출합니다.** 예: `"%ld\n"과 가를 printf해요.`

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ Rust that produces x86-64 Linux ELF object files. Originally made for the Compil
두 정수 가와 나를 받아 나누고 정수를 반환 {
나머지는 정수예요.
(나 == 0)이 아닌 동안 {
나머지에 (가 % 나)를 넣어요.
가에 나를 넣어요.
나에 나머지를 넣어요.
나머지는 (가 % 나)예요.
가는 나예요.
나는 나머지예요.
}
가를 반환해요.
}
Expand Down
41 changes: 21 additions & 20 deletions docs/LANGUAGE_DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ to `printf`).
Decisions already made:

- Identifiers do not accept digits (hangul, latin and `_`).
- Speech level: 해요체 in function bodies (`예요`, `반환해요`, `넣어요`…). The sentence declaration
- Speech level: 해요체 in function bodies (`예요`, `반환해요`, `더해요`…). The sentence declaration
reads like a line of a specification and ends with the noun `반환` (see
[Sentence declaration](#sentence-declaration)).
- End of statement: the ending in `요` ends the statement, no `;`. A `.` is accepted right after
Expand All @@ -26,8 +26,8 @@ Decisions already made:
attached.
- Plain arithmetic is always possible: wherever a value is expected (assignment, argument, return,
declaration, condition), an expression with operators is accepted, without going through a
function. Between parentheses if a particle follows: `개수에 (개수 + 1)을 넣어요` (`a = a + 1`),
`결과에 (가 * 나)를 넣어요` (`a = b * c`).
function. Between parentheses if a particle follows: `개수는 (개수 + 1)이에요` (`a = a + 1`),
`결과는 (가 * 나)예요` (`a = b * c`).
- Negative number: `-5` is a simple term (`-5를 반환해요`). The `-` stays a separate token in the
lexer (otherwise `가-5` would give `가` then `-5`); the parser attaches `-` to a number. `-가`
stays an expression: `(-가)를 반환해요`.
Expand Down Expand Up @@ -302,7 +302,7 @@ choice against the 받침 (`나을` → "받침이 없으니 '를'을 쓰세요"
| | Concept | Word | Notes |
| --- | --- | --- | --- |
| ★ | function | `TYPE을/를 반환하는 VERB다(TYPE name, …) { … }` | "VERB, which gives a TYPE"; without return: `VERB다(…) { … }` |
| | variable | `NAME은/는 VALUE이에요/예요` or `NAME은/는 TYPE이에요/예요` | with a value: deduced type (`0` → `정수`, `0.5` → `소수`); with a type: default value (zero of the type); `이에요` after a consonant, `예요` after a vowel; mutable by default |
| | variable | `NAME은/는 VALUE이에요/예요` or `NAME은/는 TYPE이에요/예요` | with a value: deduced type (`0` → `정수`, `0.5` → `소수`); with a type: default value (zero of the type); `이에요` after a consonant, `예요` after a vowel; mutable by default; with a value on a name already declared: a new value (see Modifiers) |
| | constant | `고정된 NAME은/는 VALUE이에요/예요` | see Modifiers |
| | function of another file | `TYPE을/를 반환하는 VERB다(TYPE name, …)` | no body, no `외부`: defined in another file of the program, see Several files |
| ★ | external function (libc) | `외부 TYPE을/를 반환하는 name(TYPE name, …)` | latin name only (`외부` is for the libc), no body; `…` for variadics: `외부 정수를 반환하는 printf(문자 주소 형식, …)` |
Expand Down Expand Up @@ -339,8 +339,7 @@ A file calls a function of another file through a declaration without a body and
정수를 반환하는 더하다(정수 가, 정수 나) // defined in lib.kr

정수를 반환하는 main() {
결과는 정수예요.
40과 2를 더해서 결과에 넣어요.
결과는 40과 2를 더한 값이에요.
결과를 반환해요. // 42
}
```
Expand Down Expand Up @@ -422,7 +421,8 @@ next word. A particle (`를`, `과`…) announces a call chain, `인 동안` a l

Every arithmetic operator of C that has no Korean word keeps its symbol, with the precedence and
associativity of C. Only `&&`, `||` and `!` are replaced by words (see the next section).
Assignment (`=`, `+=`…) and `++` / `--` do not exist: use `넣다`.
Assignment (`=`, `+=`…) and `++` / `--` do not exist: write the new value like a declaration,
`개수는 (개수 + 1)이에요`.

| Precedence (high → low) | Operators | Associativity |
| --- | --- | --- |
Expand Down Expand Up @@ -471,20 +471,22 @@ negation right after a condition.
| | immutable | `고정된` | "fixed" (고정되다 → `고정된`); placed before the name, like `짧은 정수`; longer variant: `바뀌지 않는` ("that does not change") |

```
개수는 0이에요 // mutable
고정된 합은 3과 4를 더한 값이에요 // immutable
개수에 1을 넣어요 // assignment: "put 1 into 개수"
개수와 1을 더해서 개수에 넣어요 // 개수 = 개수 + 1
개수에 개수와 1을 더해서 넣어요 // the same, with the destination first
합에 5를 넣어요 // error: 합 is 고정된
개수는 0이에요 // mutable
고정된 합은 3과 4를 더한 값이에요 // immutable
개수는 1이에요 // assignment: 개수 is already declared
개수는 개수와 1을 더한 값이에요 // 개수 = 개수 + 1
개수는 (개수 + 1)이에요 // the same, without a function
합은 5예요 // error: 합 is 고정된
개수는 정수예요 // error: 개수 is already declared
```

Assignment uses the built-in verb 넣다 ("put into") with `에` ("into"): it naturally goes at the
end of a chain. `넣어요` ends the sentence, `넣어서` continues the chain with the assigned value.
An assignment is written like the declaration: `NAME은/는 VALUE이에요/예요` on a name already
declared in the block or a block around it gives that variable a new value, of its type. There
is no shadowing, so the sentence cannot declare a second variable of the same name. Only a
value assigns: a type (`개수는 정수예요`) or `고정된` on a name already declared is an error.

The destination `NAME에` can also open the sentence, before the chain: a leading `NAME에` is an
argument of the **last** verb of the chain. There is no ambiguity, since only that verb can take
it and no other step expects an `에`.
The value can be the result of a chain: its last verb takes the adnominal form before `값`
(`개수는 3과 4를 더해서 제곱한 값이에요`, `결과는 "%ld\n"과 1을 printf한 값이에요`).

## Predefined names

Expand All @@ -493,7 +495,6 @@ it and no other step expects an `에`.
| ★ | entry point (`main`) | `main` | the only exception to the all-Korean language: the libc calls it by this name |
| ★ | print | — | no built-in function: `printf` of the libc, declared with `외부` |
| ★ | return a value | `반환하다` | `반환해요`: end of a chain that returns the result (see Control flow); `반환하는` and `반환` in declarations |
| | assign | `넣다` | `NAME에 VALUE을/를 넣어요`; at the end of a chain: `… 개수에 넣어요` |
| | convert | `바꾸다` | `TERM을/를 TYPE(으)로 바꿔서` (see Word operators) |
| | count (loop) | `세다` | `[TYPE] NAME을/를 A부터 B까지 세면서` (see Control flow) |

Expand All @@ -503,7 +504,7 @@ These verbs are reserved: a user function cannot take their name.
외부 정수를 반환하는 printf(문자 주소 형식, …)

"%ld\n"과 42를 printf해요 // 42
3과 4를 더해서 결과에 넣어요
결과는 3과 4를 더한 값이에요
"%ld\n"과 결과를 printf해요 // 7
```

Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ particles. It started in the Compiler class of Chung-Ang University and now cont
두 정수 가와 나를 받아 나누고 정수를 반환 {
나머지는 정수예요.
(나 == 0)이 아닌 동안 {
나머지에 (가 % 나)를 넣어요.
가에 나를 넣어요.
나에 나머지를 넣어요.
나머지는 (가 % 나)예요.
가는 나예요.
나는 나머지예요.
}
가를 반환해요.
}
Expand Down Expand Up @@ -56,7 +56,7 @@ Then compile and run it:

- **Functions are verbs.** Calls chain like a sentence, without nesting:
`3과 4를 더해서 제곱해서 반환해요`.
- **Arguments carry their particles**, as in `나머지에 (가 % 나)를 넣어요`.
- **Arguments carry their particles**, as in `48과 18을 나눈 값이에요`.
- **Statements end in the polite 해요 style**, as in `42를 반환해요.`.
- **libc functions are called with `하다`**, like foreign words in Korean:
`"%ld\n"과 가를 printf해요.`.
Expand Down
8 changes: 4 additions & 4 deletions docs/ko.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ ELF 목적 파일을 만듭니다. 함수는 동사이고, 인자에는 조사
두 정수 가와 나를 받아 나누고 정수를 반환 {
나머지는 정수예요.
(나 == 0)이 아닌 동안 {
나머지에 (가 % 나)를 넣어요.
가에 나를 넣어요.
나에 나머지를 넣어요.
나머지는 (가 % 나)예요.
가는 나예요.
나는 나머지예요.
}
가를 반환해요.
}
Expand Down Expand Up @@ -56,7 +56,7 @@ cd krc-v0.1.0-x86_64-linux

- **함수는 동사입니다.** 호출을 중첩하지 않고 문장처럼 이어서 씁니다:
`3과 4를 더해서 제곱해서 반환해요`
- **인자에는 조사가 붙습니다.** 예: `나머지에 (가 % 나)를 넣어요`
- **인자에는 조사가 붙습니다.** 예: `48과 18을 나눈 값이에요`
- **문장은 해요체로 끝납니다.** 예: `42를 반환해요.`
- **libc 함수는 라틴 문자 이름에 `하다`를 붙여 호출합니다.** 예: `"%ld\n"과 가를 printf해요.`

Expand Down
8 changes: 4 additions & 4 deletions sample/03_chains.kr
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,19 @@
정수를 반환하는 main() {
결과는 정수예요.

10과 4를 빼서 결과에 넣어요.
결과는 10과 4를 뺀 값이에요.
"%ld\n"과 결과를 printf해요. // 6

3과 4를 더해서 제곱해서 2를 빼서 결과에 넣어요.
결과는 3과 4를 더해서 제곱해서 2를 뺀 값이에요.
"%ld\n"과 결과를 printf해요. // (3 + 4)² - 2 = 47

계산해서 결과에 넣어요.
결과는 계산한 값이에요.
"%ld\n"과 결과를 printf해요. // 81

// name intermediate results with -(으)ㄴ 값
합은 3과 4를 더한 값이에요. // 7
차는 10과 4를 뺀 값이에요. // 6
합과 차를 더해서 결과에 넣어요.
결과는 합과 차를 더한 값이에요.
"%ld\n"과 결과를 printf해요. // 13

0을 반환해요.
Expand Down
4 changes: 2 additions & 2 deletions sample/04_conditions.kr
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@
}

"%ld %ld\n"과 가와 나를 printf해요.
가를 확인해서 가에 넣어요.
가는 가를 확인한 값이에요.
"%ld\n"과 가를 printf해요. // 1
나를 부호해서 나에 넣어요.
나는 나를 부호한 값이에요.
"%ld\n"과 나를 printf해요. // -1

0을 반환해요.
Expand Down
4 changes: 2 additions & 2 deletions sample/05_loops.kr
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
숫자는 1이에요.
숫자 < 100인 동안 {
"%ld\n"과 숫자를 printf해요.
숫자에 (숫자 * 2)를 넣어요.
숫자는 (숫자 * 2)예요.
}

// while not: countdown 3, 2, 1
남은은 3이에요.
(남은 == 0)이 아닌 동안 {
"%ld\n"과 남은을 printf해요.
남은에 (남은 - 1)을 넣어요.
남은은 (남은 - 1)이에요.
}

// the loop declares 칸: 0 to 4
Expand Down
2 changes: 1 addition & 1 deletion sample/06_types.kr
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"%ld\n"과 넓이를 printf해요.

// conversion with the built-in verb 바꾸다
7을 소수로 바꿔서 비율에 넣어요.
비율은 7을 소수로 바꾼 값이에요.
"%f\n"과 비율을 printf해요. // 7.0

0을 반환해요.
Expand Down
8 changes: 4 additions & 4 deletions sample/07_sentences.kr
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@

정수를 반환하는 main() {
결과는 정수예요.
7과 3을 비교해서 결과에 넣어요.
결과는 7과 3을 비교한 값이에요.
결과를 보여줘요. // 1
21을 두배해서 결과에 넣어요.
결과는 21을 두배한 값이에요.
결과를 보여줘요. // 42
6과 7을 곱해서 결과에 넣어요.
결과는 6과 7을 곱한 값이에요.
결과를 보여줘요. // 42
10과 4를 빼서 결과에 넣어요.
결과는 10과 4를 뺀 값이에요.
결과를 보여줘요. // 6
0을 반환해요.
}
6 changes: 3 additions & 3 deletions sample/08_fibonacci.kr
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

정수 번을 0부터 20까지 세면서 {
"%ld\n"과 앞을 printf해요.
합에 (앞 + 뒤)를 넣어요.
앞에 뒤를 넣어요.
뒤에 합을 넣어요.
합은 (앞 + 뒤)예요.
앞은 뒤예요.
뒤는 합이에요.
}

0을 반환해요.
Expand Down
4 changes: 2 additions & 2 deletions sample/09_primes.kr
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
만약 가 % 약수 == 0이면 {
0을 반환해요.
}
약수에 (약수 + 1)을 넣어요.
약수는 (약수 + 1)이에요.
}
1을 반환해요.
}

정수를 반환하는 main() {
판정은 정수예요.
정수 후보를 0부터 50까지 세면서 {
후보를 검사해서 판정에 넣어요.
판정은 후보를 검사한 값이에요.
만약 판정 == 0이면 { 넘어가요. }
"%ld\n"과 후보를 printf해요.
}
Expand Down
8 changes: 4 additions & 4 deletions sample/10_gcd.kr
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
두 정수 가와 나를 받아 나누고 정수를 반환 {
나머지는 정수예요.
(나 == 0)이 아닌 동안 {
나머지에 (가 % 나)를 넣어요.
가에 나를 넣어요.
나에 나머지를 넣어요.
나머지는 (가 % 나)예요.
가는 나예요.
나는 나머지예요.
}
가를 반환해요.
}

정수를 반환하는 main() {
결과는 정수예요.
48과 18을 나눠서 결과에 넣어요.
결과는 48과 18을 나눈 값이에요.
"gcd(48, 18) = %ld\n"과 결과를 printf해요. // 6
결과를 반환해요.
}
7 changes: 4 additions & 3 deletions sample/11_assignment.kr
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/*
* 11_assignment.kr: initializations and assignments of literals and variables.
* 11_assignment.kr: initializations and assignments of literals and variables. A name already
* declared gets a new value with the same sentence as its declaration.
* main returns 7: `echo $?` prints 7 after the run.
*/

정수를 반환하는 main() {
가는 1이에요.
나는 2예요.
7을 가에 넣어요.
가를 나에 넣어요.
가는 7이에요.
나는 가예요.
나를 반환해요.
}
Loading
Loading