Coder Social home page Coder Social logo

gamescript's Introduction

GScript scripting language

'GScript' (gamescript) is an interpreted (for now) statically typed programming language. It was created using the parser generator Antlr. I may potentially use it in future games which is why it's called 'gamescript'. The main purpose of this project is the study of programming language design and development.

Features

  • 4 types: int, float, string, bool
  • functions, both native (defined inside gamescript), and external (callback to host)
  • scoped variables, name overloading and parameter overloading with a global keyword
  • nested functions, function scoping and overloading
  • statically typed variables

Missing Features

  • no array types
  • typed function returns

Code Examples

For a lot of code check testscript.txt, it contains the entire test suite with which the language is validated. Here are some smaller code examples.

Scoping Behavior

void assert(bool obj){
    if(!obj){
        print("error, assertion failed");
    }
}

int test = 0;
void testA(int test){
    assert(test == 1);
    assert(global.test == 0);

    void testB(int test){
        assert(test == 2);
        assert(global.test == 0);
    }
    testB(2);
}
testA(1);

Random function

Dice roll example making use of the external rand() function:

int roll = (rand()*6)|int;

Operator Precedence

Operator precedence and boolean logic work as expected.

[...]
assert(true);
assert(!false);
assert(true | false);
assert(!(true & false));
assert(true | false & false); //fails if 'and/or' precedence faulty

assert(1);
assert(-1+2);
assert(0.001);

Power Function

[...]
float pow(float val, int power){
    float ret = 1;
    int i = 0;
    while(i < power){
        ret = ret * val;
        i = i+1;
    }
    return ret;
}

assert(pow(4,0) - 1 < 0.001);
assert(pow(4,1) - 4 < 0.001);
assert(pow(4,2) - 16 < 0.001);
assert(pow(4,3) - 64 < 0.001);

gamescript's People

Contributors

kraballa avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.