Table of Contents

Class VariableEvaluatorSyntax

Namespace
Hi.NcParsers.EvaluationSyntaxs
Assembly
HiMech.dll

Pure expression normalizer for Custom Macro B syntax. Walks the parser-stage residue on a single block and inlines numeric values wherever a Fanuc-style variable reference or bracket expression appears — but does not write to any specific store. Routing “where the resolved literal lands” stays in the brand-specific reader syntaxes (VolatileVariableReadingSyntax, RetainedCommonVariableTable's reader, FanucSystemControlVariableSyntax, …) which run after this syntax on the same block.

Two passes per block:

  1. Assignments normalizeParsing.Assignments.#nnn entries whose RHS is non-literal (e.g. "#500+1", "SQRT[#100]") are evaluated via the VariableEvaluatorSyntax.ChainLookup and the RHS string is replaced with the resolved literal (round-trip-safe "R"-format). The entry stays in Parsing.Assignments so downstream reader syntaxes consume it as a pure-literal assignment. Iteration follows source order (Parsing.Assignments insertion order).
  2. Parsing tree substitution — every string-typed value reachable from Parsing.<tag> (axis tags, canned-cycle sub-objects) is parsed; on a successful evaluation the string is replaced with a numeric JsonValue. Failures silently leave the original string and rely on downstream GetParsedDouble(JsonObject, string, ISentenceCarrier, NcDiagnosticProgress) at consumer sites to surface VariableExpression--Unevaluated only if the tag is actually read.

Lookup chain (first non-null wins, configured per brand preset via RuntimeVariableLookups + IVariableLookup instances on NcDependencyList):

  1. Current block's own resolved assignments — built-in to VariableEvaluatorSyntax.ChainLookup; covers same-block forward references in source order (an earlier #nnn=literal is visible to a later RHS that mentions #nnn).
  2. Each IRuntimeVariableLookup in RuntimeVariableLookups, in list order. Typical contents for a Fanuc-family preset: LocalVariableLookup (#1-#33), VolatileVariableLookup (#100-#499), FanucPositionVariableLookup (#5001-#5043).
  3. Each IVariableLookup on the runner's NcDependencyList, in registration order (RetainedCommonVariableTable, FanucParameterTable, FanucToolOffsetVariableLookup).

Each lookup self-gates its id range; the evaluator stays brand- and range-agnostic. Adding a new variable surface is additive: register an IVariableLookup on a dependency or push an IRuntimeVariableLookup onto the per-preset list.

Same-block forward reference — when an Assignment RHS references a #nnn that is also being assigned later in the same block (i.e. listed in Parsing.Assignments after the RHS being evaluated), the VariableEvaluatorSyntax.ChainLookup cannot pick up the not-yet-resolved value and falls back to traceback / dependency-table reads — effectively the pre-block value. A VariableEvaluator--SameBlockForwardReference warning is emitted per such RHS so the user is told the source-order semantics were not honoured. Practical impact is near-zero for typical CAM-emitted NC (one assignment per line).

Formula mirror tree — when either pass actually performs a non-trivial expression evaluation (i.e. the RHS / tag value was not already a pure literal and the evaluator returned a finite value), the original expression string is mirrored to a parallel Formula.<same path> entry at the root of the block JSON. The Parsing.* subtree carries the resolved value (R-format string for Assignments; numeric JsonValue for tags); the Formula.* subtree preserves the source-text expression for diagnostics, round-trip reconstruction, and downstream inspection. Pure-literal RHS / tag values produce no Formula entry — the Parsing value is already the original text. Evaluation failures (parse error, vacant variable, non-finite result) also produce no Formula entry — the original string is still in Parsing.* untouched, no preservation needed.

public class VariableEvaluatorSyntax : ISituNcSyntax, INcSyntax, IMakeXmlSource
Inheritance
VariableEvaluatorSyntax
Implements
Inherited Members
Extension Methods

Constructors

VariableEvaluatorSyntax()

Default constructor.

public VariableEvaluatorSyntax()

VariableEvaluatorSyntax(XElement)

Loads from an XML element produced by MakeXmlSource(string, string, bool); restores RuntimeVariableLookups via XFactory dispatch.

public VariableEvaluatorSyntax(XElement src)

Parameters

src XElement

Fields

FormulaKey

Top-level key under which the Formula mirror tree is written.

public const string FormulaKey = "Formula"

Field Value

string

Properties

Name

Syntax kind name (typically the concrete type name).

public string Name { get; }

Property Value

string

RuntimeVariableLookups

Per-preset list of context-sensitive lookups (block-local Vars.Local / Vars.Volatile, position reads, runtime-state reads). Walked in list order, before the dependency-bound IVariableLookups. Brand presets configure this; the list is XML-serialised so a runner rebuilt from XML keeps its brand-specific lookups (each impl is stateless and dispatches by its XName via XFactory).

public List<IRuntimeVariableLookup> RuntimeVariableLookups { get; set; }

Property Value

List<IRuntimeVariableLookup>

XName

XML element name for Generators registration.

public static string XName { get; }

Property Value

string

Methods

Build(LazyLinkedListNode<SyntaxPiece>, List<INcDependency>, NcDiagnosticProgress)

Build syntax arrangement into the syntaxPieceNode in-place.

public void Build(LazyLinkedListNode<SyntaxPiece> syntaxPieceNode, List<INcDependency> ncDependencyList, NcDiagnosticProgress ncDiagnosticProgress)

Parameters

syntaxPieceNode LazyLinkedListNode<SyntaxPiece>
ncDependencyList List<INcDependency>
ncDiagnosticProgress NcDiagnosticProgress

MakeXmlSource(string, string, bool)

Creates an XML representation of the object. This method may also generate additional resources such as related files.

public XElement MakeXmlSource(string baseDirectory, string relFile, bool exhibitionOnly)

Parameters

baseDirectory string

The base directory for resolving relative paths

relFile string

The relative file path for the XML source

exhibitionOnly bool

if true, the extended file creation is suppressed.

Returns

XElement

An XML element representing the object's state

Remarks

For the demand of easy moving source folder (especially project folder) without configuration file path corruption, the relative file path is applied. The baseDirectory is typically the folder at the nearest configuration file folder. Since the folder can be moving with the configuration file.

Reg(XFactory)

Registers this type's deserializer with the given XFactory (or Default when factory is null). Idempotent.

public static void Reg(XFactory factory = null)

Parameters

factory XFactory