Suttree.com: Casual Games, Social Software

Read more at the weblog »

Autocoder

Autocoder is a very simple, very high level language interpreter. It interprets the instructions passed to it, but does not execute any of the resulting code. Autocoder creates a Perl script that does the work that the instructions ask it to.

Currently it can be used for simple import scripts, specifically importing csv files and creating SQL code that can be piped into a database. In these instances, a lot of the code can be broken down into pseudo-code. These form the basis of the 'SQL::Like' language that controls Autocoder.

SQL::Like.
SQL::Like is the simple, high level language that controls Autocoder. Since the main steps in a simple Perl script can be represented in SQL like plain English statements, SQL::Like is meant to imitate and benefit from this simplicity.
There are four commands that Autocoder understands so far, these are;

READ
Syntax: READ /path/to/file/filename AS Alias
The READ command will open a file and read its contents into the variable defined by Alias.

SPLIT
Syntax: SPLIT Alias USING separator
The SPLIT command simply separates the contents of the Alias, and for the main is used to denote how the input file is formed, e.g., whether it is a comma separated file, or a tab separated file, and so on.

JOIN
Syntax: JOIN WHERE Alias_1.x equals Alias_2.y
The JOIN command is used when there are two or more files open that need to be linked. It is an attempt to mimic the SQL command JOIN, and uses the Alias files named in READ, and a numeric, zero based index to specify the columns on which to join. The JOIN mechanism can either be equals for string equality, or = for numeric equality.

PRINT
Syntax: PRINT string
The PRINT command is just a simple print utility, with all output currently being sent to STDOUT.

Usage
In order to make use of Autocoder, create a set of instructions using the four commands above and store them in an instructions file. Then call autocoder.pl and supply the instructions file as a command line parameter, e.g.
% ./autocoder.pl instructions.ins

Once the script has run, it will create a file called example.pl in the current directory. This filename can be changed by manually editing autocoder.pl, and a tidier version of specifying the filename will form part of Autocoder version 2.0. The example.pl file can then be run as a normal Perl script;
% ./example.pl or % perl example.pl

Installation
Installation should be simple, just decompress the contents of autocoder.tar.gz to a directory. This should create a folder called Autocoder-v1.0 inside which is a file called autocoder.pl, which needs to be edited before it can be run. Open autocoder.pl using your favourite text editor, and head for the line that reads;
#use lib("/Your/Install/Path/Here/modules");

Uncomment that line and replace /Your/Install/Path/Here/ with the full path to the directory you decompressed the autocoder.tar.gz archive. It should end up looking something like this;
use lib("/Users/duncan/Autocoder-v1.0/modules");

Once that is done, the script is ready to run. An example set of data is provided, in the form of a test instruction set (instructions.ins) and two .csv files (Train_Stations.csv and Train_Companies.csv). Run autocoder.pl as follows, and this should create a simple example.pl script that joins those two .csv files together and outputs a few lines of SQL code that would insert details about train stations and train companies into a fictional database table.
% ./autocoder.pl instructions.ins

Download
Autocoder and SQL::Like can be downloaded from here;
Download Autocoder v1.0

Version 2
Version 2 is underway, so any flames, feedback and questions can be directed to me, , while I bask in the reflected glory of the wonderous language that is Perl.

Suttree Beatniks with better clothing, brought to you by Duncan Gough. About Archives Casual Game Dev Code Disclaimer EcoLocal Music Knows PMOG Tumblee
Links for Saturday, October 11th, 2008