├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── asset ├── index.scss ├── mustache │ ├── contents-nav.html │ ├── contents-part.html │ ├── contents.html │ ├── footer.html │ ├── header.html │ ├── in_design.html │ ├── index.html │ ├── nav.html │ ├── page.html │ └── prev-next.html ├── sass │ ├── chapter.scss │ ├── contents.scss │ ├── print.scss │ ├── shared.scss │ └── sign-up.scss └── style.scss ├── book ├── a-bytecode-virtual-machine.md ├── a-map-of-the-territory.md ├── a-tree-walk-interpreter.md ├── a-virtual-machine.md ├── acknowledgements.md ├── appendix-i.md ├── appendix-ii.md ├── backmatter.md ├── calls-and-functions.md ├── chunks-of-bytecode.md ├── classes-and-instances.md ├── classes.md ├── closures.md ├── compiling-expressions.md ├── contents.md ├── control-flow.md ├── dedication.md ├── evaluating-expressions.md ├── functions.md ├── garbage-collection.md ├── global-variables.md ├── hash-tables.md ├── index.md ├── inheritance.md ├── introduction.md ├── jumping-back-and-forth.md ├── local-variables.md ├── methods-and-initializers.md ├── optimization.md ├── parsing-expressions.md ├── representing-code.md ├── resolving-and-binding.md ├── scanning-on-demand.md ├── scanning.md ├── statements-and-state.md ├── strings.md ├── superclasses.md ├── the-lox-language.md ├── types-of-values.md └── welcome.md ├── c ├── chunk.c ├── chunk.h ├── clox.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ ├── IDEWorkspaceChecks.plist │ │ │ └── WorkspaceSettings.xcsettings │ └── xcshareddata │ │ └── xcschemes │ │ └── clox.xcscheme ├── common.h ├── compiler.c ├── compiler.h ├── debug.c ├── debug.h ├── main.c ├── memory.c ├── memory.h ├── object.c ├── object.h ├── scanner.c ├── scanner.h ├── table.c ├── table.h ├── value.c ├── value.h ├── vm.c └── vm.h ├── java └── com │ └── craftinginterpreters │ ├── lox │ ├── AstPrinter.java │ ├── Environment.java │ ├── Expr.java │ ├── Interpreter.java │ ├── Lox.java │ ├── LoxCallable.java │ ├── LoxClass.java │ ├── LoxFunction.java │ ├── LoxInstance.java │ ├── Parser.java │ ├── Resolver.java │ ├── Return.java │ ├── RuntimeError.java │ ├── Scanner.java │ ├── Stmt.java │ ├── Token.java │ └── TokenType.java │ └── tool │ └── GenerateAst.java ├── jlox ├── note ├── BISAC.txt ├── answers │ ├── chapter01_introduction │ │ ├── 2 │ │ │ ├── Hello.java │ │ │ └── Makefile │ │ ├── 3 │ │ │ ├── Makefile │ │ │ ├── linked_list │ │ │ ├── linked_list.c │ │ │ └── linked_list.xcodeproj │ │ │ │ ├── project.pbxproj │ │ │ │ └── project.xcworkspace │ │ │ │ └── contents.xcworkspacedata │ │ └── 1.md │ ├── chapter02_map.md │ ├── chapter03_lox.md │ ├── chapter04_scanning.md │ ├── chapter05_representing.md │ ├── chapter06_parsing.md │ ├── chapter07_evaluating.md │ ├── chapter08_statements.md │ ├── chapter09_control.md │ ├── chapter10_functions.md │ ├── chapter11_resolving │ │ ├── 4 │ │ │ └── com │ │ │ │ └── craftinginterpreters │ │ │ │ ├── lox │ │ │ │ ├── AstPrinter.java │ │ │ │ ├── Environment.java │ │ │ │ ├── Expr.java │ │ │ │ ├── Interpreter.java │ │ │ │ ├── Lox.java │ │ │ │ ├── LoxCallable.java │ │ │ │ ├── LoxFunction.java │ │ │ │ ├── Parser.java │ │ │ │ ├── Resolver.java │ │ │ │ ├── Return.java │ │ │ │ ├── RuntimeError.java │ │ │ │ ├── Scanner.java │ │ │ │ ├── Stmt.java │ │ │ │ ├── Token.java │ │ │ │ └── TokenType.java │ │ │ │ └── tool │ │ │ │ └── GenerateAst.java │ │ └── chapter11_resolving.md │ ├── chapter12_classes.md │ ├── chapter13_inheritance │ │ ├── 1.md │ │ ├── 2.md │ │ └── 3.md │ ├── chapter14_chunks │ │ ├── 1.md │ │ └── 2.md │ ├── chapter15_virtual │ │ ├── 1.md │ │ ├── 2.md │ │ └── 3.md │ ├── chapter16_scanning.md │ ├── chapter17_compiling.md │ ├── chapter18_types.md │ ├── chapter19_strings.md │ ├── chapter20_hash │ │ └── 1.md │ ├── chapter21_global.md │ ├── chapter23_jumping │ │ ├── 1.md │ │ ├── 2.md │ │ └── 3.md │ ├── chapter24_calls │ │ ├── 1.md │ │ └── 2.md │ ├── chapter25_closures │ │ ├── 1.md │ │ ├── 2.md │ │ └── 3.lox │ ├── chapter26_garbage │ │ ├── 1.md │ │ └── 2.md │ ├── chapter27_classes │ │ ├── 1.md │ │ ├── 2.md │ │ ├── 3.md │ │ └── 4.md │ ├── chapter28_methods │ │ ├── 1.md │ │ ├── 2.md │ │ └── 3.md │ └── chapter29_superclasses │ │ ├── 1.md │ │ ├── 2.md │ │ ├── 3.diff │ │ └── 3.md ├── blurb.txt ├── contents.txt ├── design breaks.md ├── images.md ├── indexing.md ├── log.txt ├── names.txt ├── objects.txt ├── outline.md ├── research.txt ├── scope.txt ├── struct sizes.txt ├── style guide.md └── todo.txt ├── site ├── .htaccess ├── 404.html ├── a-bytecode-virtual-machine.html ├── a-map-of-the-territory.html ├── a-tree-walk-interpreter.html ├── a-virtual-machine.html ├── acknowledgements.html ├── appendix-i.html ├── appendix-ii.html ├── backmatter.html ├── calls-and-functions.html ├── chunks-of-bytecode.html ├── classes-and-instances.html ├── classes.html ├── closures.html ├── columns.png ├── compiling-expressions.html ├── contents.html ├── control-flow.html ├── dedication.html ├── evaluating-expressions.html ├── font │ ├── crimson-bold.woff │ ├── crimson-bolditalic.woff │ ├── crimson-italic.woff │ ├── crimson-roman.woff │ ├── crimson-semibold.woff │ └── crimson-semibolditalic.woff ├── functions.html ├── garbage-collection.html ├── global-variables.html ├── hash-tables.html ├── image │ ├── a-map-of-the-territory │ │ ├── ast.png │ │ ├── mountain.png │ │ ├── plants.png │ │ ├── string.png │ │ ├── tokens.png │ │ └── venn.png │ ├── a-virtual-machine │ │ ├── array.png │ │ ├── ast.png │ │ ├── bars-stacked.png │ │ ├── bars.png │ │ ├── chunk.png │ │ ├── pancakes.png │ │ ├── reverse.png │ │ ├── stack-c.png │ │ ├── stack-crepe.png │ │ └── stack-empty.png │ ├── background.png │ ├── calls-and-functions │ │ ├── argument-stack.png │ │ ├── arithmetic.png │ │ ├── calls.png │ │ ├── overlapping-windows.png │ │ ├── parameter-window.png │ │ ├── return.png │ │ └── window.png │ ├── chunks-of-bytecode │ │ ├── ast.png │ │ ├── format.png │ │ ├── grow.png │ │ ├── insert.png │ │ └── phases.png │ ├── classes-and-instances │ │ ├── klass.png │ │ ├── lox-clox.png │ │ └── stack.png │ ├── classes │ │ ├── bound-method.png │ │ ├── call.png │ │ ├── circle.png │ │ ├── closure.png │ │ ├── method.png │ │ ├── setter.png │ │ └── zip.png │ ├── closures │ │ ├── closing.png │ │ ├── execution-flow.png │ │ ├── flying.png │ │ ├── linked-list.png │ │ ├── linked-upvalues.png │ │ ├── obj-closure.png │ │ ├── open-upvalue.png │ │ └── recursion.png │ ├── compiling-expressions │ │ ├── calls.png │ │ ├── connections.png │ │ ├── keyhole.png │ │ ├── mystery.png │ │ ├── pipeline.png │ │ └── points-to.png │ ├── control-flow │ │ ├── dangling-else.png │ │ ├── sugar.png │ │ └── turing-machine.png │ ├── dogshot.jpg │ ├── evaluating-expressions │ │ ├── lightning.png │ │ ├── muffin.png │ │ └── skeleton.png │ ├── favicon.png │ ├── format-ebook.jpg │ ├── format-pdf.jpg │ ├── format-print.jpg │ ├── format-web.jpg │ ├── functions │ │ ├── binding.png │ │ ├── body.png │ │ ├── closure.png │ │ ├── foreign.png │ │ ├── global.png │ │ ├── lambda.png │ │ └── recursion.png │ ├── garbage-collection │ │ ├── baguette.png │ │ ├── black.png │ │ ├── gray.png │ │ ├── latency-throughput.png │ │ ├── mark-sweep.png │ │ ├── reachable.png │ │ ├── recycle.png │ │ ├── stack.png │ │ ├── tricolor-trace.png │ │ ├── unlink.png │ │ └── white.png │ ├── ginny.png │ ├── global-variables │ │ ├── ast-bad.png │ │ ├── ast-good.png │ │ ├── setter.png │ │ └── stack-effect.png │ ├── hash-tables │ │ ├── bucket-array.png │ │ ├── chaining.png │ │ ├── collision.png │ │ ├── delete-1.png │ │ ├── delete-2.png │ │ ├── delete-3.png │ │ ├── insert-1.png │ │ ├── insert-2.png │ │ ├── insert-3.png │ │ ├── insert-4.png │ │ ├── insert-5.png │ │ ├── insert-6.png │ │ ├── insert-7.png │ │ ├── pigeons.png │ │ └── tombstone.png │ ├── header-small.png │ ├── header.png │ ├── inheritance │ │ ├── classes.png │ │ ├── doughnuts.png │ │ ├── environments.png │ │ ├── superclass.png │ │ └── superhero.png │ ├── introduction │ │ ├── bootstrap.png │ │ ├── little-languages.png │ │ └── yak.png │ ├── jumping-back-and-forth │ │ ├── and.png │ │ ├── bad-else.png │ │ ├── for.png │ │ ├── full-if-else.png │ │ ├── if-else.png │ │ ├── if-without-else.png │ │ ├── or.png │ │ ├── patch.png │ │ └── while.png │ ├── local-variables │ │ ├── block.png │ │ ├── declaration.png │ │ ├── local-slots.png │ │ ├── phases.png │ │ └── scopes.png │ ├── logotype.png │ ├── methods-and-initializers │ │ ├── benchmark.png │ │ ├── bind-method.png │ │ ├── closure-slot.png │ │ ├── init-call-frame.png │ │ ├── method-instructions.png │ │ └── party-hat.png │ ├── optimization │ │ ├── bools.png │ │ ├── double.png │ │ ├── hash-chart.png │ │ ├── mask.png │ │ ├── nan.png │ │ ├── nil.png │ │ ├── obj.png │ │ ├── qnan.png │ │ └── union.png │ ├── parsing-expressions │ │ ├── direction.png │ │ ├── panic.png │ │ ├── sequence.png │ │ ├── syntax-trees.png │ │ └── tokens.png │ ├── representing-code │ │ ├── breakfast.png │ │ ├── columns.png │ │ ├── expression.png │ │ ├── rows.png │ │ ├── table.png │ │ ├── tree-evaluate.png │ │ └── visitor.png │ ├── resolving-and-binding │ │ ├── environment-1.png │ │ ├── environment-2.png │ │ ├── environment-3.png │ │ ├── environment-4.png │ │ ├── environment-5.png │ │ └── split.png │ ├── scanning-on-demand │ │ ├── axolotl.png │ │ ├── fields.png │ │ ├── keywords.png │ │ ├── numbers.png │ │ └── pipeline.png │ ├── scanning │ │ ├── lexemes.png │ │ └── lexigator.png │ ├── statements-and-state │ │ ├── blocks.png │ │ ├── brain.png │ │ ├── cactus.png │ │ ├── chaining.png │ │ └── environment.png │ ├── strings │ │ ├── obj.png │ │ ├── pstring.png │ │ ├── stack.png │ │ ├── value.png │ │ └── viola.png │ ├── superclasses │ │ ├── clox-resolve.png │ │ ├── inherit-stack.png │ │ ├── jlox-resolve.png │ │ ├── monkey.png │ │ ├── super-instructions.png │ │ └── super-invoke.png │ ├── the-lox-language │ │ ├── class-lookup.png │ │ └── prototype-lookup.png │ ├── types-of-values │ │ ├── memcmp.png │ │ ├── struct.png │ │ ├── union.png │ │ ├── universe.png │ │ └── value.png │ └── wood.jpg ├── index.css ├── index.css.map ├── index.html ├── inheritance.html ├── introduction.html ├── jquery-3.4.1.min.js ├── jumping-back-and-forth.html ├── local-variables.html ├── methods-and-initializers.html ├── optimization.html ├── parsing-expressions.html ├── representing-code.html ├── resolving-and-binding.html ├── rows-22.png ├── rows.png ├── sample.pdf ├── scanning-on-demand.html ├── scanning.html ├── script.js ├── statements-and-state.html ├── strings.html ├── style.css ├── style.css.map ├── superclasses.html ├── the-lox-language.html ├── types-of-values.html └── welcome.html ├── test ├── assignment │ ├── associativity.lox │ ├── global.lox │ ├── grouping.lox │ ├── infix_operator.lox │ ├── local.lox │ ├── prefix_operator.lox │ ├── syntax.lox │ ├── to_this.lox │ └── undefined.lox ├── benchmark │ ├── binary_trees.lox │ ├── equality.lox │ ├── fib.lox │ ├── instantiation.lox │ ├── invocation.lox │ ├── method_call.lox │ ├── properties.lox │ ├── string_equality.lox │ ├── trees.lox │ ├── zoo.lox │ └── zoo_batch.lox ├── block │ ├── empty.lox │ └── scope.lox ├── bool │ ├── equality.lox │ └── not.lox ├── call │ ├── bool.lox │ ├── nil.lox │ ├── num.lox │ ├── object.lox │ └── string.lox ├── class │ ├── empty.lox │ ├── inherit_self.lox │ ├── inherited_method.lox │ ├── local_inherit_other.lox │ ├── local_inherit_self.lox │ ├── local_reference_self.lox │ └── reference_self.lox ├── closure │ ├── assign_to_closure.lox │ ├── assign_to_shadowed_later.lox │ ├── close_over_function_parameter.lox │ ├── close_over_later_variable.lox │ ├── close_over_method_parameter.lox │ ├── closed_closure_in_function.lox │ ├── nested_closure.lox │ ├── open_closure_in_function.lox │ ├── reference_closure_multiple_times.lox │ ├── reuse_closure_slot.lox │ ├── shadow_closure_with_local.lox │ ├── unused_closure.lox │ └── unused_later_closure.lox ├── comments │ ├── line_at_eof.lox │ ├── only_line_comment.lox │ ├── only_line_comment_and_line.lox │ └── unicode.lox ├── constructor ├── empty_file.lox ├── expressions │ ├── evaluate.lox │ └── parse.lox ├── field │ ├── call_function_field.lox │ ├── call_nonfunction_field.lox │ ├── get_and_set_method.lox │ ├── get_on_bool.lox │ ├── get_on_class.lox │ ├── get_on_function.lox │ ├── get_on_nil.lox │ ├── get_on_num.lox │ ├── get_on_string.lox │ ├── many.lox │ ├── method.lox │ ├── method_binds_this.lox │ ├── on_instance.lox │ ├── set_evaluation_order.lox │ ├── set_on_bool.lox │ ├── set_on_class.lox │ ├── set_on_function.lox │ ├── set_on_nil.lox │ ├── set_on_num.lox │ ├── set_on_string.lox │ └── undefined.lox ├── for │ ├── class_in_body.lox │ ├── closure_in_body.lox │ ├── fun_in_body.lox │ ├── return_closure.lox │ ├── return_inside.lox │ ├── scope.lox │ ├── statement_condition.lox │ ├── statement_increment.lox │ ├── statement_initializer.lox │ ├── syntax.lox │ └── var_in_body.lox ├── function │ ├── body_must_be_block.lox │ ├── empty_body.lox │ ├── extra_arguments.lox │ ├── local_mutual_recursion.lox │ ├── local_recursion.lox │ ├── missing_arguments.lox │ ├── missing_comma_in_parameters.lox │ ├── mutual_recursion.lox │ ├── nested_call_with_arguments.lox │ ├── parameters.lox │ ├── print.lox │ ├── recursion.lox │ ├── too_many_arguments.lox │ └── too_many_parameters.lox ├── if │ ├── class_in_else.lox │ ├── class_in_then.lox │ ├── dangling_else.lox │ ├── else.lox │ ├── fun_in_else.lox │ ├── fun_in_then.lox │ ├── if.lox │ ├── truth.lox │ ├── var_in_else.lox │ └── var_in_then.lox ├── inheritance │ ├── constructor.lox │ ├── inherit_from_function.lox │ ├── inherit_from_nil.lox │ ├── inherit_from_number.lox │ ├── inherit_methods.lox │ ├── parenthesized_superclass.lox │ └── set_fields_from_base_class.lox ├── limit │ ├── loop_too_large.lox │ ├── no_reuse_constants.lox │ ├── stack_overflow.lox │ ├── too_many_constants.lox │ ├── too_many_locals.lox │ └── too_many_upvalues.lox ├── logical_operator │ ├── and.lox │ ├── and_truth.lox │ ├── or.lox │ └── or_truth.lox ├── method │ ├── arity.lox │ ├── empty_block.lox │ ├── extra_arguments.lox │ ├── missing_arguments.lox │ ├── not_found.lox │ ├── print_bound_method.lox │ ├── refer_to_name.lox │ ├── too_many_arguments.lox │ └── too_many_parameters.lox ├── nil │ └── literal.lox ├── number │ ├── decimal_point_at_eof.lox │ ├── leading_dot.lox │ ├── literals.lox │ ├── nan_equality.lox │ └── trailing_dot.lox ├── operator │ ├── add.lox │ ├── add_bool_nil.lox │ ├── add_bool_num.lox │ ├── add_bool_string.lox │ ├── add_nil_nil.lox │ ├── add_num_nil.lox │ ├── add_string_nil.lox │ ├── comparison.lox │ ├── divide.lox │ ├── divide_nonnum_num.lox │ ├── divide_num_nonnum.lox │ ├── equals.lox │ ├── equals_class.lox │ ├── equals_method.lox │ ├── greater_nonnum_num.lox │ ├── greater_num_nonnum.lox │ ├── greater_or_equal_nonnum_num.lox │ ├── greater_or_equal_num_nonnum.lox │ ├── less_nonnum_num.lox │ ├── less_num_nonnum.lox │ ├── less_or_equal_nonnum_num.lox │ ├── less_or_equal_num_nonnum.lox │ ├── multiply.lox │ ├── multiply_nonnum_num.lox │ ├── multiply_num_nonnum.lox │ ├── negate.lox │ ├── negate_nonnum.lox │ ├── not.lox │ ├── not_class.lox │ ├── not_equals.lox │ ├── subtract.lox │ ├── subtract_nonnum_num.lox │ └── subtract_num_nonnum.lox ├── precedence.lox ├── print │ └── missing_argument.lox ├── regression │ ├── 394.lox │ └── 40.lox ├── return │ ├── after_else.lox │ ├── after_if.lox │ ├── after_while.lox │ ├── at_top_level.lox │ ├── in_function.lox │ ├── in_method.lox │ └── return_nil_if_no_value.lox ├── scanning │ ├── identifiers.lox │ ├── keywords.lox │ ├── numbers.lox │ ├── punctuators.lox │ ├── strings.lox │ └── whitespace.lox ├── string │ ├── error_after_multiline.lox │ ├── literals.lox │ ├── multiline.lox │ └── unterminated.lox ├── super │ ├── bound_method.lox │ ├── call_other_method.lox │ ├── call_same_method.lox │ ├── closure.lox │ ├── constructor.lox │ ├── extra_arguments.lox │ ├── indirectly_inherited.lox │ ├── missing_arguments.lox │ ├── no_superclass_bind.lox │ ├── no_superclass_call.lox │ ├── no_superclass_method.lox │ ├── parenthesized.lox │ ├── reassign_superclass.lox │ ├── super_at_top_level.lox │ ├── super_in_closure_in_inherited_method.lox │ ├── super_in_inherited_method.lox │ ├── super_in_top_level_function.lox │ ├── super_without_dot.lox │ ├── super_without_name.lox │ └── this_in_superclass_method.lox ├── this │ ├── closure.lox │ ├── nested_class.lox │ ├── nested_closure.lox │ ├── this_at_top_level.lox │ ├── this_in_method.lox │ └── this_in_top_level_function.lox ├── unexpected_character.lox ├── variable │ ├── collide_with_parameter.lox │ ├── duplicate_local.lox │ ├── duplicate_parameter.lox │ ├── early_bound.lox │ ├── in_middle_of_block.lox │ ├── in_nested_block.lox │ ├── local_from_method.lox │ ├── redeclare_global.lox │ ├── redefine_global.lox │ ├── scope_reuse_in_different_blocks.lox │ ├── shadow_and_local.lox │ ├── shadow_global.lox │ ├── shadow_local.lox │ ├── undefined_global.lox │ ├── undefined_local.lox │ ├── uninitialized.lox │ ├── unreached_undefined.lox │ ├── use_false_as_var.lox │ ├── use_global_in_initializer.lox │ ├── use_local_in_initializer.lox │ ├── use_nil_as_var.lox │ └── use_this_as_var.lox └── while │ ├── class_in_body.lox │ ├── closure_in_body.lox │ ├── fun_in_body.lox │ ├── return_closure.lox │ ├── return_inside.lox │ ├── syntax.lox │ └── var_in_body.lox ├── tool ├── analysis_options.yaml ├── bin │ ├── benchmark.dart │ ├── build.dart │ ├── build_xml.dart │ ├── compile_snippets.dart │ ├── split_chapters.dart │ ├── test.dart │ └── tile_pages.dart ├── lib │ └── src │ │ ├── book.dart │ │ ├── code_tag.dart │ │ ├── format.dart │ │ ├── location.dart │ │ ├── markdown │ │ ├── block_syntax.dart │ │ ├── code_syntax.dart │ │ ├── html_renderer.dart │ │ ├── inline_syntax.dart │ │ ├── markdown.dart │ │ └── xml_renderer.dart │ │ ├── mustache.dart │ │ ├── page.dart │ │ ├── page_parser.dart │ │ ├── snippet.dart │ │ ├── source_file_parser.dart │ │ ├── split_chapter.dart │ │ ├── syntax │ │ ├── grammar.dart │ │ ├── highlighter.dart │ │ ├── language.dart │ │ └── rule.dart │ │ ├── term.dart │ │ └── text.dart ├── pubspec.lock └── pubspec.yaml └── util ├── c.make ├── intellij ├── chap04_read.iml ├── chap05_scanning.iml ├── chap06_representing.iml ├── chap07_parsing.iml ├── chap08_evaluating.iml ├── chap09_statements.iml ├── chap10_control.iml ├── chap11_functions.iml ├── chap12_resolving.iml ├── chap13_classes.iml ├── chap14_inheritance.iml ├── intellij.iml ├── jlox.iml ├── section_test.iml └── snippet_test.iml └── java.make /.gitignore: -------------------------------------------------------------------------------- 1 | # Intermediate and built stuff. 2 | .sass-cache/ 3 | /build/ 4 | /gen/ 5 | clox 6 | *.class 7 | exercises/chapter01_introduction/3/linked_list 8 | .idea/ 9 | 10 | # I keep a scratch file at the top level to try stuff out. 11 | temp.lox 12 | 13 | # XCode user-specific stuff. 14 | xcuserdata/ 15 | 16 | # Dart stuff. 17 | /tool/.dart_tool/ 18 | /tool/.packages 19 | -------------------------------------------------------------------------------- /asset/mustache/contents-nav.html: -------------------------------------------------------------------------------- 1 |