Giter VIP home page Giter VIP logo

slox's Introduction

slox

Lox解释器的Swift实现版本

Lox是一门迷你编程语言,来自于Bob Nystrom写的编译器教程Crafting Interpreters

UPDATE 2022/05/27 已经完成本书PART II

实现

会尽量参照书中PART II所示的Java代码结构来实现

但是Swift本身有太多优秀和新奇的特点,比如enumOptionalPOP等,我也会使用这些Swift独占特性,但整体的结构和逻辑应该和书本上的并无太大差异

To-Do

  • 4. Scanning

    • Challenge 4: C-style /* ... */ block comments.
  • 5. Representing Code

    • Challenge 3: AST Printer In Reverse Polish Notation.
    • GenerateAst tool
  • 6. Parsing Expressions

    • Challenge 1: Add prefix and postfix ++ and -- operators.
    • Challenge 2: Add support for the C-style conditional or “ternary” operator ?:
    • Challenge 3: Add error productions to handle each binary operator appearing without a left-hand operand.
  • 7. Evaluating Expressions

    • Challenge 1: Allowing comparisons on types other than numbers could be useful.
    • Challenge 2: Many languages define + such that if either operand is a string, the other is converted to a string and the results are then concatenated.
    • Challenge 3: Change the implementation in visitBinary() to detect and report a runtime error when dividing by 0.
  • 8. Statements and State

    • Challenge 1: Add support to the REPL to let users type in both statements and expressions.
    • Challenge 2: Make it a runtime error to access a variable that has not been initialized or assigned to
  • 9. Control Flow

    • Challenge 3: Add support for break statements.
  • 10. Functions

    • Challenge 2: Add anonymous function (lambdas) syntax.
  • 11. Resolving and Binding

    • Challenge 3: Extend the resolver to report an error if a local variable is never used.
    • Challenge 4: Store local variables in an array and look them up by index.
  • 12. Classes

    • Challenge 1: Add class methods.
    • Challenge 2: Support getter methods.
  • 13. Inheritance

    • Challenge 1: Multiple inheritance. Nothing to implement...?
    • Challenge 2: Reverse method lookup order in class hierarchy.

测试

我尽量使用TDD的**来开发每个阶段,所以Xcode工程中包含了使用XCTest实现的单元测试文件。

工程结构

使用 SPM 来管理frameworks、依赖文件

解释器的主体实现包含在一个framework中,通过一个简单的CLI程序使用该framework来运行解释器

  • slox: 可执行文件,用于在CLI中直接运行解释器
  • LoxCore: 包含Lox核心实现的Swift framework

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.