Skip to content

oduwa/Gary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gary

Simple procedural programming language for general purpose scripts.

Screenshot

Gary is case insensitive. This means that keywords can be upper case, lower case or even a mix of both and still work. Also, note that semicolons are not necessary at the end of each line but are optional. Programming statements are logically separated by new lines. However, if you want multiple programming statements on the same line, a semicolon is necessary at the end of each line. Below are the features of the language and how they are used by default. The keywords can be customised to use other words but the idea is the same.

Note: While some features (docmented below) are available, Gary is still a work in progress. Please stay tuned for a stable release.

Setup and Keyword Customisation

Simply download the repository and copy the dist directory to wherever you want to use it. To start writing programs in Gary, simply run the GaryEditor.jar file to start the mini IDE and get cracking! The default setup of syntax and keywords is described in the following sections. To setup your own keywords, use the KeywordConfig command line program distributed with Gary. Spaces are not allowed in custom keywords. To separate words in a keyword, the underscore character ("_") may be used instead. The signature of the tool is as follows:

Unix:

./KeywordConfig [OPTIONS]

Windows:

KeywordConfig.exe [OPTIONS]

An example command for how this program can be used is as follows -

# This command will change the "disp", "increment" and
# "while" keywords to "print", "plusplus" and "round_and_round".
#
# On Windows, replace "./KeywordConfig" with "KeywordConfig.exe"
./KeywordConfig -disp print -pls plusplus -while round\_and\_round

The table at the bottom of this document shows a list of the available options for the KeywordConfig tool.

Variable Types and Assignment

Values are assigned to variables using the << operator. Gary is a weakly-typed language. Basically, this means that you do not need to specify the type of a variable when you declare it. Its type is inferred from the value it is assigned.

@firstName << "John";
@lastName << "Doe";
@age << 100;
@height << 6.1;

Output

Use the disp keyword to print to the console.

disp "Hello World!";

Comments

Use the "#" character to denote that a line contains comments and should not be processed. Note that this character must be at the start of the line and no other programming statements can be on that line.

# This is a comment
disp "There's a comment above!";

Conditionals

Gary provides if, else and elseif-statements as shown below

if @varA == @varB then
  disp 1
elif 1 > @varA then
  disp 2
else
  disp 3
endif;

Iteration

Gary supports iteration via while-loops. An expression is specified as a condition after the while keyword. As long as this expression evalueates to 1, the code within the while loop will be executed.

@varA << 0;
while 10 >= @varA then
	increment @varA;
	disp @varA;
endwhile

(The increment and decrement keywords are the Gary equivalent of ++ and -- in other mainstream languages)

Functions

With Gary, functions are declared using the func keyword, followed by the function name and a list of arguments between brackets and the the function return type. After the function is defined, its scope should be closed using the endfunc keyword.

func myFunc() void:
	disp "printing from my function"; 
endfunc

myFunc();

Functions don’t need to be declared or defined before they’re called. They just need to be defined at some point.

Lists

Lists are created using the built-in CREATE_LIST(TEXT type, NUMBER size) function. Lists can be manipulated with add and remove operations provided by the built-in ADD_TO_LIST(VAR list, VAR value), PUT_IN_LIST(VAR list, NUMBER index, VAR value) and REMOVE_FROM_POSITION_IN_LIST(VAR list, NUMBER index) functions. Note that lists are indexed starting from 1 and not 0.

# Create list of strings
@words << CREATE_LIST(string, 5);

# Manipulate lists
ADD_TO_LIST(@words, "pie");
ADD_TO_LIST(@words, "sky");
ADD_TO_LIST(@words, "tie");
REMOVE_FROM_POSITION_IN_LIST(@words, 3);
PUT_IN_LIST(@words, 2, "sky");

# Print list
disp @words;

Index

Option Description
-if Replacement for if keyword
-then Replacement for then keyword
-else Replacement for else keyword
-elif Replacement for elif keyword
-endif Replacement for endif keyword
-while Replacement for while keyword
-ewhile Replacement for endwhile keyword
-assgn Replacement for <<, the assignment operator
-and Replacement for AND keyword
-or Replacement for OR keyword
-e Replacement for ==, the equality operator
-disp Replacement for disp keyword
-ret Replacement for return keyword
-func Replacement for func keyword
-efunc Replacement for endfunc keyword
-lmake Replacement for CREATE_LIST keyword
-ladd Replacement for ADD_TO_LIST keyword
-lput Replacement for PUT_IN_LIST keyword
-lrmv Replacement for REMOVE_FROM_LIST keyword
-pls Replacement for INCREMENT keyword
-mns Replacement for DECREMENT keyword

About

Customisable programming language for general purpose scripts

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published