Table of Contents

Class HeidenhainExpressionParser

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

Recursive-descent parser for Heidenhain klartext FN value expressions. Produces the same NcExpr AST as the Fanuc NcExpressionParser so NcExpressionEvaluator is reused unchanged. Pure: no variable lookup, no evaluation.

Grammar (lowest precedence at top):

expr     := add-expr
add-expr := term (('+' | '-') term)*
term     := factor (('*' | '/' | 'DIV') factor)*
factor   := ('+' | '-')? primary
primary  := number
         | '(' expr ')'
         | 'Q' digits | 'QR' digits | 'QL' digits | 'QS' digits
         | func primary                    → prefix form "SQRT 4" (FN 5)
         | func '(' arglist ')'            → paren form "SQRT(Q2)"

Dialect notes: Q-family tokens are canonicalised to uppercase (q1Q1) so Parsing.Assignments keys, table lookups and same-block references agree. (Caveat shared with the Siemens R canonicalisation: a lowercase-captured Assignments key keeps its raw spelling in the evaluator's same-block dictionary, so a later same-block reference resolves to the pre-block value instead — klartext posts emit uppercase, corpus-zero.) DIV is the FN 4 division spelling (FN 4: Q4 = +8 DIV +Q2) and maps onto the shared divide operator. Function names are limited to the klartext math vocabulary (SQRT SIN COS TAN ASIN ACOS ATAN ABS INT FRAC SGN NEG LN LOG EXP); INT normalises to the evaluator's FIX (truncate toward zero), names the shared evaluator lacks (FRAC/SGN/NEG/LOG) parse fine and fail soft at evaluation. Any other identifier is a parse error — klartext has no named variables, and rejecting bare words keeps the evaluator's Parsing-tree pass from touching non-expression strings (MM, MAX, tool-axis letters). Comparison/logical operators are deliberately absent: FN 9–12 jump conditions are pre-normalised by the control-flow syntaxes (P5), not parsed here.

public sealed class HeidenhainExpressionParser
Inheritance
HeidenhainExpressionParser
Inherited Members
Extension Methods

Methods

TryParse(string, out NcExpr, out string)

Parses source requiring the whole string to be consumed. On success, expr is the AST and error is null. On failure, expr is null and error describes the syntax problem.

public static bool TryParse(string source, out NcExpr expr, out string error)

Parameters

source string
expr NcExpr
error string

Returns

bool

TryParsePrefix(string, out NcExpr, out int, out string)

Parses the longest valid expression prefix of source. On success, consumedLength is the number of leading characters that form the expression (trailing text from that offset on is the caller's to keep, e.g. as remaining UnparsedText). Fails only when not even a prefix parses — callers fall back to their legacy lexical capture in that case. This is the parser-delimited RHS boundary for Q1 = Q1 - 1-style assignments (whitespace inside the expression, trailing non-expression words split correctly).

public static bool TryParsePrefix(string source, out NcExpr expr, out int consumedLength, out string error)

Parameters

source string
expr NcExpr
consumedLength int
error string

Returns

bool