Skip to content

notfatdan/Nya-Script

Repository files navigation

Picutre of catgirl

NyaScript - A Bytecode Interpreter for a Toy Programming Language

this project implements a custom programming language with a bytecode interpreter written in C++. The language has quirky syntax inspired by the meme that software engineers perform their best while wearing programming socks and cute kitty ears.

Features

Variable Declaration

Variables are declared using the nya keyword, followed by the variable name and an optional assignment.

nya x = 10;
nya y = "herrow senpai (˶˃⤙˂˶) ";

Printing

Printing is done using the senpaii keyword, without brackets and closed with a semi-colon. e.g.

nya a = 5;
senpaii a; //Prints 5

Functions (Currently not working)

uwu someFunction(param1, param2) {
  senpaii "hello";
}

Lists

Lists are created using square brackets (like in python)

nya someList = ["a", "b", "c"];

Lists in NyaScript are also dynamic. e.g.

nya someList = ["a", "b", "c"];

someList[3] = "d";

senpaii someList;

// prints [a, b, c, d]

Control Flow

C Style For Loops:

for (nya i = 0; i < 10; i = i + 1) {
  senpaii i;
}
// prints 0-9

While loops:

while (x > 0) {
  x = x - 1;
}

If/Else Statements: if and else statements are just like normal except the keyword for else is ewse

if (x == 10) {
  senpaii "x is 10";
} ewse {
  senpaii "x is not 10";
}

Switch Statements (currently falling through): Switch statements are C like, except the keyword for default is defauwt

switch (x) {
  case 1:
    senpaii "x is 1";
  case 2:
    senpaii "x is 2";
  defauwt:
    senpaii "x is neither 1 nor 2";
}

Logical AND and OR operators

if (x < y and y == 10) {
  senpaii "x is less than y and y equals 10";
} ewse {
  senpaii "Something is wrong";
}

if (x > y or y == 10) {
  senpaii "Either x is greater than y or y equals 10";
} ewse {
  senpaii "Neither condition is true";
}

The keyword for nil is zilch

if (a < b and a != zilch) {
  senpaii "a is less than b and is not zilch";
} ewse if (a == zilch or b == zilch) {
  senpaii "One of a or b is zilch";
} ewse {
  senpaii "Both are valid non-zilch values";
}

TODO

  • Fix functions, currently having object pointers lose their values when pushing or popping off the stack.
  • Fix switch statements falling through, maybe by implementing breaks.
  • Implement classes
  • Implement more data structures

Compiling and Usage

g++ *.cpp -o nya_compiler && ./nya_compiler nyaa SomeScript

Alternatively (but not recommended) fire up the REPL

g++ *.cpp -o nya_compiler && ./nya_compiler

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages