Skip to content

Vierre3/Glados

Repository files navigation

Basic structure of a glados program

Here is a short description with examples of a glados program, with each element explained :



Comments

Comments allows the developer to specify the description of the program, the name of the program, and the creation date and time of the program.
Documentation comments are usually placed at the start of the program.
Documentation can be represented as:

// description, name of the program, of a function, programmer name, date, time etc.

or

///
    description, name of the program, programmer name, date, time etc.
///

Anything written as comments will be treated as documentation of the program and this will not interfere with the given code.
They simply gives an overview to the reader of the program.



Include

See compilation and builtins in glados

Include allows the program to call upon functions that are not part of the compiled files.
These includes must be at the top of the file, and will otherwise break

Examples:

include #io;

Note

To use a library one must explicit the folder containing the libraries during compilation.
To do so, use the --library flag followed by the concerned folder.



Global Declarations

The global declaration section contains global variables, function declaration, function calls and static variables.
Variables and functions which are declared in this scope can be used anywhere in the program.

Examples:

int num <- 18;
str val <- "Hello World!";


Scopes

Scopes allow instructions to be intertwined together and combined to form a single value.
These scopes are necessary to attribute to a variable or return a combination of operations.
Scopes can be chained together to allow the retrieval more complex set of instructions.

Examples:

str val <- ("Hello " + "World!");
float num <- ((18 + 2) / 4);


Functions

User-defined functions are called in this section of the program.
The control of the program is shifted to the called function whenever they are called from the main or outside the main() function.
These are specified as per the requirements of the programmer.

Example:

int sum(int x, int y) [
    return (x + y);
];


Main Function

The main function is optional in a glados program.
A main will not be mandatorily called but can instead be called explicitely from the global scope.
Return of an error code to the terminal can be made through use of the exit built-in.
Should the user wish to use a main without returning anything, the main can simply be called by itself.

Example:

int main() [
    ...
];

exit(main())
void main() [
    ...
];

main()


Example: glados program to find the sum of 2 numbers:

// Documentation

///
// file: sum.gs
// author: you
// description: program to find sum.
///

// Include
include #io;

// Global Declaration
int x <- 20;

// Subprogram
int sum(int y) [
  return (x + y);
];

// Main Function
int main() [
  int y <- 55;

  putStr("Sum: ");
  printLn(sum(y));

  return 0;
];

// Main Function Call
exit(main());

Output :

Sum: 75

Explanation of the above Program

Below is the explanation of the above program. With a description explaining the program's meaning and use.

Sections Description
///
/ file: sum.gs
/ author: you
/ description: program to find sum.
///
This comment is a part of the description section of the code.
include #io; This include specifies the library that contains functions not declared in the compiled files
int x <- 20 This globally declared variable can be used anywhere in the program.
int sum(int y) [
 return (x + y);
]
This is the function we defined, which in this example is called in the main() function.
int main() main() is conventionally the first called function of a program.
[...] These square brackets mark the beginning and end of the a function.
printLn(sum(y)); The printLn() function is used to print the sum on the screen and converts the output of sum() to a string.
return 0 We have used int as the return type so we have to return 0 which states that the given program is free from any error and can be exited successfully.

If you're curious about running your program, see glados program compilation

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors