Namespace Hi.NcParsers.LogicSyntaxs.Evaluation
Classes
- NcBinaryExpr
Binary arithmetic on two operands (
+ - * /orMOD).
- NcExpr
AST root for a Fanuc Custom Macro B value expression. Concrete leaves and combinators sit alongside NcExpressionParser; walking is the job of NcExpressionEvaluator.
- NcExpressionEvaluator
Walks an NcExpr AST and produces an EvalResult. Resolves
#nnnvia an IVariableLookup; built-in function names are matched case-insensitively against a fixed table.Phase-1 supports:
SIN COS TAN ASIN ACOS ATAN SQRT ABS ROUND FIX FUP LN EXP POW. Trigonometric arguments and results are in degrees, matching Fanuc Custom Macro B convention. Unknown function names surface as UnsupportedFunctionCode; arity mismatches as ArgumentMismatchCode; division / MOD by zero and domain errors (e.g.SQRT[-1]) as MathErrorCode; vacant operands as VacantErrorCode.
- NcExpressionParser
Recursive-descent parser for Fanuc Custom Macro B value expressions. Pure: takes a string, produces an NcExpr AST. Performs no variable lookup and no evaluation.
Grammar (highest precedence last):
expr := term (('+' | '-') term)* term := factor (('*' | '/' | 'MOD') factor)* factor := ('+' | '-')? primary primary := number | '#' integer | '#' '[' expr ']' | '[' expr ']' | ident '[' arglist ']' ('/' '[' expr ']')? arglist := expr (',' expr)*Function names are case-insensitive (
SIN=sin); whitespace is skipped between tokens. The'/' '[' expr ']'tail captures the dual-bracket form Fanuc uses forATAN[a]/[b]; non-ATAN callers that happen to use it produce a function with an extra arg, which the evaluator rejects with an arity error.
- NcFunctionExpr
Built-in function call like
SIN[x],SQRT[x],ATAN[a]/[b].
- NcIndirectVariableExpr
Indirect variable reference
#[expr]. The inner expression is evaluated and truncated toward zero to obtain an integer; the lookup key is then Prefix concatenated with that integer (e.g.Prefix="#", computed124→"#124").
- NcLiteralExpr
Numeric literal (e.g.
1.5,15.,.5,1e-3).
- NcUnaryExpr
Unary
+or-applied to an operand.
- NcVariableExpr
Direct variable reference; Key is the raw source token (e.g.
"#124") passed verbatim to Get(string).
Structs
- EvalResult
Outcome of evaluating an NcExpr. Either a successful numeric value, or a failure with an error code matching the diagnostic catalogue used by reading / evaluator syntaxes.
Interfaces
- IRuntimeVariableLookup
Stateless variable lookup that needs per-block runtime context — the current SyntaxPiece node (for Previous traceback into runtime-state sections like
MachineCoordinateState/ProgramXyz) and the dependency list (so the lookup can read from sibling dependencies without holding a static reference).Distinguished from IVariableLookup: that one is for long-lived dependencies that already hold their own data (parameter tables, tool-offset wrappers, retained-variable tables) and need no block context.
IRuntimeVariableLookupis for context-sensitive resolutions configured declaratively on RuntimeVariableLookups.Implementations should be brand-specific (e.g. Fanuc
#5001-#5043position reads) and returnnullfor keys outside their range so the evaluator's chain can fall through to the next lookup.
- IVariableLookup
Resolves a Custom Macro B variable reference to its current numeric value, or
nullfor vacant (Fanuc<vacant>) and out-of-scope alike.The key is the raw source token — Fanuc
"#124", Heidenhain"Q1", Siemens"R1"— so the interface itself is brand-agnostic. Implementations are typically narrow (one per id range / per brand prefix) and parse the prefix locally; chain them at the call site by trying each in priority order until one returns a non-nullvalue.A returned
nullis treated by NcExpressionEvaluator as vacant and surfaces as aVariable--Vacantfailure when the value is consumed in arithmetic context.
Enums
- NcBinaryOp
Binary operators allowed in Fanuc Custom Macro B value expressions.
- NcUnaryOp
Unary operators allowed in Fanuc Custom Macro B value expressions.