Giter Site home page Giter Site logo

ryanalameddine / rlcompiler Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 11.25 MB

Tokenizer, Parser, and Compiler for RLang, a strongly typed OO language compiled to CIL created by me. Also includes vscode extension with language support

C# 91.58% Ragel 3.99% TypeScript 3.97% JavaScript 0.46%

rlcompiler's Introduction

RLCompiler

Tokenizer, Parser, and Compiler for rLang (.rl extension), a strongly typed OO language compiled to CIL created by me. This repository also includes a vscode extension and a Language Server (see below)

Rules

  • Case sensitive
  • No multi-line statements
  • Function names, class names, and variable names must be unique
  • Function calls do not require parenthesis (unless the function has no parameters)
  • Main function with [int] parameter is entrypoint

  • Namespace: namespace Identifier
  • Function: def Identifier :: input parameter, input parameter2, etc -> ouput parameter(s)

  • Class: class

  • Arrays: [Type]

  • Ranges: [[0-9]+-\0-9]+]

  • Types: (int|bool|string)

  • Variables: var

  • Loops: (while condition|for variable in array)

  • Conditionals: (if condition|elif condition|else)

  • Char Literals: '\?.'

  • String Literals: ".*?"

  • Int Literals: [0-9]+

  • Identifiers: [a-zA-Z_]\w*

  • List Comprehensions: [{output} for {identifier} in {list} if {condition}]

VSCode

Also contains the rLang language server protocol implemented in C# a vscode extension (found in the /rlang directory) implemented in typescript which adds the following features:

  • Comments
  • Auto-closing pairs: (), [], {}, "", ''
  • Syntax Highlighting
  • Basic Intellisense
  • Snippets for common code blocks
    • e.g. lc -> [{output} for {identifier} in {list} if {condition}]
  • Abstract Syntax Tree Visualizer for parsed rLang in the vscode explorer that updates in realtime
    • includes jumpTo button to navigate through code from the perspective of the syntax tree
  • Diagnostics (error reports) which shows the little red squiggles we all love to see under our code

Example Code

Some example files can be found in this repository (see anything with the .rl extension)

namespace Good.Old.Times

#wow such good code
class TestClass
{
    #function called Func
    #takes two ints as parameters and returns a list of lists of int
    def Func :: a:int, b:int -> [[int]]
    {
        var list:[int]
        [x * 4 + 2 for x in [1..4] if GreaterThanTwo x] -> list
        #this evaluates to [14, 18]
        
        [list, [1, 2, 3 a], [b]] -> var megaList:[[int]]
        
        ret megaList
    }
    
    def GreaterThanTwo :: a:int -> bool
    {
        ret a > 2
    }
}
namespace Test

using System

class Program
{
	var x:int
	var coolObject:Ball
	#NOTE: DELEGATES NOT YET IMPLEMENTED
	delegate MathFunc :: int, int -> int

	def Main :: args:[int] -> void
	{
		Add 1 2 3 -> x
		
		Add x 2 (Add 1 2 3) -> x
		
		Ball "stan but in sphere form" -> coolObject

		coolObject.PrintName (Add (x + 1) 2 3)

		#calling function on base class
		coolObject.Draw ()

		#[x * 2 for x in [1..5] if x / 2 < 5] -> var y:[int]
		[num * 2 for num in [1..5] if num / 2 < x] -> var y:[int] 
		
		coolObject.PrintName -> magicalDelegate
		magicalDelegate () 
	}

	def Add :: a:int, b:int, c:int -> int
	{
		ret a + b + c
	}
}

class Ball : Sprite
{

private:

	var n:string
	var x:int
	
internal:

	def PrintName :: a:int -> void
	{
		Console.Write (n + x:string)
	}

public:

	def magicalFunction :: void#hi there
	{
		var array:[int]
		[1, 3, 4] -> array
		[0..5] -> array

		var i:int 
		
		while i < list.Length
		{
			Console.WriteLine (list.get i)
			i + 1 -> i
		}
	}

	def evenMoreMagicalFunction
	{
		for val:int in [x * 4 + n for x in [1..3] if x > 2]
		{
			Console.WriteLine val
		}
	}

	def Ball :: name:string -> Ball
	{
		name -> n
	}
}

class Sprite
{
public:
	
	def Draw 
	{
		#some cool stuff in here
	}
}

rlcompiler's People

Contributors

ryanalameddine avatar

Stargazers

 avatar

Watchers

James Cloos 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.