Table Driven Logic
Compiler Compile-Time Functions
June 1, 2021


The readability of programming logic has many benefits. So as I move toward a unified approach to software development, the fabric that will tie everything together will be our ability to understand, change and rely upon our software development process.  To change our current technology is difficult, or at least that is what I thought. With a few minor adjustments to our technology, software development can move toward perfection. The first change that I implemented was to reduce the number of logic permutations.  The second change was to allow a mixture of custom language intermixed within the Jane language. The third change that I will implement is to move toward a totally table driven software development environment.

Instead of brute force coding of complex logic, we can now program in tables of actions.  This applies to procedures such as:

  1. Parsing logic, the selection of operation based on a sequence of characters
  2. Compiler logic, where code is selected based on an opcode and on the type of operands
  3. Keyboard Events, where action is based on the keys being pressed
  4. Regular Expressions, an action based on set opcode and a sequence of characters
  5. State Transition Tables
  6. Main Menus, and Popup Menus
  7. ...many others...

The ability to change software means that we must have access to the code, and understand it. Our current software development technology permits neither of these things.

In building my first compiler function I discovered a few things:

  1. Compiler function generated code is far easier to read
  2. Compiler functions are far easier to write than conventional coding
  3. It is easier to control the scope of the project
  4. Run-time functions could be used, but is more difficult to test, slower and difficult to implement
  5. Having one location for all the code is desired (i.e. the compiler function, next to the code that uses it)
  6. Speed is a benefit, any lag-time is in compile-time, not at run-time
  7. More flexibility by having compile-time and run-time logic
  8. The learning curve is high. I need more experience
  9. I believe 60% of all applications can be table driven, but I will just have to wait and see
  10. changes the way I write code, much more efficient and easier to maintain
  11. changes logic from functions to the switch statement, which actual fits better to this environment
  12. Eliminates the need for build files, and reduce the need for complex install procedures

 

In this page I show how I enhanced the Jane Compiler to accept user defined programming languages.  One of the methods that I used was to tag a group of code to be processed at compile time by calling a user written function.


compiler function hello(script) 
{
	if (script == 'in english') return "alert('Hello World');";
	if (script == 'en española') return "alert('Hola Mundo');";
	return "";
}
hello { in english };

The "hello" function is run at compile time and is not available at run time. This example produces compiled code as if the source code read.

	alert('Hello World');

 


 

I am writing the Jane Compiler and the Jane Editor. Each of these programs benefit from the ability to be table driven. The compiler has 185 opcodes with all the permutations of operands that is best implemented in tabular form. The Editor's keyboard operations also falls into this category.

The keyboard text I use to separate onkeydown event logic. I wrote a program to output the complex logic needed. Below each case statement I will add the code to perform the specific editor logic of each key down event. The Generated Code is difficult to program and even harder to change. So I let a program organize and rearrange the statements as needed. Click HERE to see full listing of the following code.

	keyboard
	{
		case keyboard.space:
		case keyboard.alpha:
		case keyboard.alpha(shift):
		case keyboard.number:

		case keyboard.A(ctrl):
		case keyboard.C(ctrl):
		case keyboard.V(ctrl):
		case keyboard.X(ctrl):

		case keyboard.escape:
		case keyboard.alt:
		case keyboard.end:
		case keyboard.pause:
		case keyboard.tab:
		
		....
	}	

The keyboard Compiler Function that I wrote generates all the code needed to implement the Jane Editor. The compiler treats all the text enclosed in braces {} as text that is passed to the named compiler function. The return value from the function is then compiled as part of the input text. 

Note: The braces may contain unique tags: keyboard {~mytag~ .... ~mytag~}. This eliminates the need for your custom programming language from having to use escape characters. Just select a tag that is unique.

 


Multiple Languages

There are many benefits that I found that were not obvious. I will be adding other computer languages to the Jane Language. These will be treated differently to take advantage for the similarities between all programming languages. The syntax to the programmer remains the same.

	ALERT('Hello world');

	FORTRAN
	{
		FUNCTION ALERT(TEXT)
		WRITE (*,*) TEXT
		END
	}

 


 

Fast Custom Application

Another benefit that I found was, that we will be able build custom application like compilers in a few minutes by simply selecting the statements that we which to implement.  This is critical for security reasons, by having code that is restricted to a just the opcodes and operands needed for a given environment. 

Readability and changeability is absolute. Testing becomes segmented from the first line of code to the very last in a way that reliability is obvious to the casual user.   Evolution of logic is expected, desired and supported by this type of development.  

	MY ASSEMBLE
	{
		machine 	Intel 8080;
		
		statement	move;
		statement 	compare;
		statement	add;
	}