Skip to content

🦑 A Designer Programming Language originally created for a class, but pushed beyond the requirements. Version 2 is in the works.

License

Notifications You must be signed in to change notification settings

at-ninja/Leviathan

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Andrew Thomas
Designer Programming Language

(This readme was designed to have text-wrap turned on)

To run the test problem simulation, simply run the command "make run-problem"
To change the test problem inputs, open the file "TestProblem.lv", 
 which is found in the leviathanCode/source directory
The signals are set for the test problem on lines 23, 24, and 25. 
By changing the values set there, you can change the inputs to the test problem

 ___      _______  __   __  ___   _______  _______  __   __  _______  __    _ 
|   |    |       ||  | |  ||   | |   _   ||       ||  | |  ||   _   ||  |  | |
|   |    |    ___||  |_|  ||   | |  |_|  ||_     _||  |_|  ||  |_|  ||   |_| |
|   |    |   |___ |       ||   | |       |  |   |  |       ||       ||       |
|   |___ |    ___||       ||   | |       |  |   |  |       ||       ||  _    |
|       ||   |___  |     | |   | |   _   |  |   |  |   _   ||   _   || | |   |
|_______||_______|  |___|  |___| |__| |__|  |___|  |__| |__||__| |__||_|  |__|

Introduction

    Leviathan has been designed for quick prototyping of ideas, and has been built from the ground up to allow the user to code quickly and efficiently. Leviathan incorporates my favorite features of popular dynamically typed languages, such as Python and JavaScript, to help make Leviathan as robust as it can be. Some features of Leviathan include objects, Python-like for loops, dynamic typing, two sets of keywords for quick typing ease, and inline include statements that import files relative to the file being run.
    
Installing and Running Leviathan

    To install leviathan, simply call "make build" while in this directory. To run programs, use the command "leviathan <filename>", where <filename> is a leviathan source code file.
    
Programming in Leviathan

    Leviathan has many ways to create working code, so in this section, only a few would be shown.  By far the most important keyword in Leviathan is "var" or "V".  Both of these keywords allow for variables to be defined, which in turn allows for classes, values, and functions to be assigned to variables.  To show how simple it is to create a Hello World program in leviathan, here is a valid program in leviathan:

var hello = function() "Hello, World!" println(hello())

    To create functions in Leviathan, one simply uses the "function" or "F" keyword.  All functions are lambda functions, but they may be assigned to variables.  To specify a function's parameters, simply add the parameters in the parenthesis following the function keyword in a comma deliminated list.  After the parameters, simply add the function body, which can be either a single statement or a block of code.  The same rules apply for classes in Leviathan, and the keywords for class are "class" and "C".
    
V exampleClass = C(param) V classProperty = param
V exampleFunction = F(param1, param2) 
    { 
        PL("Param1 is ", param1) 
        exampleClass(param2)
    }
    
    Some of the more advanced features of Leviathan include the "include", or "U" (for 'use') keywords, along with features such as arrays and calling functions without assigning them to variables.  The include capabilities of Leviathan allow the user to break up sections of code across multiple files, and then include other modules of code while programming.  An example is shown below:
    
File 1 ("hello.lv"):
    V hello = "Hello"
    
File 2 ("include.lv"):
    
    U "hello.lv"
    PL(hello)
    
    The program include.lv will execute all of the code in hello.lv, allowing the variable 'hello' to be defined when the evaluator reaches it.  Arrays in Leviathan are very straight forward as well, and can be defined as shown below:
    
    V array = [1,2,3]
    V array2 = [[], ["Hello"], 45, 123.32, println, none]
    
    As you can see, arrays can include a multitude of values, including integers, reals, booleans, strings, functions, classes, objects, null values (keywords "none" or "N"), or even more arrays.  They can be empty or contain as many values as you would like them to.  They can be indexed as follows:
    
    V item = array[2]
    V item2 = ([1, 3, 4])[1]
    
    You will notice in the second example that the array is able to accessed without being assigned to a variable.  This functionality can extend out to lambda functions and lambda classes as shown:
    
    V result = (F() {I true "Lambdas are great"})()
    V obj = (C() {V method = F() "Lambdas are still great"})()
    V result2 = (obj.method)()
    
    As a matter of fact, any expression that results in a function closure can be called like shown, as long as it is parenthesized correctly.
    The last basic material to cover are code flow tools.  Leviathan includes an if block structure, an if-else block structure, a for-loop structure, and a while-loop structure.  For the if block, the if-else block, and the while block, the condition provided must evaluate to a boolean.  In the for loop, it must be supplied with an identifier and an array to iterate over.  Examples of all of this are shown below:
    
    I (1 < 2)
        "Execute this statement"
    
    if (true == false)
    {
        # code block
    }
    else
    {
        # code block
    }
    
    V a = 3
    while (a > 0)
        a = a - 1
    
    L x in [1,2,3] # L stands for loop. it is the shorthand for 'for'
        println(x)
        
    Using these basic structures in combination with all that Leviathan offers makes Leviathan a very flexible language that can be used efficiently and quickly to prototype out code.
    Other things to note about Leviathan:  The basic types of Leviathan are Boolean, Integer, Real, and String.  Line numbers are captured so that they can be used to pinpoint runtime errors.  No main function is required for Leviathan code, as it executes very similar to how Python executes -- simply from the top of the program to the bottom.  The include keyword loads files relative from the location of the file the include was called from. After a "#" symbol, the rest of the line is considered a comment.  Anything between the symbols "#<" and "#>" are considered a block comment.

About

🦑 A Designer Programming Language originally created for a class, but pushed beyond the requirements. Version 2 is in the works.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published