This is just a simple markdown definition for the Shake Programming Language Syntax. It is not a full language tutorial and not meant to be a full language reference, but rather for experienced users to get a feel and overview of the language.
Shake is an object-oriented, modern programming language. It is not a scripting language. Shake has a java-like package system and a simple, yet powerful, c-style, syntax.
package com.shakelang.shake
Function declarations are written in a c-style syntax.
void main() {
...
}
Functions can have the following attributes:
public: The function is accessible from outside the package.private: The function is only accessible from inside the fileprotected: The function is accessible from inside the package, inside the file and inside of subclasses.static: Only available for functions in classes, enums and interfaces. Static functions do not need an instance to be called.final: The function can not be overridden.abstract: The function provides no implementation and must be implemented in a subclass.override: The function overrides a function in a superclass.native: The function is implemented in the compiler.synchronized: The function is synchronized.
Functions can also have parameters.
void main(int arg0) {
...
}
There are also default parameters.
void main(int arg0 = 0) {
...
}
Variables are written in a c-style syntax. They are declared with the type of value and the name of the variable. Declarations can also directly get a value assigned.
int a
int b = 0
Fields can have the following attributes:
public: The field is accessible from outside the package.private: The field is only accessible from inside the file.protected: The field is accessible from inside the package, inside the file and inside of subclasses.static: Only available for fields in classes, enums and interfaces. Static fields do not need an instance to be accessed.final: The field can not be overridden.const: The field can not be changed.abstract: The field provides no implementation and must be implemented in a subclass.override: The field overrides a field in a superclass.native: The field is implemented in the compiler.
Classes are created using the class keyword followed by the name of the class.
class MyClass {
...
}
They are able to extend other classes and implement interfaces.
class MyClass3 extends MySuperClass implements MyInterface {
...
}
A constructor is created using the constructor keyword.
class MyClass {
constructor() {
...
}
}
Constructors can have parameters.
class MyClass {
constructor(int arg0) {
...
}
}
Constructors can also have a name.
class MyClass {
constructor MyConstructor(int arg0) {
...
}
}
Classes can have fields and functions.
class MyClass {
int a
int b = 0
void main() {
...
}
}
Interfaces are created using the interface keyword followed by the name of the interface.
interface MyInterface {
...
}
Interfaces can have fields and functions.
interface MyInterface {
int a
int b = 0
void main() {
...
}
}
Interfaces can also have methods and fields. Interface fields must not have values and must not be final. Methods must not be final too.
interface MyInterface {
int a
int b = 0
void main() {
...
}
void main2() {
...
}
}
Enums are created using the enum keyword followed by the name of the enum.
enum MyEnum {
...
}
Enum fields are created at the start of the enum. Then after the last field the regular class declaration starts seperated by a semicolon. (If you do not need it the semicolon is optional.)
enum MyEnum {
A,
B,
C
}
enum MyEnum2 {
A,
B,
C;
void main() {
...
}
}
Enums can't have a superclass. They can only implement interfaces. They can declare constructors, methods and fields.
enum MyEnum {
A("a"),
B("b"),
C("c");
String name;
constructor(String name) {
this.name = name;
}
void main() {
...
}
}
Objects are created using the object keyword followed by the name of the object.
object MyObject {
...
}
They are basically the same as classes, but they are directly created.
Line comments are created using the // symbol.
// This is a comment
Block comments are created using the /* and */ symbols.
/*
This is a comment
*/
for loops are created using the for keyword. They contain three parts:
- declaration of the counter variable
- condition for the loop to run
- increment of the counter variable
for(int i = 0; i < 10; i++) {
...
}
while loops are created using the while keyword. They contain a condition for the loop to run.
while(true) {
...
}
do-while loops are created using the do keyword. They contain a condition for the loop to run.
do {
...
} while(true)
if statements are created using the if keyword. They contain a condition for the statement to run.
if(true) {
...
}
They can also contain an else statement.
if(true) {
...
} else {
...
}
Local variables are declared with the type of value and the name of the variable. They are only available inside the block they are declared in.
{
int a
}
Local variables can also have a value assigned.
{
int a = 0
}
Assignments are created using the = symbol.
a = 0
There are also +=, -=, *=, /=, %= and **= assignments.
+ is used to add two values.
a + b
- is used to subtract two values.
a - b
* is used to multiply two values.
a * b
/ is used to divide two values.
a / b
% is used to get the remainder of two values.
a % b
** is used to get the power of two values.
a ** b
== is used to compare two values.
a == b
!= is used to compare two values.
a != b
> is used to compare two values.
a > b
< is used to compare two values.
a < b
>= is used to compare two values.
a >= b
<= is used to compare two values.
a <= b
&& is used to combine two values.
a && b
|| is used to combine two values.
a || b
! is used to invert a value.
!a
^ is used to combine two values.
a ^ b
& is used to combine two values.
a & b
| is used to combine two values.
a | b
^ is used to combine two values.
a ^ b
+ is used to get the value of a value.
+a
- is used to get the value of a value.
-a
( and ) are used to group expressions.
(a + b)
() is used to call a function.
a()