AGI Logic Compiler Documentation

Floating Hills Software

Version 1.42


What is AGIC?

Until recently, there has been no easy way to recompile the logic code included with AGI games. This program, AGIC, is such a compiler. With it, one can compile a modified or new logic file, including the AGI Template Game.

The major benefits of using AGIC include:

AGIC and the associated utilities are free software. The source code for AGIC can be used in your own programs provided certain restriction are met. For information, read the COPYING file included with this distribution. Help support our planet by writing more software under the GNU Public License.

Changes in version 1.42 of AGIC?

Where is the latest version of AGIC?

The latest version of AGIC and HTML-ized documents regarding it can be downloaded at http://krypton.mankato.msus.edu/~jimf/agic/agic.htm

Questions regarding AGIC may be sent to greekcat@hotmail.com.


The Compiler

Section 1.1 - Compiling a File

To compile a file, use the command line AGIC filename [-o object_filename] [-t token_filename] [-e output_filename]. By default, AGIC will use OBJECT and WORDS.TOK for the object and token filenames, respectively. The output will normally go to LOGIC.OUT. To make life easier, this distribution includes various batch files for compiling with the preprocessor.

Section 1.2 - Executing Compiled Files

To execute a logic file, one will need to glue the logic file and other resources back into volume and directory files. There are automated utilities to do this (i.e., AGIGlue or AGI Studio).

Section 1.3 - Errors


AGIC Language

For the most part, the language is just like a mix of C and the output from the SHOWLOG program. The most important difference is the existence of a #message directive.

Section 2.1 - Variables

All variables are referenced as a lower-case v followed by the variable index. For example, variable number 3 is simply v3.

The included C-preprocessor can be used to name variables.

Section 2.2 - Flags

Flags can be referenced simply by the number (allowing the function to discern the difference) or by a lower-case f followed by the flag index. For example, flag 5 is simply f5. Flags are turned into numbers in the current version of AGIC.

The included C-preprocessor can be used to name flags.

Section 2.3 - Functions

Functions are called as in C, (i.e., foo(2,bob); or shakey(); ).

AGIC now includes limited type checking. The only distinction, however, is made between variable and non-variable arguments. Thus, load.view.v(12) will cause a warning, but set(5) and set(f5) are equivalent.

Section 2.4 - Conditionals

An if statement is the only branching command in AGIC. An if statement is as follows:

if (expression)
  {
  logic
  }
else  // optional!
  {
  more logic
  }

Although AGI, places strict limits on the complexity of boolean expressions, AGIC overcomes those limits by applying DeMorgan's laws to all boolean expressions until they are simplified down to a level applicable to direct machine code translation. Thus, the normal C logical operators (such as ! for not, && for and, and || for or) are legal in any combination one desires. The compiler will simplify the expression down to the appropriate level.

Section 2.5 - Goto

AGIC also allows the programmer to use the GOTO command. To define a label, simply begin a line with the name of the label (without spaces) followed by a colon. To goto a label, use the syntax goto(labelname); or now goto labelname. Calling a labelname that is not defined until after the goto is perfectly acceptable.

Although both parenthesis and parenthesisless forms of goto are acceptable, the parenthesis form is preferred. All other commands in AGI require parenthesis and goto should not be an exception.

Section 2.6 - Messages

One can use a string as a parameter to any function by simply including that string, enclosed in quotes (", not '), as the parameter. The compiler will allocate a message table entry and store the string there. If one uses the same string again, the compiler will reference the old message table entry.

Strings can include the usual \\, \n, and \" as used in C. They can also span multiple lines as they would in C.

Section 2.6 - #message and defstr

Sometimes, it is necessary that a particular string be assigned a particular entry in the message table. To do this, one uses the #message command. #message stores the given string at the given message table entry. The #message directive is simply:

#message num "string text goes here"
For compatability, defstr is still supported.

Section 2.7 - Arithmetic

When using AGIC, it is not always necessary to call functions to perform most arithmetic operations. Rather, these operations can be performed individually on a line. In particular, AGIC supports the C operators =, +=, -=, *=, /=, ++, and -- between variables and integers.

Section 2.8 - Indirection

AGIC also supports c-like indirection commands, in particular:

v10 = *v22; // rindirect(v10,v22)
*v10 = 22;  // lindirectn(v10,22);
*v10 = v22; // lindirectv(v10,v22);

Section 2.9 - The Preprocessor

This release of AGIC includes a Win32 port of the GNU C preprocessor. This can be used quite easily on AGI logic files, allowing variables to be defined and files to be included. The compiler is designed to deal with the modified output from the preprocessor. Comments and whatnot are also taken care of by the preprocessor.

Section 2.10 - The [ comment

Any text following a [ is considered to be a comment.

Section 2.11 - Symbol blocks

At times, it is impossible to compile a logic file because it references some symbol which contains parenthesis or some other character which confuses the compiler. In those cases, the symbol may be surrounded with |'s. For example:

if (has(|Buckazoid(s)|)) { ... }

Symbol blocks are an unstandard feature of AGIC.


The Sample Program

The sample program has been removed beginning with AGIC v1.42. We suggest that you download the excellent Template Game. Since AGIC now compiles the template game, it is a far more interesting choice than a simple program which displays a picture.