Table of Contents

Class SubProgramCallSyntax

Namespace
Hi.NcParsers.EvaluationSyntaxs
Assembly
HiMech.dll

Inlines a Fanuc-style subprogram into the source layer when an M98 or M198 host block is reached. M98 P_ L_ reads the matching O<P> file from InternalFolder; M198 P_ reads from ExternalFolder (Fanuc external-storage call — same mechanism as M98, different lookup root). The file is segmented through the host runner's segmenter (SegmenterDependency) and the resulting SyntaxPieces are prepended into layers[0] via PrependSource(IEnumerable<T>); the rest of the pipeline picks them up through ordinary walkNode.Next traversal as if they had always been part of the host file.

Pipeline placement: in the Fanuc-family Evaluation BundleSyntax, right behind VariableEvaluatorSyntax so a variable-driven call word (M98 P#500) is already a number. By the time this runs, M98Syntax / M198Syntax (each a ParameterizedFlagSyntax) have written a Parsing.M98 / Parsing.M198 sub-object carrying the captured P / L parameters. Note: those sub-objects are this syntax's only trigger — "M98" / "M198" never reach Parsing.Flags, because the parameterized match has already consumed the text by the time NumberedFlagSyntax runs.

Filename lookup uses a fallback chain: O{P:D4}.NC, O{P}.NC, O{P:D4}, O{P}, {P:D4}.NC, {P}.NC — first match wins. Case-insensitive match is delegated to the host filesystem (Windows is, Linux is not).

L > 1 inlines the same subprogram L times in series. Each repetition is a fresh segmentation pass so each block gets its own SyntaxPiece with an independent JSON object — the downstream pipeline mutates JSON in place and would clobber sibling repetitions if instances were shared.

Recursion rail: a call whose host block already carries MaxCallDepth CallStack frames is not inlined. The call word is consumed, the host's SubProgramCall record is written with Skipped, and SubProgramCall--DepthLimitExceeded is reported, as the Siemens and Heidenhain call syntaxes do; the default is the Fanuc control's total call nesting (DefaultMaxCallDepth).

Not yet supported: partial-program calls (M98 P{seq}{prog} split encoding), and the sequence-number call M98 P_ Q_ (Fanuc, bit 0 SQC of parameter No. 6005) / M98 P_ H_ (Syntec): the whole program is inlined from its top, so a program that calls a sequence number of itself recurses here until the rail stops it. M99 P{seq} returns are SubProgramReturnSyntax's. Custom Macro B argument-binding calls (G65 / G66 / G67) live in FanucMacroCallSyntax and FanucModalMacroSyntax — those handle the argument-letter-to-#1..#26 binding and the macro-call frame isolation that M98 deliberately does not provide.

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

Constructors

SubProgramCallSyntax()

Parameterless instance with the default settings.

public SubProgramCallSyntax()

SubProgramCallSyntax(XElement)

Loads MaxCallDepth from XML produced by MakeXmlSource(string, string, bool). An absent, empty or non-numeric element leaves DefaultMaxCallDepth: a controller saved before the element existed loads with the rail at its default.

public SubProgramCallSyntax(XElement src)

Parameters

src XElement

Root element named XName.

Fields

DefaultMaxCallDepth

Default for MaxCallDepth: the Fanuc control's total call nesting. FANUC Series 0i-MODEL D / 0i Mate-MODEL D OPERATOR'S MANUAL (Common to Lathe System / Machining Center System) B-64304EN/02, §14.7 MACRO CALL, Limitation, Call nesting (p.206): “Macro calls can be nested to a depth of up to five levels and subprogram calls can be nested to a depth of up to ten levels; calls can be nested to a depth of up to 15 levels in total”; §13.3 SUBPROGRAM (M98, M99) (p.154): “subprogram calls can be nested up to ten levels”. FANUC Series 30i/31i/32i-MODEL B OPERATOR'S MANUAL (Common to Lathe System / Machining Center System) B-64484EN/03 states the same: §13.3 (p.275), “In addition, when the custom macro option is used, subprogram and macro calls can be nested up to a total of 15 levels”; §16.9 MACRO CALL, Limitation, Call nesting (p.456). Past the ceiling the control stops on alarm PS0077 TOO MANY SUB,MACRO NESTING, “The total number of subprogram and macro calls exceeds the permissible range” (B-64304EN/02 Appendix H, p.973; B-64484EN/03 Appendix H, p.2189).

The rail counts the CallStack frames of every kind: M98 / M198, G65 and G66 expansions push onto one stack and a Fanuc frame carries no kind, so the default is the control's total, not its ten for subprogram calls alone. A legal Fanuc program never reaches it; a nest the control stops at one of its lower per-kind ceilings is inlined here up to 15 levels.

The Mazak and Syntec presets share this syntax and this default. Mazak nests subprograms up to 8 levels (MAZATROL MATRIX Programming Manual EIA/ISO H740PB0030E, 14-9 Subprogram Control: M98, M99, p.14-91), so a 9- to 15-deep Mazak nest is inlined here. The Syntec mill programming manual states no ceiling (Mill Machine Program Manual, revised 2025-05-20, §3 M98, pp.255-256).

public const int DefaultMaxCallDepth = 15

Field Value

int

Properties

MaxCallDepth

Recursion rail. A self- or mutually-recursive subprogram re-captures its own call inside every inlined body and would splice without end; no iteration watchdog covers the call path. A call whose host block already carries this many CallStack frames is consumed as a structured safe-skip: the host's SubProgramCall record carries Skipped, SubProgramCall–DepthLimitExceeded is reported, nothing is inlined and nothing moves, as on the Siemens and Heidenhain call rails. Any integer is taken, as there: 0 or less refuses every call, the main program's included. The value is written into every saved controller, so a later change of DefaultMaxCallDepth reaches a controller saved from this version on only through a legacy patch.

The depth read is the host's own stamp at the Evaluation stage. A block that a GOTO or WHILE / END jump re-segments inside a called program, or that an M99 P{seq} return re-segments in a called caller, carries no stack until the Logic stage, so a call made from it counts from zero. A recursion through such a jump runs past the rail until the jump's iteration watchdog (FanucGotoIterationDependency, shared by M99 P; FanucWhileDoIterationDependency) suppresses it, and the rail stops it from there; through a WHILE skipped on entry, which no watchdog counts, it runs until Stop.

public int MaxCallDepth { get; set; }

Property Value

int

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