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 syntax 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.Scripting.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.
Parser Compatibility
Expression text → parser → PPJ abstract syntax tree → interpreter + application context
Changing the parser changes how text becomes that tree. It does not automatically add new runtime operations, new member-resolution rules, or access to C# method locals. For example, recognizing SAL's concatenation operator is only correct if the emitted tree performs the intended string operation and preserves its null/conversion behavior.
Changing the default parser also changes SQL bind/into interpretation. Prefer the narrowest registration that meets the requirement. Test precedence, null propagation, conversions, member resolution, and assignment rules before switching existing scripts. Treat the AST contract as release-specific and do not execute untrusted expressions.