Table of Contents

Class FanucWhileDoSyntax

Namespace
Hi.NcParsers.EvaluationSyntaxs.Fanuc
Assembly
HiMech.dll

Resolves Fanuc Custom Macro B WHILE [..] DO m ... END m bounded loops. Two phrases dispatched by Term:

  • WHILE [..] DO m — entry: reads the resolved condition via FanucConditionReader, manages the per-LoopId frame in the top-level WhileFrames dict, and either falls through (truthy) or forward-jumps past the matching END m (falsy / unresolved).
  • END m — terminator: unconditionally reverse-jumps to the WHILE block recorded in WhileFrames[LoopId].BeginLineNo so the next iteration re-evaluates the entry condition. Increments the per-loop iteration counter on FanucWhileDoIterationDependency; suppresses the redirect above MaxIterationsPerLoopId.

WhileFrames carrier. The top-level WhileFrames JSON section is a JsonObject keyed by LoopId-as-string whose values are { BeginLineNo: int }. Frames are pushed when a WHILE block first encounters a truthy condition with no existing frame for that LoopId; popped when the condition becomes falsy or unresolved; otherwise carried forward unchanged by ModalCarrySyntax's Logic tracked-key list. Nested loops with distinct LoopIds coexist in the same dict; same-LoopId nesting (spec-undefined) overwrites and is not given special handling.

Pipeline placement. Evaluation bundle, after the variable readers (defensive — WHILE/END blocks per spec do not carry assignments, but the placement is consistent with GOTO). Must run after VariableEvaluatorSyntax so the condition string has been substituted to numeric.

Forward scan to matching END m uses the LabelScanUtil predicate overload — probe runs the brand-default FanucWhileDoParsingSyntax on each candidate, predicate matches on Parsing.FanucWhileDo.Term == "END" && LoopId == target.

Reverse scan to WHILE BeginLineNo does not need a label predicate — the BeginLineNo is a known file-line index recorded in the active frame, so the END side re-segments the file from the top and returns the slice starting at the first piece whose CharIndexSegment.Begin.LineIndex matches.

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

Remarks

Worked Example — Three-iteration WHILE [..] DO m ... END m

Given this Custom Macro B source:

#100 = 0
WHILE [#100 LT 3] DO 1
#100 = #100 + 1
END 1
X5

Each block flows through the runtime as below. The WhileFrames lifeline represents the per-block active-loop state carried block-to-block by the modal-carry pipeline; the END block consults it to find the WHILE line to reverse-jump to. The runaway-loop counter ticks on every successful END reverse-jump and suppresses further jumps above the configured iteration limit.

sequenceDiagram
    participant W as WHILE block
    participant B as body
    participant E as END block
    participant X as X5
    participant F as WhileFrames

    Note over F: empty
    Note over W: iter 1: cond=true (0 LT 3)
    W->>F: push {LoopId 1, BeginLineNo}
    W->>B: fall through
    B->>E: 
    Note over E: counter 0 to 1 (≤Max)
    E-->>W: reverse jump

    Note over W: iter 2: cond=true (1 LT 3)
    Note over W,F: frame exists, skip push
    W->>B: fall through
    B->>E: 
    Note over E: counter 1 to 2 (≤Max)
    E-->>W: reverse jump

    Note over W: iter 3: cond=true (2 LT 3)
    W->>B: 
    B->>E: 
    Note over E: counter 2 to 3 (≤Max)
    E-->>W: reverse jump

    Note over W: iter 4: cond=false (3 LT 3)
    W->>F: pop LoopId 1
    Note over W: forward jump past END
    W->>X: 

After the loop exits, X5 executes with #100 = 3 in Vars.Volatile.

Constructors

FanucWhileDoSyntax()

Parameterless instance.

public FanucWhileDoSyntax()

FanucWhileDoSyntax(XElement)

XML ctor (no child elements; reserved for forward compatibility).

public FanucWhileDoSyntax(XElement src)

Parameters

src XElement

Fields

BeginLineNoKey

Schema field inside each WhileFrames entry: the WHILE block's file-line index.

public const string BeginLineNoKey = "BeginLineNo"

Field Value

string

WhileFramesKey

Top-level JSON key for the active-loop frame dict.

public const string WhileFramesKey = "WhileFrames"

Field Value

string

Properties

Name

Syntax kind name (typically the concrete type name).

public string Name { get; }

Property Value

string

XName

XML element name used to register this syntax with XFactory.

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