Giter Site home page Giter Site logo

linecode / berry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from berry-lang/berry

0.0 3.0 0.0 395 KB

A small dynamically typed embedded scripting language.

Home Page: https://gztss.github.io/berry

License: MIT License

Makefile 0.40% C 99.60%

berry's Introduction

Berry

Introduction

Berry is a small dynamically typed embedded scripting language. Berry's design goals include running on very small memory devices, and so, Berry must be very streamlined. Its core language only supports a few types, but we still provide class and closure support.

The implementation of Berry include a one pass compiler and register-based VM, all the codes are written in ANSI C. Berry is not everything is object. Some simple value types, such as int, real, boolean and string are not class object, but list, map and range are class object. This is a consideration about performance. Register-based VM is also based on this consideration.

Documents

https://gztss.github.io/berry

Features

  • Base Type
    • Numerical value: Integer (int) and Real (real)
    • Boolean: true and false
    • String: Single quotation-mark string and double quotation-mark string
    • List: Continuous memory list, like [1, 2, 3]
    • Map: Hash Map, like { 'a': 1, 2: 3, 'map': {} }
    • Range: include a lower and a upper integer value, like 0..5
  • Operator and Expression
    • Assign operator: =
    • Relational operator: <, <=, ==, !=, >, >=
    • Logic operator: &&, ||, !
    • Arithmetic operator: +, -, *, /, %
    • Field operator: .
    • Index operator: []
    • Connect string operator: +
    • Brackets: ()
  • Control Structure
    • Conditional statement: if-else
    • Iteration statement: while and for
    • Jump statement: break
  • Function
    • Local variable and block scope
    • Return statement
    • Nested functions definition
    • Closure based on Upvalue
  • Class
    • Inheritance (only public single inheritance)
    • Method and Operator Overload
    • Constructor method

Build

  1. install the readline library (Linux or MacOS)
sudo apt install libreadline-dev # Ubuntu
brew install readline            # MacOS
  1. Build:
make
  1. Run:
./berry # Bash
berry   # Windows CMD or PowerShell

Editor pulgins

Visual Studio Code pulgin are in this directory: ./tools/pulgins/vscode.

Examples

After compiling successfully, use the berry command with no parameters to enter the REPL environment:

Berry 0.0.1 (build in Dec 24 2018, 18:12:49)
[GCC 8.2.0] on Linux (default)
>

Now enter this code:

print("Hello world!")

You will see this output:

Hello world!

You can copy this code to the REPL:

def list_iter(list)
    index = 0
    def it()
        value = list[index]
        index = index + 1
        return value
    end
    return it
end
l = [0, 1, 2, 3, 4, 5]
lout = []
it = list_iter(l)
v = it()
while (v != nil)
    lout.append(v)
    v = it()
end
print(lout)

This examples is a simple list iterator. Let's look at the output:

[0, 1, 2, 3, 4, 5]

You can save the above code to a file (eg test.c) and run:

./berry test.be

This will also get the correct output.

berry's People

Watchers

 avatar  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.