bhai-lang icon indicating copy to clipboard operation
bhai-lang copied to clipboard

Adding support for arrays

Open aditya87 opened this issue 3 years ago • 2 comments

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.

  • Declaring arrays
  • Assigning array values at index
  • Access array values at index, and using them in expressions.

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
  1. 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]
  1. 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

  • [ ] Bugfix (non-breaking change which fixes an issue)

  • [X] New feature (non-breaking change which adds functionality)

  • [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)

Package version increase in cli package?

No

Checklist before merging

Put an x in the boxes that apply

  • [X] These changes have been thoroughly tested.

  • [ ] Changes need to be immediately published on npm.

aditya87 avatar Jan 29 '23 23:01 aditya87

Deploy Preview for bhailang-preview failed.

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

netlify[bot] avatar Jan 29 '23 23:01 netlify[bot]