loxxy 0.1.17 → 0.2.04

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +47 -11
  3. data/CHANGELOG.md +72 -2
  4. data/README.md +188 -90
  5. data/bin/loxxy +54 -6
  6. data/lib/loxxy.rb +1 -0
  7. data/lib/loxxy/ast/all_lox_nodes.rb +1 -0
  8. data/lib/loxxy/ast/ast_builder.rb +20 -1
  9. data/lib/loxxy/ast/ast_visitee.rb +53 -0
  10. data/lib/loxxy/ast/ast_visitor.rb +8 -1
  11. data/lib/loxxy/ast/lox_assign_expr.rb +1 -5
  12. data/lib/loxxy/ast/lox_binary_expr.rb +1 -6
  13. data/lib/loxxy/ast/lox_block_stmt.rb +1 -5
  14. data/lib/loxxy/ast/lox_call_expr.rb +1 -5
  15. data/lib/loxxy/ast/lox_class_stmt.rb +6 -6
  16. data/lib/loxxy/ast/lox_for_stmt.rb +2 -6
  17. data/lib/loxxy/ast/lox_fun_stmt.rb +1 -5
  18. data/lib/loxxy/ast/lox_get_expr.rb +1 -6
  19. data/lib/loxxy/ast/lox_grouping_expr.rb +1 -5
  20. data/lib/loxxy/ast/lox_if_stmt.rb +2 -6
  21. data/lib/loxxy/ast/lox_literal_expr.rb +1 -5
  22. data/lib/loxxy/ast/lox_logical_expr.rb +1 -6
  23. data/lib/loxxy/ast/lox_node.rb +9 -1
  24. data/lib/loxxy/ast/lox_print_stmt.rb +1 -5
  25. data/lib/loxxy/ast/lox_return_stmt.rb +1 -5
  26. data/lib/loxxy/ast/lox_seq_decl.rb +1 -5
  27. data/lib/loxxy/ast/lox_set_expr.rb +1 -5
  28. data/lib/loxxy/ast/lox_super_expr.rb +31 -0
  29. data/lib/loxxy/ast/lox_this_expr.rb +1 -5
  30. data/lib/loxxy/ast/lox_unary_expr.rb +1 -6
  31. data/lib/loxxy/ast/lox_var_stmt.rb +1 -5
  32. data/lib/loxxy/ast/lox_variable_expr.rb +1 -5
  33. data/lib/loxxy/ast/lox_while_stmt.rb +2 -6
  34. data/lib/loxxy/back_end/engine.rb +57 -10
  35. data/lib/loxxy/back_end/lox_class.rb +13 -2
  36. data/lib/loxxy/back_end/lox_instance.rb +1 -1
  37. data/lib/loxxy/back_end/resolver.rb +31 -1
  38. data/lib/loxxy/cli_parser.rb +68 -0
  39. data/lib/loxxy/error.rb +3 -0
  40. data/lib/loxxy/front_end/grammar.rb +2 -2
  41. data/lib/loxxy/front_end/parser.rb +1 -1
  42. data/lib/loxxy/front_end/scanner.rb +32 -7
  43. data/lib/loxxy/version.rb +1 -1
  44. data/loxxy.gemspec +6 -2
  45. data/spec/front_end/scanner_spec.rb +34 -0
  46. data/spec/interpreter_spec.rb +51 -0
  47. metadata +10 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c7d720e2638407882bfd3f34384748a872086e1b1f7a3849f0e029e8672fc1c
4
- data.tar.gz: c3aa7ebe4a625ef1b0a257cc750430b9a0aa404bb39dab900b409b2987e09dea
3
+ metadata.gz: d628b0737a29bab0869827af50a363846200bfab7baddc63279e0e3fb904fa75
4
+ data.tar.gz: d617939297fe24cf267fb66c198cbc172e05a7df4472eac546bd9b5e27eef0cd
5
5
  SHA512:
6
- metadata.gz: 1eb8bb6575dd39834c55ce3ad359fbdb9a2129f91d25bc39ea093c5a4ca2aa38300ab28e673b39991678c304aea64ffda473707f9d317980b976c8f98fc3a55f
7
- data.tar.gz: d3dd5baae665ab27a60a13b7392e9d57ef32ff72a37892d8f08e314888a1bfcc3db9ceeb071a28c00dda44f4bce7afed6aadf6c33c411a93d561a30fef833edd
6
+ metadata.gz: dde10867e0a0243a5c0e2349a37df2ec76178aa2a7da625abd42363175301bf773d8d56aa249dde380361b13af5181c33a8ed65a4cf1bd2bbdaf2c946b534f99
7
+ data.tar.gz: 204243d4d781f54820a66d483d791676d144b3a4af7febbb2a1a27041c651d2ea4a0015e2bf3408754c9ea31dc0f66b4c6b0d8ad6175edc5912391331f95e9e1
data/.rubocop.yml CHANGED
@@ -3,6 +3,9 @@ AllCops:
3
3
  - 'exp/**/*'
4
4
  - 'demo/**/*'
5
5
 
6
+ Gemspec/DateAssignment:
7
+ Enabled: true
8
+
6
9
  Layout/ArgumentAlignment:
7
10
  Enabled: false
8
11
 
@@ -34,7 +37,7 @@ Layout/EndOfLine:
34
37
 
35
38
  Layout/FirstArgumentIndentation:
36
39
  Enabled: false
37
-
40
+
38
41
  Layout/HashAlignment:
39
42
  Enabled: false
40
43
 
@@ -56,7 +59,7 @@ Layout/MultilineMethodCallBraceLayout:
56
59
 
57
60
  Layout/SpaceAroundOperators:
58
61
  Enabled: true
59
-
62
+
60
63
  Layout/SpaceBeforeBrackets:
61
64
  Enabled: true
62
65
 
@@ -74,10 +77,13 @@ Layout/TrailingEmptyLines:
74
77
 
75
78
  Layout/TrailingWhitespace:
76
79
  Enabled: true
77
-
80
+
78
81
  Lint/AmbiguousAssignment:
79
82
  Enabled: true
80
83
 
84
+ Lint/DeprecatedConstants:
85
+ Enabled: true
86
+
81
87
  Lint/DuplicateBranch:
82
88
  Enabled: true
83
89
 
@@ -90,24 +96,42 @@ Lint/EmptyBlock:
90
96
  Lint/EmptyClass:
91
97
  Enabled: false
92
98
 
99
+ Lint/LambdaWithoutLiteralBlock:
100
+ Enabled: true
101
+
93
102
  Lint/Loop:
94
103
  Enabled: true
95
104
 
96
105
  Lint/NoReturnInBeginEndBlocks:
97
106
  Enabled: true
98
107
 
108
+ Lint/NumberedParameterAssignment:
109
+ Enabled: true
110
+
111
+ Lint/OrAssignmentToConstant:
112
+ Enabled: true
113
+
99
114
  Lint/RaiseException:
100
115
  Enabled: true
101
116
 
117
+ Lint/RedundantDirGlobSort:
118
+ Enabled: true
119
+
102
120
  Lint/RescueException:
103
121
  Enabled: true
104
122
 
105
123
  Lint/StructNewOverride:
106
124
  Enabled: true
107
125
 
126
+ Lint/SymbolConversion:
127
+ Enabled: true
128
+
108
129
  Lint/ToEnumArguments:
109
130
  Enabled: true
110
131
 
132
+ Lint/TripleQuotes:
133
+ Enabled: true
134
+
111
135
  Lint/UnexpectedBlockArity:
112
136
  Enabled: true
113
137
 
@@ -170,7 +194,7 @@ Naming/BlockParameterName:
170
194
 
171
195
  Naming/MethodParameterName:
172
196
  Enabled: false
173
-
197
+
174
198
  Naming/MethodName:
175
199
  Enabled: false
176
200
 
@@ -200,7 +224,7 @@ Style/ClassCheck:
200
224
 
201
225
  Style/ClassVars:
202
226
  Enabled: false
203
-
227
+
204
228
  Style/CollectionCompact:
205
229
  Enabled: true
206
230
 
@@ -221,7 +245,7 @@ Style/DefWithParentheses:
221
245
 
222
246
  Style/Documentation:
223
247
  Enabled: false
224
-
248
+
225
249
  Style/DocumentDynamicEvalDefinition:
226
250
  Enabled: true
227
251
 
@@ -236,7 +260,7 @@ Style/GuardClause:
236
260
 
237
261
  Style/HashEachMethods:
238
262
  Enabled: true
239
-
263
+
240
264
  Style/HashExcept:
241
265
  Enabled: true
242
266
 
@@ -254,13 +278,13 @@ Style/InverseMethods:
254
278
 
255
279
  Style/MissingRespondToMissing:
256
280
  Enabled: false
257
-
281
+
258
282
  Style/NegatedIfElseCondition:
259
283
  Enabled: true
260
284
 
261
285
  Style/Next:
262
286
  Enabled: false
263
-
287
+
264
288
  Style/NilLambda:
265
289
  Enabled: true
266
290
 
@@ -269,7 +293,7 @@ Style/NumericLiterals:
269
293
 
270
294
  Style/RaiseArgs:
271
295
  Enabled: true
272
-
296
+
273
297
  Style/RedundantArgument:
274
298
  Enabled: true
275
299
 
@@ -290,7 +314,7 @@ Style/StderrPuts:
290
314
 
291
315
  Style/StringLiterals:
292
316
  Enabled: true
293
-
317
+
294
318
  Style/SwapValues:
295
319
  Enabled: true
296
320
 
@@ -352,6 +376,9 @@ Style/BisectedAttrAccessor:
352
376
  Style/CaseLikeIf:
353
377
  Enabled: true
354
378
 
379
+ Style/EndlessMethod:
380
+ Enabled: true
381
+
355
382
  Style/ExplicitBlockArgument:
356
383
  Enabled: true
357
384
 
@@ -361,9 +388,15 @@ Style/GlobalStdStream:
361
388
  Style/HashAsLastArrayItem:
362
389
  Enabled: true
363
390
 
391
+ Style/HashConversion:
392
+ Enabled: true
393
+
364
394
  Style/HashLikeCase:
365
395
  Enabled: true
366
396
 
397
+ Style/IfWithBooleanLiteralBranches:
398
+ Enabled: true
399
+
367
400
  Style/OptionalBooleanParameter:
368
401
  Enabled: true
369
402
 
@@ -388,5 +421,8 @@ Style/SingleArgumentDig:
388
421
  Style/SlicingWithRange:
389
422
  Enabled: true
390
423
 
424
+ Style/StringChars:
425
+ Enabled: true
426
+
391
427
  Style/StringConcatenation:
392
428
  Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,8 +1,78 @@
1
+ ## [0.2.04] - 2021-04-25
2
+ - `Loxxy` passes the test suite for `for` statements
3
+
4
+ ### Fixed
5
+ - Method `BackEnd::Engine#after_for_stmt` now a for(;;) executes the body once; a for without test will execute forever
6
+ - Method `BackEnd::Resolver#after_for_stmt now accepts nil test expression
7
+
8
+ ## [0.2.03] - 2021-04-24
9
+ - Fixes for the set (field) expressions, `accept` methods for AST nodes are meta-programmed
10
+
11
+ ### New
12
+ - Module `Ast::Visitee` provides the `define_accept` method that generate `accept` method with meta-programming
13
+
14
+ ### Fixed
15
+ - Method `BackEnd::Engine#before_set_expr` methos method that ensure that the receiver is evaluated first, then the assigned value
16
+ - Method `BackEnd::Engine#after_set_expr` now pushes the value assigned to the field also onto the stack
17
+ - Class `BackEnd::Engine` a number of StnadardError exceptions are replaced by Loxxy::RuntimeError
18
+
19
+
20
+ ## [0.2.02] - 2021-04-21
21
+ - Improvements in the scanner class (escape sequence for quotes and newlines), error messages closer to jlox.
22
+
23
+ ### Changed
24
+ - File `loxxy` executable doesn't show a stack trace for scanner errors
25
+ - Class `ScannerError` is now a subclass of `Loxxy::Error`
26
+ - Class `Scanner` now returns a specific error message for unterminated strings
27
+ - Class `Scanner` error messages are closer to the ones from jlox
28
+ - Class `Scanner` supports now escape sequences \" for double quotes, \n for newlines
29
+ - File `README.md` Reshuffled some text
30
+
31
+ ## [0.2.01] - 2021-04-18
32
+ - Minor improvements in CLI, starting re-documenting `README.md`.
33
+
34
+ ### New
35
+ - Class `Loxxy::CLIParser` parser for the command-line options
36
+
37
+ ### Changed
38
+ - File `loxxy` executable now uses commad-line parsing
39
+ - File `.rubocop.yml` updated with new cops
40
+ - File `README.md` Added examples for command-line interface
41
+ - File `loxxy.gemspec` expanded description of gem
42
+
43
+ ## [0.2.00] - 2021-04-17
44
+ - `Loxxy` implements the complete `Lox` language including its object-oriented features.
45
+
46
+ ### New
47
+ - Class `Ast::LoxSuperExpr` an AST node that represents the occurrence of `super` in source code.
48
+ - Method `Ast::ASTBuilder#reduce_class_subclassing` action launched by the parser when detecting inheritance
49
+ - Method `Ast::ASTBuilder#reduce_super_expr` action launched by the parser when detecting the super keyword
50
+ - Method `Ast::Visitor#visit_super_expr` visit of an `Ast::LoxSuperExpr` node
51
+ - Method `BackEnd::Engine#after_super_stmt` does the lookup of an inherited method.
52
+ - Method `BackEnd::Resolver#after_super_stmt` checks for correct context for super occurrence
53
+
54
+
55
+ ### Changed
56
+ - Method `Ast::ASTBuilder#reduce_class_decl` expanded in order to support superclass
57
+ - Class `Ast::LoxClassStmt` added `superclass` attribute, expanded constructor signature.
58
+ - Method `BackEnd::Engine#after_class_stmt` adds an environment for super variable.
59
+ - Class `BackEnd::LoxClass` added `superclass` attribute, expanded constructor signature.
60
+ - Method `BackEnd::LoxClass#find_method` now does the lookup in superclass(es)
61
+ - Method `BackEnd::Resolver#after_class_stmt` super variable resolution
62
+ - File `grammar.rb` changed rules to cope with superclass name and super keyword
63
+ - File `README.md` updated to reflect current implementation level
64
+
1
65
  ## [0.1.17] - 2021-04-11
2
- - TODO
66
+ - `Loxxy` now support custom initializer.
67
+
68
+ ### Changed
69
+ - Method `BackEnd::Class#call` updated for custom initializer.
70
+ - Class `BackEnd::LoxFunction` added an attribute `is_initializer`
71
+ - Class `BackEnd::Resolver#before_return_stmt` added a check that return in initializer may not return a value
3
72
 
4
73
  ### Fixed
5
- - TODO
74
+ - Method `BackEnd::Engine#after_call_expr` now does arity checking also for initalizer.
75
+ - Method `BackEnd::LoxInstance#set` removed the check of field existence that prevented the creation of ... fields
6
76
 
7
77
  ## [0.1.16] - 2021-04-10
8
78
  - Fixed an issue in name lookup. All the `this` test suite is passing.
data/README.md CHANGED
@@ -1,59 +1,213 @@
1
1
  # loxxy
2
2
  [![Gem Version](https://badge.fury.io/rb/loxxy.svg)](https://badge.fury.io/rb/loxxy)
3
+ [![Build status](https://ci.appveyor.com/api/projects/status/8e5p7dgjanm0qjkp?svg=true)](https://ci.appveyor.com/project/famished-tiger/loxxy)
3
4
  [![License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](https://github.com/famished-tiger/loxxy/blob/main/LICENSE.txt)
4
5
 
5
- ### What is loxxy?
6
+ ## What is loxxy?
6
7
  A Ruby implementation of the [Lox programming language](https://craftinginterpreters.com/the-lox-language.html ),
7
- a simple language defined in Bob Nystrom's online book [Crafting Interpreters](https://craftinginterpreters.com/ ).
8
+ a simple language defined in Bob Nystrom's excellent online book [Crafting Interpreters](https://craftinginterpreters.com/ ).
8
9
 
9
- ### Purpose of this project:
10
- - To deliver an open source example of a programming language fully implemented in Ruby
11
- (from the scanner and parser to an interpreter).
12
- - The implementation should be mature enough to run [LoxLox](https://github.com/benhoyt/loxlox),
13
- a Lox interpreter written in Lox.
10
+ Although __Lox__ is fairly simple, it is far from being a toy language:
11
+ - Dynamically typed,
12
+ - Provides data types such as booleans, number, strings,
13
+ - Supports arithmetic operations (+, -, *, / ) and comparison ( >, >= , <, <=)
14
+ - Implements equality operators (==, !=) and the logical connectors `and` and `or`.
15
+ - Control flow statements `if`, `for` and `while`
16
+ - Functions and closures
17
+ - Object-orientation (classes, methods, inheritance).
18
+
19
+ ### Loxxy gem features
20
+ - Complete tree-walking interpreter including lexer, parser and resolver
21
+ - 100% pure Ruby with clean design (not a port from some other language)
22
+ - Minimal runtime dependency (Rley gem). Won't drag a bunch of gems...
23
+ - Ruby API for integrating a Lox interpreter with your code.
24
+ - A command-line interpreter `loxxy`
25
+ - Open for your language extensions...
26
+
27
+ ## How to start in 1, 2, 3...?
28
+ ... in less than 3 minutes...
29
+
30
+ ### 1. Installing
31
+ __Loxxy__'s installation is pretty standard:
32
+
33
+
34
+ $ gem install loxxy
35
+
36
+ Alternatively, you can install `loxxy` with Bundler.
37
+ Add this line to your application's Gemfile:
38
+
39
+ gem 'loxxy'
40
+
41
+ And then execute:
42
+
43
+ $ bundle
44
+
45
+
46
+
47
+ ### 2. Your first `Lox` program
48
+ Create a text file and enter the following lines:
49
+ ```javascript
50
+ // Your firs Lox program
51
+ print "Hello, world.";
52
+ ```
53
+
54
+ ### 3. Running your program...
55
+ Assuming that you named the file `hello.lox`, launch the `Loxxy` interpreter in same directory:
56
+
57
+ $ loxxy hello.lox
58
+
59
+ Lo and behold! The output device displays the famous greeting:
60
+
61
+ Hello, world.
62
+
63
+
64
+ Congrats! You ran your first `Lox` program thanks __Loxxy__ gem.
65
+ For a less superficial encounter with the language jump to the next section.
66
+
67
+ ## So you want something beefier?...
68
+ Let's admit it, the hello world example was unimpressive.
69
+ To a get a taste of `Lox` object-oriented capabilities, let's try another `Hello world` variant:
70
+
71
+ ```javascript
72
+ // Object-oriented hello world
73
+ class Greeter {
74
+ // in Lox, initializers/constructors are named `init`
75
+ init(who) {
76
+ this.interjection = "Hello";
77
+ this.subject = who;
78
+ }
79
+
80
+ greeting() {
81
+ this.interjection + ", " + this.subject + ".";
82
+ }
83
+ }
84
+
85
+ var greeter = Greeter("world"); // an instance is created here...
86
+ print greeter.greeting();
87
+ ```
88
+
89
+ Running this version will result in the same famous greeting.
90
+
91
+ Our next assignment: compute the first 20 elements of the Fibbonacci sequence.
92
+ Here's an answer using the `while` loop construct:
93
+
94
+ ```javascript
95
+ // Compute the first 20 elements from the Fibbonacci sequence
96
+
97
+ var a = 0; // Use the var keyword to declare a new variable
98
+ var b = 1;
99
+ var count = 20;
100
+
101
+ while (count > 0) {
102
+ print a;
103
+ print " ";
104
+ var tmp = a;
105
+ a = b;
106
+ b = tmp + b;
107
+ count = count - 1;
108
+ }
109
+ ```
14
110
 
15
- ### Current status
16
- The interpreter currently can execute all allowed __Lox__ expressions and statements except
17
- object-oriented feaures (classes and objects).
18
- The goal is to implement these missing features in Q2 2021.
111
+ Assuming, that this source code was put in a file named `fibbonacci.lox`, then
112
+ the command line
19
113
 
114
+ $ loxxy fibbonacci.lox
115
+
116
+ Results in:
117
+
118
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
119
+
120
+ Fans of `for` loops will be pleased to find their favorite looping construct.
121
+ Here again, the Fibbonacci sequence refactored with a `for` loop:
122
+
123
+ ```javascript
124
+ // Fibbonacci sequence - version 2
125
+ var a = 0;
126
+ var b = 1;
127
+ var count = 20;
128
+
129
+ for (var i = 0; i < count; i = i + 1) {
130
+ print a;
131
+ print " ";
132
+ var tmp = a;
133
+ a = b;
134
+ b = tmp + b;
135
+ }
136
+ ```
137
+ Lets's call this file `fibbonacci_v2.lox` and execute it thanks `loxxy` CLI:
138
+
139
+ $ loxxy fibbonacci_v2.lox
140
+
141
+ We see again the same sequence:
142
+
143
+ 0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181
144
+
145
+ To complete our quick tour of `Lox` language, let's calculate the sequence with a recursive function:
146
+
147
+ ```javascript
148
+ // Fibbonacci sequence - version 3
149
+ var count = 20;
150
+
151
+ // Let's define a recursive function
152
+ fun fib(n) {
153
+ if (n < 2) return n;
154
+ return fib(n - 1) + fib(n - 2);
155
+ }
156
+
157
+ // For demo purposes, let's assign the function to a variable
158
+ var fib_fun = fib;
159
+
160
+ for (var i = 0; i < count; i = i + 1) {
161
+ print fib_fun(i);
162
+ print " ";
163
+ }
164
+ ```
165
+
166
+ This completes our quick tour of `Lox`, to learn more about the language,
167
+ check the online book [Crafting Interpreters](https://craftinginterpreters.com/ )
20
168
 
21
169
  ## What's the fuss about Lox?
22
170
  ... Nothing...
23
- Bob Nystrom designed a language __simple__ enough so that he could present
171
+ Bob Nystrom designed a language __simple__ enough so that he could present
24
172
  two implementations (an interpreter, then a compiler) in one single book.
25
173
 
26
- Although __Lox__ is fairly simple, it is far from a toy language:
27
- - Dynamically typed,
28
- - Provides datatypes such as booleans, number, strings,
29
- - Supports arithmetic operations (+, -, *, / ) and comparison ( >, >= , <, <=)
30
- - Implements equality operators (==, !=) and the logical connectors `and` and `or`.
31
- - Control flow statements `if`, `for` and `while`
32
- - Functions and closures
33
- - Object-orientation (classes, methods, inheritance).
174
+ In other words, __Lox__ contains interesting features found in most general-purpose
175
+ languages. In addition to that, there are [numerous implementations](https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations) in different languages
34
176
 
35
- In other words, __Lox__ contains interesting features found in most general-purpose
36
- languages.
177
+ Lox interpreters, like `Loxxy` give the unique opportunity for the curious to learn the internals of reasonably-sized language.
37
178
 
38
179
  ### What's missing in Lox?
39
- __Lox__ was constrained by design and was therefore not aimed to be a language used in real-world applications.
40
- Here are some missing parts to make it a _practical_ language:
41
- - Collections (arrays, maps, ...)
42
- - Modules (importing stuff from other packages/files)
43
- - Error handling (e.g. exceptions)
44
- - Support for concurrency (e.g. threads, coroutines)
180
+ While `Lox` blends interesting features from the two mainstream paradigms (OO and functional),
181
+ it doesn't pretend to be used in real-life projects.
45
182
 
46
- Also a decent standard library for IO, networking,... is lacking.
183
+ In fact, the language was designed to be simple to implement at the expense of missing advanced features.
184
+ Here are features I'll like to put on my wish list:
185
+ - Collection classes (e.g. Arrays, Maps (Hash))
186
+ - Modules
187
+ - Standard library
188
+ - Concurrency / parallelism constructs
47
189
 
48
- For sure, the language has shortcomings but on the other hand, it exhibits the essential features
49
- to cover in an introduction to language implementation.
190
+ That `Lox` cannot be compared to a full-featured language, is both a drawback and and an opportunity.
191
+ Indeed, an open-source language that misses some features is an invitation for the curious to tinker and experiment with extensions.
192
+ There are already a number of programming languages derived from `Lox`...
50
193
 
51
- That's already fun... and if all this gives you the inspiration for creating your own
52
- language, that might be even funnier...
194
+ ## Why `Loxxy`? What's in it for me?...
53
195
 
54
- Last point: what's makes __Lox__ interesting is the fact that there are implementations in many [languages](https://github.com/munificent/craftinginterpreters/wiki/Lox-implementations)
196
+ ### Purpose of this project:
197
+ - To deliver an open source example of a programming language fully implemented in Ruby
198
+ (from the scanner and parser to an interpreter).
199
+ - The implementation should be mature enough to run [LoxLox](https://github.com/benhoyt/loxlox),
200
+ a Lox interpreter written in Lox.
201
+
202
+ ### Roadmap
203
+ - Extend the test suite
204
+ - Improve the error handling
205
+ - Improve the documentation
206
+ - Ability run the LoxLox interpreter
55
207
 
56
208
  ## Hello world example
209
+ The next examples show how to use the interpreter directly from Ruby code.
210
+
57
211
  ```ruby
58
212
  require 'loxxy'
59
213
 
@@ -108,48 +262,10 @@ lox_input = <<-LOX_END
108
262
  print "Hello, world!";
109
263
  LOX_END
110
264
 
111
- # Show that the raw parser accepts the above program
112
- base_parser = Loxxy::FrontEnd::RawParser.new
113
-
114
- # Now parse the input into a concrete parse tree...
115
- ptree = base_parser.parse(lox_input)
116
-
117
- # Display the parse tree thanks to Rley formatters...
118
- visitor = Rley::ParseTreeVisitor.new(ptree)
119
- tree_formatter = Rley::Formatter::Asciitree.new($stdout)
120
- tree_formatter.render(visitor)
121
- ```
122
265
 
123
- This is the output produced by the above example:
124
- ```
125
- program
126
- +-- declaration_plus
127
- | +-- declaration
128
- | +-- statement
129
- | +-- printStmt
130
- | +-- PRINT: 'print'
131
- | +-- expression
132
- | | +-- assignment
133
- | | +-- logic_or
134
- | | +-- logic_and
135
- | | +-- equality
136
- | | +-- comparison
137
- | | +-- term
138
- | | +-- factor
139
- | | +-- unary
140
- | | +-- call
141
- | | +-- primary
142
- | | +-- STRING: '"Hello, world!"'
143
- | +-- SEMICOLON: ';'
144
- +-- EOF: ''
145
- ```
146
266
 
147
267
  ## Suppported Lox language features
148
- On one hand, the parser covers the complete Lox grammar and should therefore, in principle,
149
- parse any valid Lox program.
150
268
 
151
- On the other hand, the interpreter is under development and currently it can evaluate only a subset of __Lox__.
152
- But the situation is changing almost daily, stay tuned...
153
269
 
154
270
  Here are the language features currently supported by the interpreter:
155
271
 
@@ -377,25 +493,7 @@ fun add4(n) // `add4` will be the name of the function
377
493
  print add4(6); // output: 10
378
494
  ```
379
495
 
380
- ## Installation
381
-
382
- Add this line to your application's Gemfile:
383
-
384
- ```ruby
385
- gem 'loxxy'
386
- ```
387
-
388
- And then execute:
389
-
390
- $ bundle install
391
-
392
- Or install it yourself as:
393
-
394
- $ gem install loxxy
395
-
396
- ## Usage
397
496
 
398
- TODO: Write usage instructions here
399
497
 
400
498
  ## Other Lox implementations in Ruby
401
499