Skip to content

iambnlvn/sig-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

48 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sig Parser

Description

This is a simple parser for the Sig file format. It is used to parse the Sig files and return an ast of the file.

This uses the Bun runtime

Table of Contents

-Installation
-Usage
-Language Syntax

Installation

//clone the repo
$ git clone https://github.com/iambnlvn/sig-parser.git && cd sig-parser
$ bun install

Usage

Direct usage (without executable)

Create a file with .sigx extension and ensure it follows the Sig Syntax.

Command format:

$ bun ./cli/main.ts [options] <path-to-file | inline-string-input>

Example: with file input:

$ bun ./cli/main.ts -f hello.sigx

Example: with inline string input:

$ bun ./cli/main.ts -i "class User { let name = "Sig"; }"

Options

-f, --file : path to the file to be parsed
-o, --output : output the AST to a file
-i, --inline : inline string input to be parsed
-s, --spacing : spacing to be used for the output
-h, --help : display help for command
-V, --version : output the version number

Note that the cli prioritizes file inputs when both inline string & file are entered

Executables usage

To build an executable(outputFile = sig), run:

$ bun exec

Command format:

$ ./sig [options] <path-to-file | inline-string-input>

Example: with file input:

$ ./sig -f hello.sigx

Example: with inline input:

$ ./sig -i "let a =11;"

Language Syntax

Sig syntax is a similar to javascript syntax. Refer to parser tests for more details.

Comments

Sig supports single line comments and multi line comments.

// hey mom, got borred so i decided to write a parser
/**
 * dang it, this is cool
 */

Variables

Sig supports variable declaration and assignment. only let keyword is supported for variable declaration (cuz why not). Semicolons are required for every expression;

let a,b = 12;
let a = new thing();
let a = 10;
let b = "hello";
let c = true;
let d= false;
let e = 10.5;
let f +=11;
let g -=1;
let h *=90;
let i /=69;
let k=l=89;
let m = 23>a;//boolean
let n = 25<b;//boolean
let q = 77==a;//boolean
let r = 234!=a;//boolean
let s = 2 ||d;
let t = 2 &&d;
let u = nill;// that's how you declare null; kinda way cooler than null
let v,w,x,y,z = 10;//multiple declaration

Functions

fn log(name) {
    return name;
}
log("error");

fn sayHi() {
    return "Hi,mom";
}
sayHi();
fn add(a,b,c) {
    return a+b+c;
}
add(13,12,2);

Classes

class Person {
    //properties are declared as variables
    // methods are declared as functions
}
class User extends Person{
//constructor not supported yet so the parser will treat it as a function
    let a = 10;
    this.saySomethingNice() {
    }
    fn method(){
        return nill;
    }
    super();
}

let user = new User();
user.method();// non computed values
user["method"]();// computed values

Comparisons

x > y;
x < y;
x >= y;
x <= y;
x == y;
x != y;

Loops

for (let i = 0; i < 10; ++i) {
  //do something
}
for (;;) {
  //do something
}
while (x > 1) {
  print(x);
  ++x;
}
do {
  print(x);
  ++x;
} while (x > 1);

Conditionals

if (x > 1) {
  print(x);
} else if (x < 1) {
  print(x * 2);
} else {
  print(x);
}

About

A manual Recursive-descent parser for Sig(Programming language)

Topics

Resources

Stars

Watchers

Forks