GithubHelp home page GithubHelp logo

jbunke / barebones-compiler Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 38 KB

The Barebones Compiler is a high-level language to Java transpiler that I wrote in the summer of 2018 as a proof of concept. Barebones is a rudimentary language with a C-based syntax.

BlitzBasic 11.97% BitBake 10.52% Java 77.51%

barebones-compiler's Introduction

Barebones Compiler

The Barebones Compiler is a high-level language to Java transpiler that I wrote in the summer of 2018 as a proof of concept. Barebones is a rudimentary language with a C-based syntax.

Barebones Syntax Overview:

Classes are defined with the class keyword followed by the class name. For example:

class class_name {
  // empty class
}

Global variables (fields) are declared with the field keyword, followed by type, followed by the field name. Fields can be initialised or simply declared. For example:

class field_example {
  field int foo;
  field int fee = 2;
  field bool faa = true;
  field bool fii;
  field bool fuu = (1 > 0);
}

Functions are declared with the function keyword, followed by the return type, followed by the function name, followed by a bracket-enclosed and comma-separated argument list of types and names. For example:

class function_example {
  function int a() {
    return 1;
  }
  
  function void b(int arg1, int arg2) {
    print(arg1 ++ arg2);
  }
}

Local variables are declared with var keyword as opposed to fields with the field keyword.

Control flow

If statement:

if (a > b) {
  if (a > c) {
    return a;
  }
} else if (b > c) {
  return b;
}
return c;

While-loop statement:

while (increment < limit) {
  increment = increment + 1;
} loop;

Operators

> + (Addition)
> - (Subtraction)
> * (Multiplication)
> / (Division)
> % (Modulo)
> ^ (Exponentiation)
> >= (Greather than or equal to)
> <= (Less than or equal to)
> > (Greater than)
> < (Less than)
> == (Equal to)
> != (Not equal to)
> || (Or)
> && (And)
> ! (Not; UNARY)
> ++ (Concatenation)
> # (Length; UNARY)
> @ (Element at index)

Examples:

> #"start" -> 5
> "start"@2 -> "a"
> "start"++"this"++"off"++"right" -> "startthisoffright"
> 5 / 2 -> 2
> #"testing" - 3 -> 4

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.