Giter Club home page Giter Club logo

lioness's Introduction

Lioness CubSavannaKit

Lioness Logo

The Lioness Programming Language

Travis build status Codecov
version 0.5.2 Carthage Compatible Swift Platform: iOS macOS tvOS watchOS Extension: .lion
Twitter Donate via PayPal

Lioness is a high-level, dynamic, programming language designed for mathematical purposes. This project includes a lexer, parser, compiler and interpreter. All of these are 100% written in Swift without dependencies.

The syntax of Lioness is inspired by Swift, and its feature set is akin to shader languages such as GLSL.

The standard library (abbreviated: stdlib) contains basic functions for number manipulation, including: max/min, ceil, floor, trigonometry, etc. However, more trivial functions, such as to calculate prime numbers, are not considered relevant for the standard library.

Source examples

The following Lioness code calculates factorials recursively:

func factorial(x) returns {
	
    if x > 1 {
        return x * factorial(x - 1)
    }
	
    return 1
}

a = factorial(5) // a = 120

The following Lioness code uses a do times loop:

a = 1
n = 10
do n times {
    a += a
}
// a = 1024

More examples can be found here.

Features

  • Minimalistic, yet expressive, syntax
  • No type system, language is dynamic
  • 5 basic operators: +, -, /, * and ^
    • ^ means "to the power of", e.g. 2^10 equals 1024
    • all operators have a shorthand, e.g. += for +
  • Numbers
    • All numbers are floating point
  • Booleans
    • Can be evaluated from comparison
    • Can be defined by literal: true or false
  • Functions
    • Supports parameters, returning and recursion
    • Can be declared inside other functions
  • Structs
    • Can contain any type, including other structs
  • Loops
    • for
    • while
    • do times
    • repeat while
    • break
    • continue
  • if / else / else if statements

Running

Since the project does not rely on any dependencies, running it requires no setup.

macOS

Open Lioness.xcworkspace (preferably in the latest non-beta version of Xcode) and run the macOS Example target. The example will run the code in A.lion. The output will be printed to the console.

Installing framework

Using Swift Package Manager

Add to your Package.swift file's dependencies section:

.Package(url: "https://github.com/louisdh/lioness.git",
		         majorVersion: 0, minor: 5)

Using CocoaPods

Add the following line to your Podfile:

pod 'Lioness', '~> 0.5'

Using Carthage

Add the following line to your Cartfile:

github "louisdh/lioness" ~> 0.5

Run carthage update to build the framework and drag the built Lioness.framework into your Xcode project.

Standard Library

Please note: Lioness is currently in beta

The Standard Library is currently under active development. There currently is no one document with everything from the stdlib. The best place to look for what's available is in the source files.

Roadmap

  • Structs
  • Completion suggestions (given an incomplete source string and insertion point)
  • Breakpoint support in interpreter
  • Stdlib documentation (Dash?)
  • Compiler warnings
  • Compiler optimizations
  • Faster Lexer (without regex)
  • Support emoticons for identifier names
  • guard statement
  • A lot more unit tests
  • Linux support

Xcode file template

Lioness source files can easily be created with Xcode, see XcodeTemplate.md for instructions.

Architecture

A detailed explanation of the project's architecture can be found here.

License

This project is available under the MIT license. See the LICENSE file for more info.

lioness's People

Contributors

louisdh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lioness's Issues

Powers order bug

Currently, 3^3^3 evaluates to 19.683.
This is achieved because the powers are executed from left to right:
3^3^3 => (3^3)^3 => 27^3 => 19.683

The correct behavior is to execute powers from right to left:
3^3^3 => 3^(3^3) => 3^27 => 7.625.597.484.987

Swift Package Manager: use std lib

The Swift Package Manager currently does not allow the inclusion of non .swift files, this means the Lioness Standard Library is currently unavailable from a Swift Package Manager installation.

SR-2866 should fix this.

Advantages over EquationKit???

Hi! Just took a quick glance at this project. I am the author of EquationKit, a project that enables you to write multivariate polynomials in Pure swift. It supports partial derivates and evaluation of polynomials given constants with really Swifty syntax.

I was wondering which advantages lioness has? You have gone to the ambitions length of writing an AST interpreter, which is really cool! So maybe you can express stuff that I cannot in EquationKit?

My project is protocol driven and fully generic, it supports Double or attaswift/BigInt or any Numeric conforming to my rather simple protocol NumberExpressible.

It would be cool to hear from you what your AST interpreter enables that my project lacks support for :)

Edit: Saw now that you also have Cub, so feel free to answer from the perspective of Cub :)

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.