DulLabs / bhai-lang

A toy programming language written in Typescript
https://bhailang.js.org/
MIT License
3.97k stars 501 forks source link

Adding support for arrays #275

Open aditya87 opened 1 year ago

aditya87 commented 1 year ago

What does this PR do?

Adds support for arrays and. basic array operations.

What packages have been affected by this PR?

parser, interpreter

Types of changes

Adds the following features.

Some examples:

  1. basic arrays

      hi bhai
        bhai ye hai b = 2;
        bhai ye hai a = [1, b + 2, 3];
        bol bhai a;
        bol bhai a[0];
        bol bhai a[1];
        bol bhai a[2];
        bol bhai a[3];
      bye bhai

    output:

    [1, 4, 3]
    1
    4
    3
  2. array access and length loop (new bhai-lang keyword ka lambai)

      hi bhai
        bhai ye hai a = [-1, 0, 3, 5];
        a[3] = -5;
    
        bol bhai a;
        bol bhai a[1];
    
        bhai ye hai i = 0;
        jab tak bhai (i < a ka lambai) {
          a[i] += 2;
          i += 1;
        }
        bol bhai a;
      bye bhai

    output:

    [-1, 0, 3, 5]
    0
    [1, 2, 5, -3]
  3. inner arrays

    hi bhai
        bhai ye hai a = [-1, 0, 3, [1, 2]];
        bhai ye hai k = a[3];
        k[0] = -5;
        bol bhai a;
      bye bhai

    output:

    [-1, 0, 3, [-5, 2]]

What types of changes does your code introduce to this project?

Put an x in the boxes that apply

Package version increase in cli package?

No

Checklist before merging

Put an x in the boxes that apply

netlify[bot] commented 1 year ago

Deploy Preview for bhailang-preview failed.

Name Link
Latest commit 0270adbc7c543c3c2cad600d285c154160f68f0a
Latest deploy log https://app.netlify.com/sites/bhailang-preview/deploys/63d7047d48486c000a3fd9bc