New syntax programming language Aura
Welcome to the official user guide for the Aura programming language. This guide will walk you through Aura's unique syntax, program structure, and features, using complete examples from the enclosed files.
Aura is designed with a primary goal: to make code flow from left to right, much like natural writing. This is achieved through a few core syntactical changes that streamline the development process.
First, let's cover the fundamental building blocks of the Aura language.
- Reversed Assignment Operator: The most significant change is the assignment operator. Instead of
variable = value, Aura usesvalue -> variable. This allows for a natural left-to-right flow. For example:a + b -> a. - Tagged Keywords: Control flow and structural keywords are enclosed in curly braces, much like a markup language. Examples include
{while}...{/while},{fun}...{/fun}, and{if}...{/if}This makes it easy to find mistakes and introduce new keywords. - Comments: Single-line comments begin with
//.
Aura supports standard data types:
int: integerfloat: float decimalchar: characterstring: array of "char"bool: boolean "true" or "false"
It also supports standard arithmetic operators: +, -, *, /, and % (mod) .
You can declare a variable with or without an initial value.
- Declaration only:
int i - Declaration with initialization:
int i(0)(i becomes 0) ,char c("a"),bool l(true),string s("abcde").
Aura programs are organized into modules and functions.
A program is defined within a {module} block.
{module} Euclidean // module itself
...
{/module}
Function declarations are also reversed to fit the left-to-right flow .
- Syntax:
{fun} <input_parameters> -> <function_name> <return_type> - Example:
{fun} int a, int b -> Euclid int(This declares a function namedEuclidthat takes twointparameters and returns anint). - Calling a function:
a, b -> f
The entry point for your program is the main function.
- Declaration:
{fun} string args[] -> main int
This full example demonstrates a simple module, function declaration, and Aura's powerful I/O syntax.
{module} Euclidean // module itself
{fun} int a, int b -> Euclid int // function with type int
{while} b!= 0
{if} a > b
a - b -> a
{else}
b - a -> b
{/else}
{/if}
{/while}
{return} a {/return}
{/fun}
{fun} string args[] -> main int // main function
int a, b
in -> a, b -> Euclid -> out
// combined input and output and function call
// seamless input to output syntax
{/fun}
{/module}
Notice the line: in -> a, b -> Euclid -> out. This single line seamlessly:
- Takes input (
in) - Assigns it to variables
aandb - Passes
aandbto theEuclidfunction - Takes the return value from
Euclid - Sends that result to output (
out)
Aura provides standard control flow mechanisms and array support.
The Euclidean example shows a simple {if}/{else} block.
{if} a > b
a - b -> a
{else}
b - a -> b
{/else}
{/if}
The Euclidean example also uses a {while} loop.
{while} b!= 0
...
{/while}
- Declaration:
int a[n](declares an integer array withnelements). - Initialization:
int a[4]([1, 2, 3, 4]). - Access:
a[i](0-based indexing).
Aura has a specific syntax for {for} loops .
- Syntax:
{for} i(0)++ <n - Explanation:
i(0): The iteratoriis initialized to 0 .++: The iteration step is by 1 .< n: The loop continues as long asiis less thann.
Here is an example of a {for} loop used to populate an array:
{for} k(0)++ < n // fill with true
true -> primes[k]
{/for}
The following program, primes, uses arrays and loops to implement the Sieve of Eratosthenes algorithm.
{module} primes
{fun} int n -> Eratosthenes // subroutine declaration
bool primes [ n ] // variable declaration
int l(0), i(0), index_square(3)
int first, last, factor
{for} k(0)++ < n // fill with true
true -> primes[k]
{/for}
{while} index_square < n
{if} primes[i]
0 + index_square -> first
0 + n -> last
i + i + 3 -> factor
false -> primes[first]
{while} last - first > factor
first + factor -> first
false -> primes[first]
{/while}
{/if}
i + 1 -> i
2 * i * (i + 3) + 3 -> index_square
{/while}
' 2' -> out // print out
{for} i(0)++ < n // print out
{if} primes[i]
{if} 2 * i + 3 > n
break
{/if}
' ' 2 * i + 3 -> out
l + 1 -> l
{if} l % 10 == 0
'\n' -> out
{/if}
{/if} // if
{/for} // print out
'\n number : ' l -> out
{/fun} // erato fun
{fun} main int // main function
1000 -> Eratosthenes // subroutine call
{/fun}
{/module}
This example demonstrates array manipulation (e.g., false -> primes[first] ), nested loops ({while} inside {while} ), and sending formatted output to the console (e.g., '\n' -> out ).
Aura also supports classes, allowing for object-oriented design.
- Declaration:
{class} ClassName ... {/class}. - Members: You can define data members (e.g.,
int a, int b) and member functions (e.g.,{fun} ... -> Euclid) inside a class. - Object Creation:
GCD Ncreates an instance (object)Nof the classGCD. - Access: Members are accessed using the dot operator (e.g.,
N.a,N.Euclid).
Here is the Euclidean algorithm refactored into a class.
{module} Euclidean
{class} GCD //class declaration
int a, int b //data members
{fun} int a, int b -> Euclid int //member function
{while} b!=0
{if} a > b
a - b -> a
{else}
b - a -> b
{/else}
{/if}
{/while}
{return} a {/return}
{/fun}
{/class}
{fun} string args[] -> main int //main function
GCD N //object N of class GCD
in -> N.a, N.b -> N.Euclid -> out //input, output in one line
{/fun}
{/module}
Once again, the main function showcases Aura's natural flow. The line in -> N.a, N.b -> N.Euclid -> out reads input directly into the object's data members (N.a, N.b), calls the object's member function (N.Euclid), and prints the returned result.