Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save native-m/e1c7b48f72c876c12489a619e0cf9170 to your computer and use it in GitHub Desktop.

Select an option

Save native-m/e1c7b48f72c876c12489a619e0cf9170 to your computer and use it in GitHub Desktop.
Language Design
Declaration
____________
// variable
a: int; // <var-id>: <type-id>;
b: int = 15; // <var-id>: <type-id> = <expr>;
// constant variable (must be initialized first)
let ca: int = 15; // let <var-id>: <type-id> = <expr>;
// Array
arr0: int[4]; // <var-id>: <type-id>[<num-elements>];
arr1: int[4] = [1, 2, 3, 4]; // <var-id>: <type-id>[<num-elements>] = <array-init>;
arr2: int[] = [1, 2, 3, 4] = // <var-id>: <type-id>[] = <array-init>;
// Constant array
let arr1: int[4] = [1, 2, 3, 4]; // let <var-id>: <type-id>[<num-elements>] = <array-init>;
let arr2: int[] = [1, 2, 3, 4] = // let <var-id>: <type-id>[] = <array-init>;
// Function
myFunc0: void()
{
// what else...
}
// Function with params and its return
myFunc1: int(a: int, b: int)
{
return a + b;
}
// function Grammar
<func-id>: <type-id>(<var-decl>,...) <stmts>
// User-defined type (Structure/Record)
myType0: struct
{
a: int;
b: int[4];
c: char;
...
};
// struct Grammar
<type-id>: struct
{
<var-decl>;
...
};
// Class
// TO BE IMPLEMENTED
Control Flow & Loops
____________________
The grammar will be available later
Still not done yet
// IF statement
if (a == b)
{
// ...
}
// IF-ELSE statement
if (a == b)
{
// ...
}
else
{
// ...
}
// IF-ELSE IF statement
if (a == b)
{
// ...
}
else if (a != b)
{
// ...
}
// IF-ELSE IF-ELSE statement
if (a == b)
{
// ...
}
else if (a != b)
{
// ...
}
else
{
// ...
}
// Switch statement
a: int = 2;
caseof (a)
{
when 1 =>
// ...
when 2 =>
// ...
else =>
// ...
}
// Switch statement as an if-else alternative
a: int = 1;
b: int = 2;
caseof (true)
{
when (a > b) =>
// ...
when (a < b) =>
// ...
else =>
// ...
}
// Switch statement that can assign into a variable
c: char = 'a';
a: int;
a = caseof (c) {
when 'a' =>
return 1;
when 'b' =>
return 2;
else =>
return 3;
};
// Infinite loop
loop
{
// ...
}
// While loop
while (/* expression */)
{
// ...
}
// Do-while loop
do
{
// ...
} while (/* expression */);
// C-style For loop
for (/*stmt1*/;/*stmt2*/;/*stmt3*/)
{
// ...
}
// Range based for loop
for (a: int = 0; a upto 100)
{
}
Macro
_____
NOT DONE YET
// defining constant
[$define MYDEF 1]
// defining macro function
[$define MYFUNC(x) x + x]
// If statement for macro
// Must be ended with [$endif]
// standard IF macro
[$if defined(MYDEF) && MYDEF == 1]
// ...
[$endif]
// If defined
[$ifdef MYDEF]
// ...
[$endif]
// If NOT defined
[$ifndef MYDEF]
// ...
[$endif]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment