Giter Club home page Giter Club logo

loxgo's Introduction

LoxGo

根据crafting interpreters中的教程一步步学习编译原理的知识,从零开始编写Lox语言,使用Golang语言编写。

进度

标注有*号为额外完成进度

  • 词法分析

  • 语法分析

  • (*) 类型系统

    • 内置类型及转换函数 (int, float, bool, string, array)
    • 获取类型对应字符串函数 (type)
    • 获取数组长度函数 (len)
  • 解释器

    • 表达式求值
    • (*) 自增自减运算符 a++; a--;++a;--a;
    • (*) 三目运算符 var b = a < 5 ? 0 : 1;
    • 输出语句 print a;
    • (*) (多)变量定义语句 var a = 2, b = 3;
    • 变量赋值语句 a = 5;
    • 控制流相关
      • if if (condition) {statments...} else {statments...}
      • while while(condition) {statments...}
      • for for (init;cond;inc) {statments...}
      • (*) break break;
      • (*) continue continue;
    • 函数相关
      • 函数定义 fun demo(a, b) {statments...}
      • 函数调用 demo(1, 2);
      • (*) return语句 return a+b; (并非使用异常来处理返回值)
      • 闭包
      • (*) 匿名函数 demo(func(a) {statments...}, 0)
    • 静态解析
      • 变量作用域
      • 在块中重定义变量错误
      • 在非函数中使用return语句错误
    • 类相关
      • 类的定义与实例化
      • 类的实例属性
      • 类方法与this
      • 类的构造函数与返回
      • 静态方法
      • 类的继承
  • 使用

go run main.go # 进入交互模式
go run main.go ./tests/if.lox # 运行文件

参考

loxgo's People

Contributors

way29 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

loxgo's Issues

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.