Nik300 / InterpretLayer

Interpretation layer for CosmosOS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nik300.InterpretLayer

Introduction

This layer aims at making it easier for developers to create their own programming language.
This is basically the interpreter of an abstract language, designed to be flexible and adaptable to any kind of parser.

Roadmap

InterpretLayer roadmap:
 • preliminary works (values, variables, functions, ...) ✅
 • Types declaration (class, struct, ...) ✅
 • BASIC support ⌚
 • BASIC playground
 • Statements and cycles
  • for cycle
  • while/do-while cycles
  • if/else if/else statements
 • Conditions
  • Equals (==)
  • Differs (!=)
 • Operators
  • basic
   • Add (+)
   • Subtract (-)
   • Divide (/)
   • Multiply (*)
   • Modulo (%)
  • bitwise
   • And (&)
   • Or (|)
   • Xor (^)
   • Not (~)
   • Lshift (<<)
   • Rshift (>>)
 • System library
  • basic IO functions
  • primitive types
   • string
   • anything
   • method
   • typeInfo
   • integer ✅
   • boolean
   • float
   • array
   • dictionary
   • list
  • interop between Cosmos and the document engine
 • JSON support
 • basic TypeScript support
 • Official release on nuget
 • HTML support

How to use

The interpreter is at a very early stage, but it already supports some basic statements, and even has two print functions (ioprintln and ioprint).
The function names are enclosed into brackets to clearly specify that those are internal functions and those names should be replaced with whatever the language is supposed to have.
Let's, for instance, have a very common test script executing:

using Nik300.InterpretLayer.Types;
using Nik300.InterpretLayer.Types.Builders;
using Nik300.InterpretLayer.Types.Runtime;
using Nik300.InterpretLayer.Types.Statements.General;
using Nik300.InterpretLayer.Runtime.Types;

// your class definition here

// let's define the document here
var doc = Document.Builder
                .UseName("helloWorld") // this will be used by other documents to reference to exported types
                .UseStatement(  // UseStatement simply adds a new statement to the current document
                    new FunctionCall( // This statement is pretty self explainatory, it's used to call a function
                        "sys",  // this is the library, or context, where to look for the function
                        "ioprintln",  // and this is the actual function name
                        args: new Element[] // list of arguments
                        {
                            Element.Builder
                                .UseType(Primitives.String.Instance) // type of the element
                                .UseObject("Hello World!") // element's object
                                .Build()
                        }
                    )
                )
                .Build(); // here we build our defined document into an actual document

var context = doc.GetRoot(); // this is needed to have the document's root to execute
while ((context = doc.RunNext(context)) != null) ; // and here we execute the document until no other statement is left

// output:
// Hello World!

A pseudo-code representation of this script would be something like this:

sys.println("Hello World!");

As you can see I've payed particular attention to details and tried to make this library as easy to use as possible.
This is chiefly because this library is for those of you who want to create languages compatible with cosmos os, and thus need some help with the runtime.
If you're curious and wanna look for other statements, please have a look at Development/Tests.

Contribution

Any form of help is welcome, just pull request with details and i'll be more than happy to review the request and merge it as soon as possible!

Please contact me if you're intrested in becoming a contributor to the project, I might need some help ;)

About

Interpretation layer for CosmosOS

License:GNU General Public License v3.0


Languages

Language:C# 99.5%Language:BrighterScript 0.5%