Custom Parsers

A very powerful feature of the Porting Project is the built-in interpreter that is used to support SalCompileAndEvaluate and to resolve bind/into expressions in sql statements. The interpreter executes a code tree expressed as a structured collection of code objects. The code tree can be generated in any way. Usually it's generated by a parser that parses the source code language into a code tree.

The built-in parser supports C# syntax only. However it is possible to plug-in a custom parser that is responsible only for the parsing of the source code. A custom parser class needs only to implement the PPJ.Runtime.Scripting.IScriptParser interface which defines only one method:

public interface IScriptParser
 ASTNode Parse(string script);

The custom parser should only parse the source code text into an Abstract Statement Tree (AST).

To register the custom parser to be used only with SalCompileAndEvaluate use:

Sal.Interpreter.Parser = new MyParser();

To register the custom parser to be used only with XSalScript, use:

XSalScript.Interpreter.Parser = new MyParser();

To register the custom parser to be the default parser for everything, including bind/into expressions evaluations, use:

PPJ.Runtime.Scriping.ScriptEngine.DefaultParserType = typeof(MyParser);

All AST classes are derived from ASTNode and are available in the PPJ.Runtime.Scripting namespace. There is no public reference manual about the AST classes and if you need to write your parser we can provide sample code for your reference and professional support upon request.

Last updated