This is a simple language that I made for fun and learning.
It's named Ash as A#, A as in my name and # as it's written in C#.
- Any: Any type of value
- Default: 0.
- Integer: number with no decimal.
- Default: 0.
- Double: number with decimal.
- Default: 0.0.
- Boolean: true or false.
- Default: false.
- Plus [+]: int/double + int/double
- Minus [-]: int/double - int/double
- Multiply [*]: int/double * int/double
- Divide [/]: int/double / int/double
- Exponent [^]: int/double ^ int/double
- Parenthesis [( )]: (int/double)
- Assigment [=]: variable = int/double
- Equals [==]: int/double/bool == int/double/bool
- Not equals [!=]: int/double/bool != int/double/bool
- Greater than [>]: int/double > int/double
- Less than [<]: int/double < int/double
- Greater than or equal to [>=]: int/double >= int/double
- Less than or equal to [<=]: int/double <= int/double
- And [&&]: bool && bool
- Or [||]: bool || bool
- Not [!]: !bool
- integer
- double
- boolean
- let
- true
- false
- if
- else
- for
- to
- step
- while
- break
- function
When declaring a variable this can be done in different ways:
let variableName;
- This will create a variable with the type 'any'.
- This allows further initialisation of the variable to other types.
let variableName = value;
- This will create a variable with the type of the value.
- This allows the compiler to infer the variable type.
<type> variableName;
- This will create a variable with the specified type with a default value.
<type> variableName = value;
- This will create a variable with the specified type and value.
- Once assigned a type, a variable cannot be changed to another type. See Types
- Variables of type 'any' cannot be accessed, they need to be initialised first.
- Must start with a letter.
- Can include numbers and underscores.
- Declaration and initialisation must end with a semicolon.
- Cannot be a keyword.
- Are case sensitive.
- Are accessed with the variable name.
// Declaring and assigning variables
let example_1 = 23;
let example_2 = 23.5;
let example_3 = true;
// Reassigning variables
example_1 = true // Error
example_1 = 24; // Valid
//Typed variables
let anyVariable; // Any type
anyVariable; // Error, varable
anyVariable = 23; // Integer type
anyVaraible = false // Error
integer example_4 = 24; // Integer type
double example_5 = 2,3; // Double type
boolean example_6 = false; // Boolean type
- Must be declared with the 'if' keyword.
- Must have a condition.
- Must have a body.
- The body must be surrounded by curly braces.
if(1 == 1) {
// Do something
}
- Must be declared with the 'else' keyword.
- Must have a body.
- The body must be surrounded by curly braces.
- Must be declared after an if statement.
if(1 == 2){
// Do something
} else {
// Do something else
}
- Must be declared with the 'for' keyword.
- Counter must be declared within the parenthesis.
- Elements within the parenthesis must be separated by a semicolon.
- Must have a condition.
- Must have a body.
- The step is optional (default is 1), but when used, it must be declared after the upper bound.
- The body must be surrounded by curly braces.
- Can be exited with the 'break' keyword.
for (let i = 0; to 10; step 2) {
// Do something
}
OR
for (let i = 0; to 10) {
// Do something
}
- Must be declared with the 'while' keyword.
- Must have a condition.
- Must have a body.
- The body must be surrounded by curly braces.
- Can be exited with the 'break' keyword.
while (1 == 1) {
// Do something
}
- Must be declared with the 'break' keyword.
- Can be used in for and while loops.
- Exits the loop.
- Ends with a semicolon.
break;
- Must be declared with the 'function' keyword.
- Must have a name.
- Must have a body.
- The body must be surrounded by curly braces.
- Parameters are optional.
- Parameters must be separated by a comma.
- Parameters must have the type specified. See Types.
function example() {
// Do something
}
OR
function example(integer a, double b) {
// Do something
}