Giter VIP home page Giter VIP logo

protoslang's Introduction

Protoslang

Protoslang is still in active development. The README will temporarily hold the feature set completion status.

Quick Start

Clone the repository

git clone https://github.com/jlhs1001/protoslang.git

Build the project

cd protoslang
cmake .
cmake --build .

Run the REPL

./slang_prototype

Input a file

./slang_prototype <path-to-file>

Protoslanguage

Protoslanguage is a dynamically typed, interpreted programming language. It is designed to be simple and powerful. This iteration is more so a syntactic proof of concept. Future versions will likely be more feature rich, statically typed, and compiled.

Quick Start

Clone the repository

cd protoslang
cmake .
cmake --build .

Input a file

./slang_prototype <path-to-file>

Hello World

As it is the traditional introduction to any programming language, let's start with a simple "Hello, World!" program.

// The 'println' function is used to print to the console.
println("hello world");

Variables and Data Types

Protoslanguage is dynamically typed. Variables are declared with the let keyword. The type of the variable is inferred from the value assigned to it. Variables can be reassigned to values of different types.

// Variables are declared with the 'let' keyword.
let x = 5;
let y = x;

// Variables can be reassigned.
x = 10;

println(x + y);

Operators and Expressions in Action

// This is a bit of an interesting expression.
// It combines all the supported operators.
let x = 30;
let y = x + 2 * 3 / (4 - 2);

println(y % 3);

Functions

Functions are declared with the fn keyword. They can take any number of arguments and return a single value.

// Function argument can be of any type.
fn add(x, y) {
    return x + y;
}

Calling the function is as simple as expected.

let result = add(5, 10);
println(result);

Aggregates

Protoslanguage supports lists of values.

List indexing

let list = [1, 2, 3, 4, 5];

// Lists can be indexed.
println(list[0]);

// A list index may be assigned a new value.
list[0] = 10;

println(list[0]);

Lists may contain any type of value.

let list = [1, "two", 3.0, true];

// Lists can conveniently be printed.
println(list);

Control Flow

Protoslanguage supports if-else statements, range-based for loops, iterative loops, and while loops.

If-else statement

let x = 5;

// A neat little syntax. Quite rust-like.
if x > 10 {
    println("x is greater than 10");
} else {
    println("x is less than 10");
}

Range-based for loop

The range-based for loop is a simple way to iterate over a range of values. A range in slang is a built-in type that represents a range of values. It simply contains a lower and upper bound.

// A range-based for loop.
for i in 0..10 {
    println(i);
}

Iterative loop

The iterative loop is a simple way to iterate over a list of values. It is similar to the range-based for loop, but it grants the loop body access to the current value in the list. Quite convenient.

// An iterative loop.
let grocery_list = [
    "apples",
    "bananas",
    "oranges",
    "grapes",
    "pears",
];

for let item in list {
    println(item);
}

While loop

The while loop is a simple way to iterate over a block of code until a condition is met.

let x = 0;

while x < 10 {
    println(x);
    x = x + 1;
}

That's slanguage for now. More language constructs and features will surely be added soon.

Support Status

Expressions

  • Arithmetic
    • +
    • -
    • *
    • /
    • %
  • Comparison
    • <
    • >
    • <=
    • >=
    • ==
    • !=
  • Logical
    • &&
    • ||
    • !
  • Assignment
    • =

Literal Values

  • Integers
  • Floats
  • Strings
  • Booleans

Variables

  • Declaration
  • Assignment

Functions

  • Declaration
  • Arguments
  • Return
  • Call

Control Flow

  • If-else
  • For-in (iterable)
  • For-range

protoslang's People

Contributors

jlhs1001 avatar

Watchers

 avatar

protoslang's Issues

Story: Configure LLVM Environment

Objective: Establish the foundational LLVM support required to facilitate the conversion of slang code to LLVM IR.

  • Tasks
    • Install LLVM libraries and ensure they are accessible for development.
    • Create a basic framework for converting slang code snippets into LLVM IR, as well as LLVM context initialization.

Story: Arithmetic Expression Conversion

Objective: Convert arithmetic expressions in slang to corresponding LLVM IR code, ensuring accurate translation.

  • Tasks:
    • Implement LLVM IR generation for the following operators: (+, -, *, /, %).
    • Develop corresponding unit tests to verify the correctness of LLVM IR generated for each of these operators.

Story: Control Flow Constructs Conversion

Objective: Translate the following slang control flow constructs to LLVM IR: (if-else, for-in, for-range), ensuring the maintenance of efficient and logical flow.

  • Tasks:
    • Implement the conversion of if-else statements into corresponding LLVM conditional branching instructions.
    • Translate for-in and for-range loops into LLVM loop constructs, ensuring accurate iteration over collections and ranges.
    • Create tests to comprehensively validate the generate LLVM IR for these constructs in different scenarios.

Story: Variables and Types Conversion

Objective: Support variable declarations, assignments, and type inference with appropriate IR.

  • Tasks:
    • Implement IR generation for variable declarations and assignments.
    • Create type conversion utilities to map slang types (int, float, string, bool) to LLVM types.
    • Create tests to verify the correctness and performance of variable operations and type handling.

Story: Function Handling

Objective: Enable the definition, invocation, and management of functions in slang. Ensure accurate and consistent representation in LLVM IR.

  • Tasks:
    • Devise mechanisms for the efficient translation of slang function declarations and their associated arguments and return statements into LLVM function constructs.
    • Implement function invocation support, including argument passing and return values.
    • Ensure appropriate scoping rules are applied, and proper linkage of functions within the generated LLVM IR code.
    • Create unit tests to verify scoping rules, linkage, function invocation, and function return values.

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.