grongigo 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/MIT +21 -0
- data/README.md +266 -0
- data/Rakefile +8 -0
- data/bin/grongigo +157 -0
- data/examples/calc.grg +17 -0
- data/examples/factorial.grg +21 -0
- data/examples/fizzbuzz.grg +86 -0
- data/examples/hello.grg +5 -0
- data/grongigo.gemspec +30 -0
- data/lib/grongigo/ast/assign_expr.rb +18 -0
- data/lib/grongigo/ast/binary_expr.rb +19 -0
- data/lib/grongigo/ast/block_stmt.rb +17 -0
- data/lib/grongigo/ast/break_stmt.rb +14 -0
- data/lib/grongigo/ast/call_expr.rb +18 -0
- data/lib/grongigo/ast/case_clause.rb +18 -0
- data/lib/grongigo/ast/char_literal.rb +17 -0
- data/lib/grongigo/ast/continue_stmt.rb +14 -0
- data/lib/grongigo/ast/expr_stmt.rb +17 -0
- data/lib/grongigo/ast/for_stmt.rb +20 -0
- data/lib/grongigo/ast/function_decl.rb +20 -0
- data/lib/grongigo/ast/identifier.rb +17 -0
- data/lib/grongigo/ast/if_stmt.rb +19 -0
- data/lib/grongigo/ast/index_expr.rb +18 -0
- data/lib/grongigo/ast/node.rb +15 -0
- data/lib/grongigo/ast/number_literal.rb +17 -0
- data/lib/grongigo/ast/parameter.rb +18 -0
- data/lib/grongigo/ast/program.rb +17 -0
- data/lib/grongigo/ast/return_stmt.rb +17 -0
- data/lib/grongigo/ast/string_literal.rb +17 -0
- data/lib/grongigo/ast/switch_stmt.rb +19 -0
- data/lib/grongigo/ast/unary_expr.rb +19 -0
- data/lib/grongigo/ast/var_decl.rb +19 -0
- data/lib/grongigo/ast/while_stmt.rb +18 -0
- data/lib/grongigo/ast.rb +30 -0
- data/lib/grongigo/codegen.rb +357 -0
- data/lib/grongigo/compiler.rb +156 -0
- data/lib/grongigo/constants.rb +129 -0
- data/lib/grongigo/jp2grg.rb +117 -0
- data/lib/grongigo/lexer.rb +349 -0
- data/lib/grongigo/parse_error.rb +13 -0
- data/lib/grongigo/parser.rb +572 -0
- data/lib/grongigo/token.rb +23 -0
- data/lib/grongigo.rb +12 -0
- metadata +90 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 7f21954f549836203271707cf55e17beccc4c4e8c39accc7debe0e411716d2ec
|
|
4
|
+
data.tar.gz: 2e8e2d37bf02cf3c69049df6a9aa0f7a594f0433f0a5baeafcbb3d1e2032e3e4
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: b80d40590c17dac1756a1a8c593d52dbb85ecb29419f489551681dfde58c0ced04e1a8c836f3a9502ad4b182f137a4b6800a483055420c941a9ad34b3e2d8ae6
|
|
7
|
+
data.tar.gz: d5608c00ffbd1f01bdaf9988ddbd876a525d01c380f7f20534c7821828558a215b7b263135b070302661c6b90414ae6316cc9f9b509cac96e8abc0fa2387e617
|
data/MIT
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Yudai Takada
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
1
|
+
# Grongigo
|
|
2
|
+
|
|
3
|
+
A programming language compiler using "Grongi language," the language of the Gurongi tribe from Kamen Rider Kuuga (Masked Rider Kuuga).
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
Grongigo is a programming language designed based on the linguistic rules of Grongi language. It has C-like syntax and transpiles source code written in Grongigo to C language.
|
|
8
|
+
|
|
9
|
+
### Features
|
|
10
|
+
|
|
11
|
+
- Complete Grongigo syntax: All keywords and operators are written in Grongigo
|
|
12
|
+
- Base-9 number system: Follows the Gurongi tribe's counting method using base-9
|
|
13
|
+
- Transpile to C: Generated C code can be compiled with gcc
|
|
14
|
+
|
|
15
|
+
## Grongigo Conversion Rules
|
|
16
|
+
|
|
17
|
+
Grongigo is a language that converts Japanese consonants according to certain rules:
|
|
18
|
+
|
|
19
|
+
| Japanese | Grongigo |
|
|
20
|
+
|----------|----------|
|
|
21
|
+
| ア行 | ガ行 |
|
|
22
|
+
| カ行 | バ行 |
|
|
23
|
+
| サ行 | ガ行 |
|
|
24
|
+
| タ行 | ダ行 |
|
|
25
|
+
| ナ行 | バ行 |
|
|
26
|
+
| ハ行 | ザ行 |
|
|
27
|
+
| マ行 | ラ行 |
|
|
28
|
+
| ヤ行 | ジャ行 |
|
|
29
|
+
| ラ行 | サ行 |
|
|
30
|
+
| ワ | パ |
|
|
31
|
+
| ガ行 | ガ行 |
|
|
32
|
+
| ザ行 | ザ行 |
|
|
33
|
+
| ダ行 | ザ行 |
|
|
34
|
+
| バ行 | ダ行 |
|
|
35
|
+
| パ行 | マ行 |
|
|
36
|
+
|
|
37
|
+
Special rules:
|
|
38
|
+
- Long vowels (ー) repeat the previous sound
|
|
39
|
+
- Geminate consonants (っ) repeat the following sound
|
|
40
|
+
- Particles: "ga" → "gu", "no" → "n", "ha" → "pa", "wo" → "zo"
|
|
41
|
+
|
|
42
|
+
## Language Specification
|
|
43
|
+
|
|
44
|
+
### Type Keywords
|
|
45
|
+
|
|
46
|
+
| Grongigo | C | Japanese Origin |
|
|
47
|
+
|----------|---|----------------|
|
|
48
|
+
| ゲギグウ | int | 整数 (seisuu - integer) |
|
|
49
|
+
| ロジ | char | 文字 (moji - character) |
|
|
50
|
+
| ズゾウ | float | 浮動 (fudou - floating) |
|
|
51
|
+
| バサ | void | 空 (kara - empty) |
|
|
52
|
+
|
|
53
|
+
### Control Structures
|
|
54
|
+
|
|
55
|
+
| Grongigo | C | Japanese Origin |
|
|
56
|
+
|----------|---|----------------|
|
|
57
|
+
| ジョウベン | if | 条件 (jouken - condition) |
|
|
58
|
+
| ゾバ | else | 他 (hoka - other) |
|
|
59
|
+
| ガギザ | while | 間 (aida - interval) |
|
|
60
|
+
| ブシバゲギ | for | 繰返し (kurikaeshi - repeat) |
|
|
61
|
+
| ロゾス | return | 戻す (modosu - return) |
|
|
62
|
+
| ブゲス | break | 抜ける (nukeru - exit) |
|
|
63
|
+
| ヅヅゲス | continue | 続ける (tsuzukeru - continue) |
|
|
64
|
+
| ゲンダブ | switch | 選択 (sentaku - selection) |
|
|
65
|
+
| ダガギ | case | 場合 (baai - case) |
|
|
66
|
+
| ビデギ | default | 既定 (kitei - default) |
|
|
67
|
+
|
|
68
|
+
### Operators
|
|
69
|
+
|
|
70
|
+
| Grongigo | C | Japanese Origin |
|
|
71
|
+
|----------|---|----------------|
|
|
72
|
+
| ダグ | + | 足す (tasu - add) |
|
|
73
|
+
| ジブ | - | 引く (hiku - subtract) |
|
|
74
|
+
| バゲス | * | 掛ける (kakeru - multiply) |
|
|
75
|
+
| パス | / | 割る (waru - divide) |
|
|
76
|
+
| ガラシ | % | 余り (amari - remainder) |
|
|
77
|
+
| ギセス | = | 入れる (ireru - assign) |
|
|
78
|
+
| ジドギギ | == | 等しい (hitoshii - equal) |
|
|
79
|
+
| ジドギグバギ | != | 等しくない (not equal) |
|
|
80
|
+
| ギョウバシ | < | 小なり (shounari - less than) |
|
|
81
|
+
| ザギバシ | > | 大なり (dainari - greater than) |
|
|
82
|
+
| ギバ | <= | 以下 (ika - less or equal) |
|
|
83
|
+
| ギジョウ | >= | 以上 (ijou - greater or equal) |
|
|
84
|
+
| バヅ | && | かつ (katsu - and) |
|
|
85
|
+
| ラダパ | \|\| | または (mataha - or) |
|
|
86
|
+
| ジデギ | ! | 否定 (hitei - negation) |
|
|
87
|
+
|
|
88
|
+
### Numbers (Base-9)
|
|
89
|
+
|
|
90
|
+
The Gurongi tribe uses base-9, with numbers based on English numerals converted to Grongigo:
|
|
91
|
+
|
|
92
|
+
| Decimal | Base-9 | Grongigo | Origin |
|
|
93
|
+
|---------|--------|----------|--------|
|
|
94
|
+
| 0 | 0 | ゼゼソ | zero |
|
|
95
|
+
| 1 | 1 | パパン | one (wan) |
|
|
96
|
+
| 2 | 2 | ドググ | two |
|
|
97
|
+
| 3 | 3 | グシギ | three |
|
|
98
|
+
| 4 | 4 | ズゴゴ | four |
|
|
99
|
+
| 5 | 5 | ズガギ | five |
|
|
100
|
+
| 6 | 6 | ギブグ | six |
|
|
101
|
+
| 7 | 7 | ゲズン | seven |
|
|
102
|
+
| 8 | 8 | ゲギド | eight |
|
|
103
|
+
| 9 | 10 | バギン | nine |
|
|
104
|
+
|
|
105
|
+
Compound number representation:
|
|
106
|
+
- Addition: ド (Example: バギンドパパン = 9 + 1 = 10)
|
|
107
|
+
- Multiplication: グ (Example: バギングバギン = 9 × 9 = 81)
|
|
108
|
+
|
|
109
|
+
### Syntax Elements
|
|
110
|
+
|
|
111
|
+
| Grongigo | Meaning |
|
|
112
|
+
|----------|---------|
|
|
113
|
+
| ザジレ ... ゴパシ | Block { ... } |
|
|
114
|
+
| パザ | Function definition marker |
|
|
115
|
+
| ゴロ | main function name |
|
|
116
|
+
| ジョウジ | printf |
|
|
117
|
+
| 「...」 | String literal |
|
|
118
|
+
| 『...』 | Character literal |
|
|
119
|
+
| ( ) | Parentheses |
|
|
120
|
+
| 、 | Comma |
|
|
121
|
+
| 。 | Semicolon (optional) |
|
|
122
|
+
| ゴゴ ... | Line comment |
|
|
123
|
+
| ゴビ ... ビゴ | Block comment |
|
|
124
|
+
|
|
125
|
+
## Usage
|
|
126
|
+
|
|
127
|
+
### Installation
|
|
128
|
+
|
|
129
|
+
```bash
|
|
130
|
+
git clone <repository>
|
|
131
|
+
cd grongigo
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
### Compilation
|
|
135
|
+
|
|
136
|
+
```bash
|
|
137
|
+
# Convert Grongigo source to C
|
|
138
|
+
bin/grongigo examples/hello.grg
|
|
139
|
+
|
|
140
|
+
# Specify output file
|
|
141
|
+
bin/grongigo -o output.c examples/hello.grg
|
|
142
|
+
|
|
143
|
+
# Compile and run (requires gcc)
|
|
144
|
+
bin/grongigo -r examples/fizzbuzz.grg
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Options
|
|
148
|
+
|
|
149
|
+
```
|
|
150
|
+
-o, --output FILE Specify output file name
|
|
151
|
+
-v, --verbose Verbose output
|
|
152
|
+
-t, --tokens Display token list
|
|
153
|
+
-a, --ast Display abstract syntax tree
|
|
154
|
+
-r, --run Run after compilation (requires gcc)
|
|
155
|
+
-c, --convert TEXT Convert Japanese text to Grongigo
|
|
156
|
+
-n, --number NUM Convert decimal number to base-9 Grongigo number
|
|
157
|
+
-h, --help Show help
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
### Japanese Conversion Utility
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# Convert Japanese to Grongigo
|
|
164
|
+
bin/grongigo -c "こんにちは"
|
|
165
|
+
# Output: ボンビヂザ
|
|
166
|
+
|
|
167
|
+
# Convert number to base-9 Grongigo
|
|
168
|
+
bin/grongigo -n 100
|
|
169
|
+
# Output: 100 (decimal) = バギングバギンドバギングパパンドパパン (Grongigo)
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
## Sample Programs
|
|
173
|
+
|
|
174
|
+
### Hello World
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
パザ ゲギグウ ゴロ バサ
|
|
178
|
+
ザジレ
|
|
179
|
+
ジョウジ(「リントンボドバゼ\n」)
|
|
180
|
+
ロゾス ゼゼソ
|
|
181
|
+
ゴパシ
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
### FizzBuzz
|
|
185
|
+
|
|
186
|
+
```
|
|
187
|
+
パザ ゲギグウ ゴロ バサ
|
|
188
|
+
ザジレ
|
|
189
|
+
ゲギグウ ギ ギセス パパン
|
|
190
|
+
|
|
191
|
+
ガギザ ギ ギバ バギングバギン
|
|
192
|
+
ザジレ
|
|
193
|
+
ジョウベン ギ ガラシ バギンドギブグ ジドギギ ゼゼソ
|
|
194
|
+
ザジレ
|
|
195
|
+
ジョウジ(「FizzBuzz\n」)
|
|
196
|
+
ゴパシ
|
|
197
|
+
ゾバ ジョウベン ギ ガラシ グシギ ジドギギ ゼゼソ
|
|
198
|
+
ザジレ
|
|
199
|
+
ジョウジ(「Fizz\n」)
|
|
200
|
+
ゴパシ
|
|
201
|
+
ゾバ ジョウベン ギ ガラシ ズガギ ジドギギ ゼゼソ
|
|
202
|
+
ザジレ
|
|
203
|
+
ジョウジ(「Buzz\n」)
|
|
204
|
+
ゴパシ
|
|
205
|
+
ゾバ
|
|
206
|
+
ザジレ
|
|
207
|
+
ジョウジ(「%d\n」、 ギ)
|
|
208
|
+
ゴパシ
|
|
209
|
+
|
|
210
|
+
ギ ギセス ギ ダグ パパン
|
|
211
|
+
ゴパシ
|
|
212
|
+
|
|
213
|
+
ロゾス ゼゼソ
|
|
214
|
+
ゴパシ
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
## Proper Nouns (Untranslated Words)
|
|
218
|
+
|
|
219
|
+
The following are unique Grongigo expressions that are not converted:
|
|
220
|
+
|
|
221
|
+
- クウガ (Kuuga): Ancient warrior adversary
|
|
222
|
+
- リント (Linto): Humans (hunting targets)
|
|
223
|
+
- ゲゲル (Gegeru): Murder game
|
|
224
|
+
- グロンギ (Gurongi): Tribe name
|
|
225
|
+
- グセパ (Gusepa): Bracelet that records Gegeru victims
|
|
226
|
+
- バグンダダ (Bagundada): Counter (abacus-like tool)
|
|
227
|
+
|
|
228
|
+
## File Structure
|
|
229
|
+
|
|
230
|
+
```
|
|
231
|
+
grongigo/
|
|
232
|
+
├── bin/
|
|
233
|
+
│ └── grongigo # CLI executable
|
|
234
|
+
├── lib/
|
|
235
|
+
│ ├── grongigo.rb # Main module
|
|
236
|
+
│ └── grongigo/
|
|
237
|
+
│ ├── constants.rb # Constant definitions
|
|
238
|
+
│ ├── token.rb # Token class
|
|
239
|
+
│ ├── lexer.rb # Lexical analyzer
|
|
240
|
+
│ ├── parser.rb # Parser
|
|
241
|
+
│ ├── codegen.rb # Code generator
|
|
242
|
+
│ ├── compiler.rb # Main compiler
|
|
243
|
+
│ ├── jp2grg.rb # Japanese to Grongigo converter
|
|
244
|
+
│ ├── parse_error.rb # Parse error class
|
|
245
|
+
│ └── ast/ # AST node classes
|
|
246
|
+
├── examples/
|
|
247
|
+
│ ├── hello.grg # Hello World
|
|
248
|
+
│ ├── calc.grg # Calculation sample
|
|
249
|
+
│ ├── fizzbuzz.grg # FizzBuzz
|
|
250
|
+
│ └── factorial.grg # Factorial calculation
|
|
251
|
+
├── spec/ # Test files
|
|
252
|
+
└── README.md
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
## License
|
|
256
|
+
|
|
257
|
+
MIT License
|
|
258
|
+
|
|
259
|
+
## Acknowledgments
|
|
260
|
+
|
|
261
|
+
Thanks to the production staff of "Kamen Rider Kuuga (Masked Rider Kuuga)" and all the fans who have decoded and researched Grongi language.
|
|
262
|
+
|
|
263
|
+
---
|
|
264
|
+
|
|
265
|
+
*"リントンボドバゼ ザバゲデ グロンギゴゾ ダボギレ!"*
|
|
266
|
+
(Speak in Linto's words, enjoy Grongigo!)
|
data/Rakefile
ADDED
data/bin/grongigo
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
# frozen_string_literal: true
|
|
3
|
+
|
|
4
|
+
require_relative '../lib/grongigo'
|
|
5
|
+
require 'optparse'
|
|
6
|
+
|
|
7
|
+
# Set standard I/O encoding to UTF-8
|
|
8
|
+
Encoding.default_external = Encoding::UTF_8
|
|
9
|
+
Encoding.default_internal = Encoding::UTF_8
|
|
10
|
+
|
|
11
|
+
options = {
|
|
12
|
+
verbose: false,
|
|
13
|
+
output_tokens: false,
|
|
14
|
+
output_ast: false,
|
|
15
|
+
output: nil,
|
|
16
|
+
run: false,
|
|
17
|
+
convert: false
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
parser = OptionParser.new do |opts|
|
|
21
|
+
opts.banner = <<~BANNER
|
|
22
|
+
Grongigo - Grongigo Programming Language Compiler
|
|
23
|
+
|
|
24
|
+
Usage: #{$PROGRAM_NAME} [options] <source_file.grg>
|
|
25
|
+
|
|
26
|
+
Compiles programs written in Grongi language to C.
|
|
27
|
+
|
|
28
|
+
BANNER
|
|
29
|
+
|
|
30
|
+
opts.on('-o', '--output FILE', 'Output file name') do |file|
|
|
31
|
+
options[:output] = file
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
opts.on('-v', '--verbose', 'Verbose output') do
|
|
35
|
+
options[:verbose] = true
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
opts.on('-t', '--tokens', 'Output tokens') do
|
|
39
|
+
options[:output_tokens] = true
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
opts.on('-a', '--ast', 'Output AST') do
|
|
43
|
+
options[:output_ast] = true
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
opts.on('-r', '--run', 'Compile and run (requires gcc)') do
|
|
47
|
+
options[:run] = true
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
opts.on('-c', '--convert TEXT', 'Convert Japanese text to Grongigo') do |text|
|
|
51
|
+
options[:convert] = text
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
opts.on('-n', '--number NUM', Integer, 'Convert number to Grongigo (9-base)') do |num|
|
|
55
|
+
puts "#{num} (decimal) = #{Grongigo::Jp2Grg.num2grg(num)} (Grongigo)"
|
|
56
|
+
exit
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
opts.on('-h', '--help', 'Show this help') do
|
|
60
|
+
puts opts
|
|
61
|
+
exit
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
opts.on('--version', 'Show version') do
|
|
65
|
+
puts "Grongigo version #{Grongigo::VERSION}"
|
|
66
|
+
exit
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
parser.parse!
|
|
71
|
+
|
|
72
|
+
# Japanese conversion mode
|
|
73
|
+
if options[:convert]
|
|
74
|
+
puts Grongigo::Jp2Grg.convert(options[:convert])
|
|
75
|
+
exit
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
# If no source file is specified
|
|
79
|
+
if ARGV.empty?
|
|
80
|
+
# Display sample program
|
|
81
|
+
puts parser
|
|
82
|
+
puts <<~SAMPLE
|
|
83
|
+
|
|
84
|
+
=== Sample program (Hello World) ===
|
|
85
|
+
|
|
86
|
+
パザ ゲギグウ ゴロ バサ
|
|
87
|
+
ザジレ
|
|
88
|
+
ジョウジ(「リントンボドバ」)
|
|
89
|
+
ロゾス ゼゼソ
|
|
90
|
+
ゴパシ
|
|
91
|
+
|
|
92
|
+
=== Keywords Reference ===
|
|
93
|
+
|
|
94
|
+
Types:
|
|
95
|
+
ゲギグウ (int) ロジ (char) ズゾウ (float) バサ (void)
|
|
96
|
+
|
|
97
|
+
Control:
|
|
98
|
+
ジョウベン (if) ゾバ (else) ガギザ (while) ブシバゲギ (for)
|
|
99
|
+
ロゾス (return) ブゲス (break) ヅヅゲス (continue)
|
|
100
|
+
ゲンダブ (switch) ダガギ (case) ビデギ (default)
|
|
101
|
+
|
|
102
|
+
Operators:
|
|
103
|
+
ダグ (+) ジブ (-) バゲス (*) パス (/) ガラシ (%)
|
|
104
|
+
ギセス (=) ジドギギ (==) ジドギグバギ (!=)
|
|
105
|
+
ギョウバシ (<) ザギバシ (>) ギバ (<=) ギジョウ (>=)
|
|
106
|
+
バヅ (&&) ラダパ (||) ジデギ (!)
|
|
107
|
+
|
|
108
|
+
Numbers (base-9):
|
|
109
|
+
ゼゼソ (0) パパン (1) ドググ (2) グシギ (3)
|
|
110
|
+
ズゴゴ (4) ズガギ (5) ギブグ (6) ゲズン (7) ゲギド (8)
|
|
111
|
+
バギン (9)
|
|
112
|
+
#{' '}
|
|
113
|
+
Addition: ド Multiplication: グ
|
|
114
|
+
Example: バギンドパパン = 9 + 1 = 10
|
|
115
|
+
|
|
116
|
+
Syntax:
|
|
117
|
+
ザジレ ... ゴパシ ({ ... })
|
|
118
|
+
パザ (function definition marker)
|
|
119
|
+
「文字列」 (string literal)
|
|
120
|
+
『文字』 (character literal)
|
|
121
|
+
( ) (parentheses)
|
|
122
|
+
、 (comma)
|
|
123
|
+
。 (semicolon)
|
|
124
|
+
|
|
125
|
+
SAMPLE
|
|
126
|
+
exit
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Execute compilation
|
|
130
|
+
input_file = ARGV[0]
|
|
131
|
+
unless File.exist?(input_file)
|
|
132
|
+
puts "Error: File not found: #{input_file}"
|
|
133
|
+
exit 1
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
compiler = Grongigo::Compiler.new(options)
|
|
137
|
+
output_file = options[:output] || input_file.sub(/\.[^.]+$/, '.c')
|
|
138
|
+
|
|
139
|
+
if compiler.compile_file(input_file, output_file)
|
|
140
|
+
puts "Successfully compiled: #{input_file} -> #{output_file}"
|
|
141
|
+
|
|
142
|
+
if options[:run]
|
|
143
|
+
exe_file = output_file.sub(/\.c$/, '')
|
|
144
|
+
system("gcc -o #{exe_file} #{output_file}")
|
|
145
|
+
if $?.success?
|
|
146
|
+
puts "\n=== Running program ===\n"
|
|
147
|
+
system("./#{exe_file}")
|
|
148
|
+
else
|
|
149
|
+
puts 'Error: gcc compilation failed'
|
|
150
|
+
exit 1
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
else
|
|
154
|
+
puts 'Compilation failed:'
|
|
155
|
+
compiler.errors.each { |e| puts " #{e}" }
|
|
156
|
+
exit 1
|
|
157
|
+
end
|
data/examples/calc.grg
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
パザ ゲギグウ ゴロ バサ
|
|
2
|
+
ザジレ
|
|
3
|
+
ゲギグウ ガ ギセス ズガギ
|
|
4
|
+
ゲギグウ ダ ギセス グシギ
|
|
5
|
+
ゲギグウ ボダイ
|
|
6
|
+
|
|
7
|
+
ボダイ ギセス ガ ダグ ダ
|
|
8
|
+
ジョウジ(「%d ダグ %d ジドギギ %d\n」、 ガ、 ダ、 ボダイ)
|
|
9
|
+
|
|
10
|
+
ボダイ ギセス ガ バゲス ダ
|
|
11
|
+
ジョウジ(「%d バゲス %d ジドギギ %d\n」、 ガ、 ダ、 ボダイ)
|
|
12
|
+
|
|
13
|
+
ボダイ ギセス ガ ガラシ ダ
|
|
14
|
+
ジョウジ(「%d ガラシ %d ジドギギ %d\n」、 ガ、 ダ、 ボダイ)
|
|
15
|
+
|
|
16
|
+
ロゾス ゼゼソ
|
|
17
|
+
ゴパシ
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
パザ ゲギグウ バギジョウシギャス ゲギグウ バ
|
|
2
|
+
ザジレ
|
|
3
|
+
ジョウベン バ ギバ パパン
|
|
4
|
+
ザジレ
|
|
5
|
+
ロゾス パパン
|
|
6
|
+
ゴパシ
|
|
7
|
+
ロゾス バ バゲス バギジョウシギャス(バ ジブ パパン)
|
|
8
|
+
ゴパシ
|
|
9
|
+
|
|
10
|
+
パザ ゲギグウ ゴロ バサ
|
|
11
|
+
ザジレ
|
|
12
|
+
ゲギグウ ギ ギセス ゼゼソ
|
|
13
|
+
|
|
14
|
+
ガギザ ギ ギバ バギン
|
|
15
|
+
ザジレ
|
|
16
|
+
ジョウジ(「%d! = %d\n」、 ギ、 バギジョウシギャス(ギ))
|
|
17
|
+
ギ ギセス ギ ダグ パパン
|
|
18
|
+
ゴパシ
|
|
19
|
+
|
|
20
|
+
ロゾス ゼゼソ
|
|
21
|
+
ゴパシ
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
パザ バサ ジンドゲンギュウ ゲギグウ バ
|
|
2
|
+
ザジレ
|
|
3
|
+
ゲギグウ ジュウンベダ
|
|
4
|
+
ゲギグウ ギヂギダ
|
|
5
|
+
|
|
6
|
+
ジュウンベダ ギセス バ パス バギン
|
|
7
|
+
ギヂギダ ギセス バ ガラシ バギン
|
|
8
|
+
|
|
9
|
+
ジョウベン ジュウンベダ ザギバシ ゼゼソ
|
|
10
|
+
ザジレ
|
|
11
|
+
ジンドゲンギュウ(ジュウンベダ)
|
|
12
|
+
ジョウジ(「グ」)
|
|
13
|
+
ゴパシ
|
|
14
|
+
|
|
15
|
+
ジョウベン ギヂギダ ジドギギ ゼゼソ
|
|
16
|
+
ザジレ
|
|
17
|
+
ジョウジ(「ゼゼソ」)
|
|
18
|
+
ゴパシ
|
|
19
|
+
ゾバ ジョウベン ギヂギダ ジドギギ パパン
|
|
20
|
+
ザジレ
|
|
21
|
+
ジョウジ(「パパン」)
|
|
22
|
+
ゴパシ
|
|
23
|
+
ゾバ ジョウベン ギヂギダ ジドギギ ドググ
|
|
24
|
+
ザジレ
|
|
25
|
+
ジョウジ(「ドググ」)
|
|
26
|
+
ゴパシ
|
|
27
|
+
ゾバ ジョウベン ギヂギダ ジドギギ グシギ
|
|
28
|
+
ザジレ
|
|
29
|
+
ジョウジ(「グシギ」)
|
|
30
|
+
ゴパシ
|
|
31
|
+
ゾバ ジョウベン ギヂギダ ジドギギ ズゴゴ
|
|
32
|
+
ザジレ
|
|
33
|
+
ジョウジ(「ズゴゴ」)
|
|
34
|
+
ゴパシ
|
|
35
|
+
ゾバ ジョウベン ギヂギダ ジドギギ ズガギ
|
|
36
|
+
ザジレ
|
|
37
|
+
ジョウジ(「ズガギ」)
|
|
38
|
+
ゴパシ
|
|
39
|
+
ゾバ ジョウベン ギヂギダ ジドギギ ギブグ
|
|
40
|
+
ザジレ
|
|
41
|
+
ジョウジ(「ギブグ」)
|
|
42
|
+
ゴパシ
|
|
43
|
+
ゾバ ジョウベン ギヂギダ ジドギギ ゲズン
|
|
44
|
+
ザジレ
|
|
45
|
+
ジョウジ(「ゲズン」)
|
|
46
|
+
ゴパシ
|
|
47
|
+
ゾバ
|
|
48
|
+
ザジレ
|
|
49
|
+
ジョウジ(「ゲギド」)
|
|
50
|
+
ゴパシ
|
|
51
|
+
|
|
52
|
+
ジョウベン ジュウンベダ ザギバシ ゼゼソ
|
|
53
|
+
ザジレ
|
|
54
|
+
ジョウジ(「ド」)
|
|
55
|
+
ゴパシ
|
|
56
|
+
ゴパシ
|
|
57
|
+
|
|
58
|
+
パザ ゲギグウ ゴロ バサ
|
|
59
|
+
ザジレ
|
|
60
|
+
ゲギグウ ギ ギセス パパン
|
|
61
|
+
|
|
62
|
+
ガギザ ギ ギバ バギングバギン
|
|
63
|
+
ザジレ
|
|
64
|
+
ジョウベン ギ ガラシ バギンドギブグ ジドギギ ゼゼソ
|
|
65
|
+
ザジレ
|
|
66
|
+
ジョウジ(「ズィズダズ\n」)
|
|
67
|
+
ゴパシ
|
|
68
|
+
ゾバ ジョウベン ギ ガラシ グシギ ジドギギ ゼゼソ
|
|
69
|
+
ザジレ
|
|
70
|
+
ジョウジ(「ズィズ\n」)
|
|
71
|
+
ゴパシ
|
|
72
|
+
ゾバ ジョウベン ギ ガラシ ズガギ ジドギギ ゼゼソ
|
|
73
|
+
ザジレ
|
|
74
|
+
ジョウジ(「ダズ\n」)
|
|
75
|
+
ゴパシ
|
|
76
|
+
ゾバ
|
|
77
|
+
ザジレ
|
|
78
|
+
ジンドゲンギュウ(ギ)
|
|
79
|
+
ジョウジ(「\n」)
|
|
80
|
+
ゴパシ
|
|
81
|
+
|
|
82
|
+
ギ ギセス ギ ダグ パパン
|
|
83
|
+
ゴパシ
|
|
84
|
+
|
|
85
|
+
ロゾス ゼゼソ
|
|
86
|
+
ゴパシ
|
data/examples/hello.grg
ADDED
data/grongigo.gemspec
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'lib/grongigo'
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |spec|
|
|
6
|
+
spec.name = 'grongigo'
|
|
7
|
+
spec.version = Grongigo::VERSION
|
|
8
|
+
spec.authors = ['Yudai Takada']
|
|
9
|
+
spec.email = ['t.yudai92@gmail.com']
|
|
10
|
+
|
|
11
|
+
spec.summary = 'Grongigo programming language compiler - A programming language based on Grongi language from Kamen Rider Kuuga (Masked Rider Kuuga)'
|
|
12
|
+
spec.description = 'Grongigo is a programming language compiler that transpiles Grongi language code to C language. Features include complete Grongigo syntax, base-9 number system, and C language transpilation.'
|
|
13
|
+
spec.homepage = 'https://github.com/ydah/grongigo'
|
|
14
|
+
spec.license = 'MIT'
|
|
15
|
+
spec.required_ruby_version = '>= 3.0.0'
|
|
16
|
+
|
|
17
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
|
18
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ydah/grongigo'
|
|
19
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ydah/grongigo/blob/main/CHANGELOG.md'
|
|
20
|
+
|
|
21
|
+
spec.files = Dir.chdir(__dir__) do
|
|
22
|
+
`git ls-files -z`.split("\x0").reject do |f|
|
|
23
|
+
(File.expand_path(f) == __FILE__) ||
|
|
24
|
+
f.start_with?(*%w[bin/ test/ spec/ features/ .git .github appveyor Gemfile])
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
spec.bindir = 'bin'
|
|
28
|
+
spec.executables = ['grongigo']
|
|
29
|
+
spec.require_paths = ['lib']
|
|
30
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'node'
|
|
4
|
+
|
|
5
|
+
module Grongigo
|
|
6
|
+
module AST
|
|
7
|
+
# Assignment expression
|
|
8
|
+
class AssignExpr < Node
|
|
9
|
+
attr_reader :target, :value
|
|
10
|
+
|
|
11
|
+
def initialize(target, value, line = 0, column = 0)
|
|
12
|
+
super(line, column)
|
|
13
|
+
@target = target
|
|
14
|
+
@value = value
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'node'
|
|
4
|
+
|
|
5
|
+
module Grongigo
|
|
6
|
+
module AST
|
|
7
|
+
# Binary expression
|
|
8
|
+
class BinaryExpr < Node
|
|
9
|
+
attr_reader :left, :operator, :right
|
|
10
|
+
|
|
11
|
+
def initialize(left, operator, right, line = 0, column = 0)
|
|
12
|
+
super(line, column)
|
|
13
|
+
@left = left
|
|
14
|
+
@operator = operator
|
|
15
|
+
@right = right
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative 'node'
|
|
4
|
+
|
|
5
|
+
module Grongigo
|
|
6
|
+
module AST
|
|
7
|
+
# Block文
|
|
8
|
+
class BlockStmt < Node
|
|
9
|
+
attr_reader :statements
|
|
10
|
+
|
|
11
|
+
def initialize(statements, line = 0, column = 0)
|
|
12
|
+
super(line, column)
|
|
13
|
+
@statements = statements
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|