Giter Site home page Giter Site logo

woo's Introduction

Woo

一个简单的编译器原型,语法规则继承了pascal和python的风格。

学习过程分享:

  • 先写了一个简单的正则引擎,然后基于这个正则引擎快速写出词法分析器,参考轮子哥的博客
  • 语法分析部分就是经典的递归下降方法生成AST,codgen过程用虚函数,真的很简洁也利于理解,参考llvm tutorial
  • 虚拟机部分关键是理解工作原理,可以参考知乎上相关答案

Supports

  • 语法
    • 类型:整数,字符串
    • 运算:算数表达式计算
    • 控制结构:while
    • 条件表达式:>,<,>=,<=
    • 函数:参数列表,递归调用
    • 内置函数:print
  • 编译器功能
    • 编译错误提示
    • 编译成功后,输出中间代码文件,需要配合Wvm解释中间代码。

Syntax

语法特点:

  • 每行代码以换行结束

  • 变量不需要定义,直接使用,因为默认初始化为0了。

  • 函数定义使用def 关键字,后面接一对圆括号,括号内为参数列表,函数以end结束。

     def func()
     	. . .
     	代码
     	. . . 
     end
     
    
  • while也需要以end结束

     while(a>b)
     	...
     	...
     end
     
    
  • 内置输出函数print(参数列表)括号里可以是表达式或者字符串,也可以接收多个参数。

     a = 1
     b = "hello"
     print(a,b)
     
    

Example

  • 编译错误提示 img

  • 打印一个心型图案(其实包括Woo这个语言的命名,都是受Leviathan1995的鼓舞,haha)源代码

    img

woo's People

Contributors

tvytlx avatar

Watchers

James Cloos avatar Slanterns avatar  avatar

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.