The Angliconian2 Language
Latest Release R19
Angliconian2 is my first (successful) attempt at writing an interpretor and a language. Currently it works fine and is tested under linux, Mac OS X, and FreeBSD but should work under other systems including Windows.
Angliconian2 got its name from two places. The Ang part is from my girlfriend's name, and the liconian was added for fun. The 2 is in the name because after so many failed attempts before a working one, and so many rewrites, I just started over (again) and named it Angliconian2.
Note that the information on this page is only a guide to the currently implimented features found at in the source of my website. As new features are added (and uploaded) they will be added here.
Obtaining the latest (working) sources
Now working
Simply types these commands in a terminal/console:
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/angliconian2 login
cvs -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/angliconian2 co ang2
When asked a password just hit enter.
Command Line Parameters
-w, -c, -n
-w is a web parameter. This automatically prints the HTML content type and disables input.
-c simply displays all comments as if there was a {print} before them (and will display variable information).
-n is -c but with {printn}
General Information
The structure of the language is quite simple. Every line will start with a character that describes what will happen. No characters are needed at the end of a line of code.
- : - Create Variable
- [ - Set Variable
- { - Call Function
- ! - Compare Statement
- / - Declare Label
- . - Goto Label
Comments
Given that the interpretor only interprets lines starting with a :, [, {, !, /, or ., a comment can simply be declared by not starting with one of those.
Example:
Declaring variable i
:i
Now doing something else...
Creating Variables
:VARIABLE_NAME
VARIABLE_NAME refers to the name you wish to call your variable. Variables now autosize!.
Example:
:i
will create a variable i.
Setting Variable Data
[VARIABLE_NAME]DATA
This is pretty self explanitory, DATA will be parsed for variables and VARIABLE_NAME will be resized.
Example:
[i]hello
will set i to the string hello.
Printing To The Screen
{print}DATA
{print}DATA[VARIABLE]DATA
{printn}DATA
{printn}DATA[VARIABLE]DATA
{printbr}DATA
{printbr}DATA[VARIABLE]DATA
DATA is simply any text you want written to the screen and [VARIABLE] will display the contents of VARIABLE to the screen.
{printn} is the same thing as {print} but moves the cursor to the next line afterwards.
{printbr} is the same thing as {printbr} but addes <br/> before the \n
Example:
{printn}Hello
{print}You are
{printn}[name]
{printn}Hello, you are [name]
Receiving Input
{input}[VARIABLE]
This is pretty self explanatory. Note that it will not save the line return to the variable. At the moment, a max of ISIZE (200) will be allowed.
Example:
:name
{print}What is your name?
{input}[name]
{printn}Hello, [name]
Receiving Integer Input
{inputn}[VARIABLE]
This is the same thing as input but will only take integers.
Random Numbers
{rand}[VARIABLE], MAX
Note that this goes from 1 to MAX.
Example:
:rand
{rand}[rand], 100
{printn}Random number from 1-100: [rand]
Math Expressions
{eval}[VARIABLE]
{evals}[VARIABLE], EXPRESSION
Evaluates the data in VARIABLE with a math parser.
Example:
:i
[i]5+1
{eval}[i]
{printn}5 + 1 is [i]
Truncating a number to an integer
{makeint}[VARIABLE]
Pretty self explanatory, makes a number an integer. Note that this does not round, it truncates.
Rounding a number to an integer
{makeintr}[VARIABLE]
{makeint} but rounds instead of truncates.
Resizing Variables
{resize][VARIABLE], NEW_SIZE
Pretty self explanatory, resizes the variable and truncates any data if needed.
What's the point with (now) auto-sizing variables? Truncating mostly.
Example:
:i
{resize}[i], 2
Conditional Statements
![VARIABLE]!OPERATOR!COMPARE_TO
VARIABLE is the first part of the condition.
OPERATOR can be <, =, >, <=, >=, or 0 (0 is for not equal to).
COMPARE_TO can be either a simple string or a variable.
Note 1: that to end a statement, you use *!
Note 2: that to use an else, instead of *! use *e (THIS IS NOT AN ELSE IF)
Note 3: that to use an else if, instead of *! or *e, use *i.
Example:
:mynumber
:guessednumber
{rand}[mynumber], 10
/guess
{print}I have a number from 1-10, guess:
{inputn}[guessednumber]
![mynumber]!<![guessednumber]
{printn}Guess lower.
.guess
*!
![mynumber]!=![guessednumber]
{printn}Good job!
*!
![mynumber]!>![guessednumber]
{printn}Guess higher.
.guess
*!
Labels and Jumps
/LABEL_NAME
.LABEL_NAME
To create a label to jump to, use / followed by the name of the label.
To jump to that label, use . followed by the name of the label.
Note, jumping to a non-existant label will essentially end your program (allowing you to .exit as long as there is no /exit)
Example:
/start
...
...code...
...
.start
Appending data to variables
{append}[a], [b]
{append}[a], TEXT
{appends}[a], [b]
{appends}[a], TEXT
Pretty self explanatory. {appends} is an {append} where it adds a space before [b] or TEXT. Note that you can mix variables and text.
Quotes
"..."
Allows you to to do something like {append}[a], " ..."
Special Characters
\\, \", \n, \t, \[
You can now make use of simple special characters. \\ becomes \, \" becomes ", \n becomes a new line, \t is equivilant to pressing tab, and \[ becomes [.
Getting text from a variable
{getc}[TOSTORE], [GETFROM], x
{gettext}[TOSTORE], [GETFROM], x, y
getc will take the xth character from GETFROM and place it in TOSTORE.
gettext will take all characters starting at x UP TO y.
NOTE that the first character of a string is 0 not 1
Example:
[a]Test
{getc}[b], [a], 0
{gettext}[c], [a], 1, 3
[a] will contain Test
[b] will contain T
[c] will contain es
Loading files
{loadfile}[DATA VARIABLE], [FILE]
This will load the file into DATA and then set a variable called [ferr] to either Y or N. ferr means File Error so if it is Y then an error occured.
Example:
:data
{loadfile}[data], testfile
![ferr]!=!Y
{printn}ERROR
*!
![ferr]!=!N
{printn}[data]
*!
Saving files
{savefile}[DATA VARIABLE], [FILE]
Identical to {loadfile} with the exception of it saving instead of loading.
Bit Logic
{and}[SAVE TO], [VARIABLE 1], [VARIABLE 2]
{or}[SAVE TO], [VARIABLE 1], [VARIABLE 2]
{not}[SAVE TO], [VARIABLE]
Pretty self explanatory -- numbers will be truncated to ifs however.
Can be useful for ifs!
Also now you can use & for and, | for or, $ for xor, and ~ for not in {eval} and {evals}
Working With Parameters
{getarg}[SAVE TO], [ARGUMENT NUMBER]
{argcount}[SAVE TO]
Pretty obvious - note that outside of a function this refers to the parameters sent to the interpretor (excluding interpretor options) and where 0 is the source file and 1 is the first meaningful parameter to your program.
Inside of a function, it will refer to the parameters passed to it, starting at 1 (for consistancy with 0 being the function name)
It is good programming practice to check argcount before proceding to use getarg.
Variable Length
{size}[SAVE TO], [VARIABLE]
{asize}[SAVE TO], [VARIABLE]
{size} will obviously save the length of VARIABLE to SAVE TO
{asize} will set SAVE TO to the amount of items in the array VARIABLE
Functions!
{{NAME}}VARCOUNT
...
*}}
Currently, return values and references are not supported but recurssion is along with parameter passing.
Passing parameters and calling a function are the same as internal functions.
NOTE: If there are no parameters, use 0 for VARCOUNT
NOTE: Variables are local ONLY - global variables will be seen as undeclared variables in the functions. Also, error line numbers are specific to function, in the main scope count lines as if the functions were not there.
NOTE: With {getarg}, argument 0 is ALWAYS the function name (just as in any C program argv[0] is how the user called the program, only this applies for all functions in Angliconian2).
Examples:
{{printx}}1
:x
{getarg}[x], 1
{printn}x=[x]
*}}
[x]5
{printx}[x]
[x]1.0
{printx}[x]
Function Return Values
{{NAME}}RVARCOUNT
...
{setreturn}RETURN DATA
*}}
Functions with an R preceding the variable count mean the first parameter passed to it will contain the returned value.
Note that the return value variable is not included in the variable count.
Example:
{{adder}}R2
:a
:b
:c
{getarg}[a], 1
{getarg}[b], 2
{evals}[c], [a]+[b]
{setreturn}[c]
*}}
:result
{adder}[result], 5, 7
{printn}5+7=[result]