Skip to main content

SalCompileAndEvaluate

SalCompileAndEvaluate interprets application-supplied expression text at runtime. PPJ uses related scripting infrastructure for SQL bind/into expressions. This differs from compiling the surrounding C# application: a successful project build does not validate a string that will be parsed later.

The default parser uses a C#-style syntax, with PPJ compatibility behavior. It is not a promise to support every construct accepted by the current C# compiler. A custom parser can provide another syntax; see Custom Parsers.

Syntax​

Review expression strings separately from the generated C# code. Common translations are:

IntentSAL expressionC#-style expression
Concatenate stringssName || " suffix"sName + " suffix"
Logical andbReady AND bValidbReady && bValid
Logical orbReady OR bValidbReady || bValid
NegationNOT bReady!bReady
EqualitynValue = 10nValue == 10

The same || symbols mean string concatenation in the SAL example and logical OR in the C#-style syntax. Mechanical text replacement is unsafe when an operator appears inside a quoted string or when the surrounding expression relies on precedence. Test the complete expression, with parentheses that make the intended grouping explicit.

Comparison Versus Assignment​

For a Boolean test, submit an expression such as nValue == 10. The expression nValue = 10 is an assignment in C#-style syntax and can change application state instead of testing it.

PPJ disables inline assignments by default to help catch this migration mistake. Compatibility handling of explicit assignment statements such as Set belongs to the installed parser; do not confuse interpreter input with a C# if statement, which also needs C# statement syntax and a Boolean condition.

This property enables inline assignments:

PPJ.Runtime.Scripting.ScriptEngine.AllowInlineAssignments = true;

It is a shared engine setting, not a repair for one comparison string. Prefer correcting the intended comparison. If assignment is an intentional application feature, review all expressions affected before changing the shared policy.

Full Script​

The PPJ interpreter also supports script blocks using the constructs available in its parser. This excerpt illustrates a block; the ellipsis stands for the remaining arguments required by the chosen CompileAndEvaluate overload:

Sal.CompileAndEvaluate(@"
{
for (int i = 0; i < 10; i++)
{
Sal.MessageBox(i.ToString(), sTitle, 0);
}
}", ...);

Variables declared inside the script, such as i, are interpreter locals. They are different from C# method locals outside the string. The external sTitle still has to resolve through an available application context.

Scope​

A C# local named sTitle does not become visible merely because the script string was created in the same method. The interpreter needs a resolvable object member or registered application symbol. Generated extracted locals, supplied through SqlContext, provide one such bridge.

C# method local alone → not an object member the interpreter can discover
Extracted locals.sTitle → available through the established locals context
Owner's member → requires the intended owner context
Application global → requires the generated/registered global context

Visibility is not unlimited access to every loaded object or arbitrary private member. Preserve the generated contexts and global-registration conventions. If multiple scopes contain the same name, inspect which value the installed resolver selects rather than assuming the C# lexical scope controls it.

Expression Review​

Treat interpreted text as executable application logic. Do not evaluate untrusted text as a substitute for parsing user input. A restricted UI around a textbox does not by itself turn the interpreter into a sandbox.

For each migrated expression, record the input values, expected result type/value, and any intended side effects. Test null values, true and false conditions, strings containing operator characters, and duplicate names in different owners. Distinguish parsing failure from name-resolution failure and from an exception raised by a function the script calls. See Tracing when diagnosing runtime evaluation.