Jamie Balfour

Welcome to my personal website.

Find out more about me, my personal projects, reviews, courses and much more here.

ZPE 1.5.2 brings a huge new feature!

Back in the days of version 1.3 it was always my intention to make it possible to add custom compiler syntax to ZPE. I did this originally in a very simple way that made it easy for me to develop but harder for others to develop. Today, version 1.5.2 brings this feature back. It improves it considerably and makes it fully possible to write your own syntax. I've even decided to make it possible to overwrite the built in keywords including things like if and while. 

How does this work?

It's not the easiest of things to explain but I will try. Firstly, when ZPE is launched it will search through all of it's plugin directories. A new directory called 'keywords' has been added to version 1.5.2. This directory contains all of the user's custom keyword plugins. The manager then adds these to the compiler based on the name value given to the keyword plugin.

The next stage is for the compiler to compile the word. The plugin handles the compilation job and can access the owning ZPE's public functions (including the new ExternalMethods object) before returning an AST.

Within the interpreter the plugin's traverse method is called. It is then the plugins job to traverse when the plugin is given an AST back (the same AST given previously) and to run it as code. It's pretty easy to do and it's designed to be easier than doing it the way the internal compiler does it.

Below is a plugin called 'jack'. It simply takes the next word and stores it as a value.

Java
import jamiebalfour.zpe.core.AST;
import jamiebalfour.zpe.core.ZenithEngine;
public class ZenithCustomModule implements jamiebalfour.zpe.core.ZenithCustomModule {

	@Override
	public String GetName() {
		return "jack";
	}

	@Override
	public AST CompileToAST(ZenithEngine z) {
		
		AST a = new AST();
		z.ExternalMethods.EatSymbol();
		a.value = z.ExternalMethods.GetCurrentCompilerWord();
		
		return a;
	}

	@Override
	public void Traverse(ZenithEngine z, AST node) {
		
		System.out.println(node.value);
		
	}

}

Below is a sample of the ZenLang code that runs this:

ZenLang
function main()
	jack x
	$a = 0
end function
Comments
Powered by DASH 2.0