Keywords - KidneyThief/TinScript1.0 GitHub Wiki

The syntax of TinScript closely resembles C++ in it usage of types, function definitions, namespaces, flow control, and other elements.

Comments

Starting with one of the basics, TinScript supports both single line and block comments:

  • Two forward slashes '//' will allow the parser to ignore all remaining text until a new line character is reached.
    • e.g. float x = 5; // the value of x will be 5
  • All text between the start of a block comment /* and the block end */ is ignored.
    • e.g.
      /*
      This entire block of text on multiple lines
      is ignored by the parser.
      */

Flow Control

Statement type Format Example Comments
'if .. else' if (<condition>)
    <consequent statement>
else
    <alternative statement>
// Determine if x is negative
if (x < 0)
    Print("x is negative");
else
    Print("x is zero or positive");
  • You can specify a statement block for
    either the consequent or alternative,
    using { ... }
  • You can also chain a sequence of
    'if' statements using 'else if'
  • TinScript always evaluates the entire
    conditional, and does not "early out".
'while' loop while (<condition>)
    <statement block>
// Print 1 to 10
int counter = 1;
while (counter <= 10)
{
    Print(counter);
    counter = counter + 1;
}
  • As with 'if' statements, you can
    use { ... } to execute a statement block
  • As with 'if' statements, the entire
    conditional is evaluated.
  • 'do .. while' loops are not yet supported
'for' loop Contains three elements:
  • <init>: a statement to
    execute once at the start
  • <cont>: a conditional that
    must be true to execute the body
  • <iter>: a statement executed
    each time the body is executed
for (<init>; <cont>; <iter>)
    <statement block>
// Print 1 to 10
int i;
for (i= 1; i<= 10; i += 1)
    Print(i);
  • As with 'if' statements, you can
    use { ... } to execute a statement block
  • As with 'if' statements, the entire
    conditional is evaluated.
  • Variable declarations must happen
    before the 'for' loop - local variables
    are not scoped beyond the function body.
break Used to prematurely exit the
body of any of the above statements
// Print 1 to 7
int i;
for (i = 1; i < 100; i += 1)
{
    // should we exit?
    if (i == 7)
            break;
    Print(i);
}
continue Used to prematurely exit the
current iteration but does not
exit the loop.
// Print even numbers to 10
int i;
for (i = 1; i <= 10; i += 1)
{
    // skip odd numbers
    if ((i % 2) == 1)
            continue;
    Print(i);
}
⚠️ **GitHub.com Fallback** ⚠️