GithubHelp home page GithubHelp logo

yak's Introduction

the Yak Programming Language

warning: this project is still on working

Yak projects can be compiled into a Scratch(.sb3) file.

Docs

  1. Compiler - RIP

  2. Yak Guide

    Yak's syntax is like Python, but it only allows definitions in the top-level scope. Here is an example of a yak source file:

    def Fact(n) -> num:
        if n < 2:
            return 1
        return n * Fact(n - 1)

    It looks like Python, isn't it? Okay, let's get Yaking.

    Identifiers

    Identifiers can include letters, the underscore(_) and numbers and identifiers cannot start with a number.

    Yak has some keywords that cannot be used as an identifier. Here are these keywords:

    def struct use for in while if elif else return unit  num str bool list nil _
    

    Yak has another identifier that can include any charactors you want, they start with a r# and end with a #.

    Identifier can be connect into a new identifier using ::. Here are some examples:

    abc r#+# r#def# abc::ghi::r#return#
    

    Fucntions

    Functions start with a def keyword, an identifier, an optional generics list, an argument list, an optional return type, a colon(:) and a function body. A empty body must include a ....

    warning: a function with generic types or struct types cannot be compiled into a vaild Scratch project

    def Func1():
        ...
     
    def Func2<T, U>(a: T, b: num, c, d: U) -> num:
        ...

    Yak's compiler will try to infer the type of identifiers with no type hint and produce an error if the compiler fails to infer.

    Structs

    Structs start with a struct keyword, an identifier, an optional generics list, a colon(:) and a struct body. Empty structs are not allowed.

    struct Pair<T, U>:
        _0: T
        _1: U

    Call a function with generics

    If you want to call a function with generics, you need to use ::<> after the function name to specify the function's type. Here's an Example:

    def Eq<T>(lhs: T, rhs: T) -> bool:
        return lhs == rhs
    
    def Test(x: num, y: num) -> bool:
        return Eq::<num>(x, y)

    Globals

    An identifier starts with a uppercase letter will be exported to the global scope.

  3. How does yak work?

    warning: this session is still on working

    First, yak's compiler spilts the source file into tokens and parses them into an AST(Abstract Syntax Tree) object. Second, scan the AST and bind all identifiers to its definition. Third, infer the type of any identifiers and expressions. Fourth, translate the AST into a lower Scratch IR and emits a vaild json of some Scratch blocks.

    An example of lower Scratch IR translation:

    def Fact(n):
        if n < 2:
            return 1
        return n * Fact(n - 1)

    the lower Scratch IR:

yak's People

Contributors

yukitai avatar

Stargazers

tourkveg avatar nights avatar

Watchers

 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.