Skip to content
Tom Barham edited this page Sep 14, 2015 · 2 revisions

MCA is a macro language. This means that instead of writing code that will run at runtime, MCA code will run at compiletime, and be used to generate the runtime code. MCA also provides a standard library, which includes functions for string operations, mathematical operations, error handling, and some advanced code generation.

The syntax is primarily C-based, however it also borrows from Assembly, and of course the Minecraft command syntax.

The majority of operations in MCA are completed with macros. Macros are pieces of code that can be repeated in other locations, and are the first things to be 'expanded' during the parsing process.

Here is an example of a simple macro:

SAY_HELLO /say hello;

SAY_HELLO;
SAY_HELLO;
SAY_HELLO;

// becomes:
/say hello;
/say hello;
/say hello;

Macros can also have arguments, allowing you to pass variables into the macro:

GET_ONE_MORE(number) number + 1;

accumulator = 0;
/say {accumulator};
accumulator = GET_ONE_MORE(accumulator);
/say {accumulator};
accumulator = GET_ONE_MORE(accumulator);
/say {accumulator};
accumulator = GET_ONE_MORE(accumulator);
/say {accumulator};

// becomes:
/say 0;
/say 1;
/say 2;
/say 3;

MCA also supports blocks, allowing us to create more powerful macros with contained scopes and return values:

SAY_AND_ADD(number) {
    /say The number is {number};
    return number + 1;
}

n = 0;
n = SAY_AND_ADD(n);
n = SAY_AND_ADD(n);
n = SAY_AND_ADD(n);

// becomes:
/say The number is 0;
/say The number is 1;
/say The number is 2;
Clone this wiki locally