/creamscript

A CoffeeScript-like language that compiles to C++

Primary LanguageC++

CreamScript

A CoffeeScript-like language that compiles to C++.

Examples

Hello World

CreamScript

import stdio

using namespace std

int main() ->
  cout << "Hello world!" << endl
  return 1

Compiled C++

#include <stdio>

using namespace std;

int main()
{
  cout << "Hello world!" << endl;
  return 1;
}

Fibonacci

CreamScript

int fibonacci(int n) ->
  if n > 1
    return fibonacci(n - 1) + fibonacci(n - 2)
  else
    return n

int main() ->
  cout << "Fibonacci(10): " << fibonacci(10) << endl

Compiled C++

int fibonacci(int n) {
  if (n > 1)
    return fibonacci(n - 1) + fibonacci(n - 2);
  else
    return n;
}

int main()
{
  cout << "Fibonacci(10): " << fibonacci(10) << endl;
}

Lambdas

CreamScript

sum = (double a, double b) ->
  return a + b

sum(41, 1)

Compiled C++

auto sum = [] (double a, double b)
{
  return a + b;
}

sum(41, 1);

Features

Language

  • ✓ Identifiers
  • ✓ Variables
    • ✗ Definition
    • ✗ Assignment
  • ✗ Keywords
  • ✗ Types
  • ✓ Literals
    • ✓ Numbers
    • ✓ Strings
  • ✓ Blocks
    • ✓ Single line
    • ✗ Multi-line
  • ✓ Statements
    • ✗ If Else
    • ✗ For
    • ✗ While
    • ✓ Return
  • ✓ Expressions
    • ✓ Expression Groups
  • ✓ Operations
    • ✓ Arithmetic
      • ✓ Add, Subtract, Multiply, Divide
  • ✗ Functions
    • ✓ Definition
    • ✓ Lambdas
    • ✓ Parameter Lists
    • ✗ Calls

Compiler

  • ✓ Token
  • ✓ Scanner
  • ✓ Rewriter
  • ✓ Lexer
  • ✓ Parser
  • ✓ Back end
    • ✓ C++ Output