YAP Language

Yet Another Programming Language

A modern, intuitive language designed for simplicity and Readability

Get Started

Key Features

  • Simple Syntax: YAP's syntax is designed to be readable and intuitive.
  • Boolean Values: Uses nocap (true) and cap (false) for boolean values.
  • Function Returns: Uses the keyword yeet for returning values from functions.
  • Built-in Data Structures: Support for arrays, stacks, and queues.
  • I/O Operations: yap() for output and spill() for input.

Getting Started

Ready to start coding in YAP? Check out our comprehensive documentation to learn the basics:

How to Write Code in YAP?

Welcome to the YAP programming language documentation. YAP is designed to be intuitive yet powerful, with a syntax that's both expressive and easy to learn.

1Variables and Data Types

The datatype of the variable must be defined by the user at the time of declaration. You can declare variables using the following types:

  • int - Whole numbers
  • float - Decimal numbers
  • bool - nocap (true) or cap (false)
  • string - Text
  • int[], float[], bool[], string[] - Arrays
  • fn - Functions

Declaring Variables:

int age = 25;
float pi = 3.14;
bool isStudent = nocap;
string name = "Alice";

2Printing Output

Use yap() to display values.

Example: Printing

yap("Hello, world!");
int x = 10;
yap(x);
Hello, world! 10

3Taking User Input

Use spill() to get values from the user.

Example: Input

int age = spill();
yap("Your age is: ", age);

If you enter 20, output will be:

Your age is: 20

4Operations

4.1 Arithmetic Operations

Operator Name Example Output
+ Addition 5+3 8
- Subtraction 5-3 2
* Multiplication 5*3 15
/ Division 6/3 2.0
^ Exponentiation 5^3 125
~ Unary Negation ~2 -2
% Modulo 10%3 1

4.2 Comparison Operations

Operator Name Example Output
< Less than 5<3 cap
> Greater than 5>3 nocap
<= Less than or equal to 5<=3 cap
>= Greater than or equal to 5>=3 nocap
== Equal to 5==3 cap
!= Not equal to 5!=3 nocap

4.3 Logical Operations

Operator Name Example Output
and AND nocap and cap cap
or OR nocap or cap nocap
not NOT not cap nocap

4.4 Bitwise Operations

Operator Name Example Binary Calculation Output
& AND 5&3 101 & 011 = 001 1
| OR 5|3 101 | 011 = 111 7
~~ NOT ~~3 ~011 = 100 -4

5Conditional Statements

Use if, elif, and else for decision-making.

Example: If-Else

int num = spill();
if (num > 0) {
    yap("Positive number");
} elif (num < 0) {
    yap("Negative number");
} else {
    yap("Zero");
}

Input: 5

Positive number

Example: Nested If-Else

int x = 4;
float y = 7.0;
bool z = nocap;
string msg = "hello";
if (x > 0) {
    if ((y > 2.0) and (z == nocap)) {
        yap("Complex nested condition 1");
        if (msg == "Hello") {
            yap("Deepest nesting");
        } else {
            yap("Deep nest else");
        }
    } else {
        yap("Complex nested condition 2");
    }
} else {
    yap("Outer else");
}
Complex nested condition 1 Deep nest else

6Loops

YAP supports several types of loops for repeating code execution.

6.1 while loop

int count = 0;
while (count < 5) {
    yap(count);
    count = count + 1;
}
0 1 2 3 4

6.2 for loop

for (int i = 0; i < 5; i = i + 1) {
    yap(i);
}
0 1 2 3 4

6.3 break and continue

Loop control statements can modify the normal execution flow:

  • break: Exits the loop immediately.
  • continue: Skips the current iteration and moves to the next one.

Using break to exit a loop early:

for (int i = 0; i < 5; i = i + 1) {
    yap(i);
    if (i==2){
        break;
    }
}
0 1 2

Using continue to skip an iteration:

for (int i = 0; i < 5; i = i + 1) {
    if (i==2){
        continue;
    }
    yap(i);
}
0 1 3 4

7Arrays

Arrays can be defined for any of these types: int[], float[], bool[], string[]. Arrays having elements of different datatypes are not supported.

int[] numbers = [1, 2, 3, 4];
string[] words = ["hello", "world"];

Access array elements:

yap(numbers[2]);
3

Modify array elements:

numbers[1] = 10;
yap(numbers[1]);
10

Appending Elements

numbers.append(5);
yap(numbers);
[1, 10, 3, 4, 5]

Deleting Elements

Delete takes the index of the element which is to be deleted:

numbers.delete(1);
yap(numbers);
[1, 3, 4, 5]

Finding length

yap(numbers.len());
4

8Functions

A function is defined using def, and parameters are statically typed. The data type for return value is to be specified at the time of function definition, else the function is set to void by default. The keyword 'yeet' is used for returning functions. Functions can only return one value currently.

Note: There are no ';' at the end of 'yeet' statements.

Note: Functions cannot be parsed as parameters to other functions; However, function calls can be parsed.

Function with Parameters

def add(int a, int b) -> int {
    yeet a + b
}
yap(add(5, 3));
8

Function without Return Value

def greet(string name) {
    yap("Hello, ", name);
}
greet("Alice");
Hello, Alice

Function with an Array as Input and Output

def double_elements(int[] arr) -> int[] {
    for (int i = 0; i < 4; i = i + 1) {
        arr[i] = arr[i] * 2;
    }
    yeet arr
}
int[] numbers = [1, 2, 3, 4];
int[] result = double_elements(numbers);
yap("Doubled Array:", result);
Doubled Array:[2, 4, 6, 8]

Recursive Function

def fib(int n) -> int{
    if((n==1) or (n==0) ){
        yeet n
    }
    int x = fib(n-1) + fib(n-2);
    yeet x
}
yap(fib(8));
21

Functions Calls

def add(int a, int b) -> int {
    yeet a + b
}
def multiply(int x, int y) -> int {
    yeet x * y
}
yap(multiply(add(2, 3), 4));
20

Functions as First-Class Values

def double(int x) -> int {
    yeet x * 2
}

fn f = double;
yap(f(5));
10
def return_fn() -> fn {
    def say_hello() -> int {
        yap("hi");
        yeet 0
    }

    yeet say_hello
}

fn greeter = return_fn();
greeter();
hi

Function and Scoping

def changeVar(int x) -> int {
    x = x + 10;
    yeet x
}
int x = 5;
yap(changeVar(x));  # Expected: 15
yap(x);
15 5

Explanation: Scoping in YAP

In YAP, function parameters are passed by value. This means that when you call changeVar(x), the function gets a copy of x, not the original variable. Inside the function, the modification x = x + 10; affects only the copy, not the original x. After the function returns, x remains unchanged outside the function.

To modify a variable globally, you would need to return the new value and explicitly reassign it:

int x = 5;
x = changeVar(x);
yap(x);
15

9Stacks and Queues

Stacks and queues can be declared using stack<type> and queue<type>, where type is the datatype.

9.1 Stacks

A stack follows the Last In, First Out (LIFO) principle.

Declaring a Stack:

stack<int> s;

Stack operations:

s.stackPush(3) - pushes 3 into stack
s.stackPop()-pops the top element
s.top() - return the top element

9.2 Queues

A queue follows the First In, First Out (FIFO) principle.

Declaring a Queue:

queue<int> q;

Queue operations:

q.queuePush(3) - pushes 3 into queue
q.queuePop()-pops the first element
q.first() - return the first element

About YAP Language

YAP is a modern programming language designed for simplicity, readability, and power. Created as an educational project, YAP combines the best features of multiple programming languages to create an experience that's both enjoyable and productive.

Our Mission

Our mission is to create a programming language that's accessible to beginners while still being powerful enough for more complex applications. We believe that learning to code should be fun and intuitive, and YAP was designed with this philosophy in mind.

Connect With Us

GitHub Repository

Check out our open source code and contribute to the project: